-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/com/github/huda0209/irongolemspawncanceller/command/commandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.github.huda0209.irongolemspawncanceller.command; | ||
|
||
import com.github.huda0209.irongolemspawncanceller.IronGolemSpawnCanceller; | ||
import com.github.huda0209.irongolemspawncanceller.configload; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class commandHandler implements CommandExecutor { | ||
|
||
private final IronGolemSpawnCanceller plugin; | ||
public commandHandler(IronGolemSpawnCanceller pl){ | ||
this.plugin = pl; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){ | ||
if(args.length==0) return false; | ||
switch (args[0].toLowerCase(Locale.ROOT)){ | ||
case "setmode" : | ||
if(!sender.hasPermission("IronGolemSpawnCanceller.SetMode")){ | ||
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c You don't have permission!"); | ||
return true; | ||
} | ||
if(args.length!=2){ | ||
return false; | ||
} | ||
if(!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")){ | ||
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c Please specify SetMode with true or false."); | ||
return true; | ||
} | ||
|
||
Boolean mode = args[1].equalsIgnoreCase("true"); | ||
|
||
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§a IronGolemSpawnCancellMode set to "+ mode.toString() +"."); | ||
configload.setIronGolemSpawnCancellMode(mode,plugin); | ||
break; | ||
|
||
case "reload": | ||
if(!sender.hasPermission("IronGolemSpawnCanceller.Reload")){ | ||
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c You don't have permission!"); | ||
return true; | ||
} | ||
try { | ||
configload.loadConfig(plugin); | ||
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§a Reload the config file."); | ||
}catch(Exception e){ | ||
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c While reload the config file, occurred error. Please check console."); | ||
System.out.println(e.toString()); | ||
} | ||
break; | ||
|
||
default: | ||
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c Unknown command."); | ||
break; | ||
} | ||
return true; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/github/huda0209/irongolemspawncanceller/configload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.huda0209.irongolemspawncanceller; | ||
|
||
import org.bukkit.configuration.Configuration; | ||
|
||
public class configload { | ||
|
||
public static Boolean IronGolemSpawnCancellMode = false; | ||
private static Configuration config; | ||
|
||
public static void loadConfig(IronGolemSpawnCanceller pl){ | ||
try{ | ||
config = pl.getConfig(); | ||
}catch (Exception exception){ | ||
System.out.println("While load the config file, occurred error."); | ||
return; | ||
} | ||
|
||
IronGolemSpawnCancellMode = config.getBoolean("IronGolemSpawnCancellMode"); | ||
} | ||
|
||
public static void setIronGolemSpawnCancellMode(Boolean bool,IronGolemSpawnCanceller pl){ | ||
IronGolemSpawnCancellMode = bool; | ||
config.set("IronGolemSpawnCancellMode",bool); | ||
pl.saveConfig(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/github/huda0209/irongolemspawncanceller/listener/IronGolemSpawnEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.huda0209.irongolemspawncanceller.listener; | ||
|
||
import com.github.huda0209.irongolemspawncanceller.IronGolemSpawnCanceller; | ||
import com.github.huda0209.irongolemspawncanceller.configload; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.IronGolem; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntitySpawnEvent; | ||
|
||
public class IronGolemSpawnEvent implements Listener { | ||
|
||
private final IronGolemSpawnCanceller plugin; | ||
public IronGolemSpawnEvent(IronGolemSpawnCanceller pl) { | ||
this.plugin = pl; | ||
} | ||
|
||
@EventHandler | ||
public void IronGolemSpawnEvent(EntitySpawnEvent event){ | ||
Entity entity = event.getEntity(); | ||
|
||
if(!configload.IronGolemSpawnCancellMode) return; | ||
if(!(entity instanceof IronGolem)) return; | ||
|
||
IronGolem ig = (IronGolem) entity; | ||
|
||
if(!ig.isPlayerCreated()) event.setCancelled(true); | ||
System.out.println("[IronGolemSpawnCanceller]-------------------------------\nTo spawn IronGolem successful Cancelled.\n"+ | ||
"World : "+entity.getWorld().getName()+"\n"+ | ||
"Location: ("+entity.getLocation().getX()+", "+entity.getLocation().getY()+", "+entity.getLocation().getZ()+ | ||
"\n-------------------------------"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
# ------------------------------------------------------------- | ||
# | IronGolemSpawnCanceller | | ||
# | | | ||
# | Author : huda0209 | | ||
# | Depend : | | ||
# | GitHub : | | ||
# |https://github.com/stella-server-mc/IronGolemSpawnCanceller| | ||
# | ran by spigot 1.13 | | ||
# ------------------------------------------------------------- | ||
|
||
IronGolemSpawnCancellMode: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters