diff --git a/.classpath b/.classpath deleted file mode 100644 index d7fdc31..0000000 --- a/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df639c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db +bin +target +*.glob +.*.glob +.classpath +.project +.settings +.idea/ +*.iml +*.ipr +*.iws +dependency-reduced-pom.xml +/target/ +/anvilstringcommand/target/ +/common/target/ +/v18r1/target/ +/v18r2/target/ +/v18r3/target/ +/v19r1/target/ +/v19r2/target/ +*.class +.project +.classpath +/.settings/ + +/lib/ +.settings +.git diff --git a/.project b/.project deleted file mode 100644 index 2a3f6e6..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - ScriptBlock v0.8.0 (build 2020) - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 03d7020..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Mon Feb 13 02:10:16 CET 2012 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/Configuration/org/bukkit/util/config/Configuration.class b/Configuration/org/bukkit/util/config/Configuration.class deleted file mode 100644 index 6737e30..0000000 Binary files a/Configuration/org/bukkit/util/config/Configuration.class and /dev/null differ diff --git a/Configuration/org/bukkit/util/config/ConfigurationException.class b/Configuration/org/bukkit/util/config/ConfigurationException.class deleted file mode 100644 index 008aded..0000000 Binary files a/Configuration/org/bukkit/util/config/ConfigurationException.class and /dev/null differ diff --git a/Configuration/org/bukkit/util/config/ConfigurationNode.class b/Configuration/org/bukkit/util/config/ConfigurationNode.class deleted file mode 100644 index c139fdf..0000000 Binary files a/Configuration/org/bukkit/util/config/ConfigurationNode.class and /dev/null differ diff --git a/Configuration/org/bukkit/util/config/EmptyNullRepresenter$EmptyRepresentNull.class b/Configuration/org/bukkit/util/config/EmptyNullRepresenter$EmptyRepresentNull.class deleted file mode 100644 index a4214f2..0000000 Binary files a/Configuration/org/bukkit/util/config/EmptyNullRepresenter$EmptyRepresentNull.class and /dev/null differ diff --git a/Configuration/org/bukkit/util/config/EmptyNullRepresenter.class b/Configuration/org/bukkit/util/config/EmptyNullRepresenter.class deleted file mode 100644 index b24f2dc..0000000 Binary files a/Configuration/org/bukkit/util/config/EmptyNullRepresenter.class and /dev/null differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..494f3c4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,72 @@ + + + + 4.0.0 + + scriptblock + ScriptBlock + 0.8.72 + ScriptBlock + + + + UTF-8 + Unknown + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + md_5-repo + http://repo.md-5.net/content/groups/public/ + + + yeti-repo + http://nexus.theyeticave.net/content/repositories/pub_releases + + + + + + org.bukkit + bukkit + 1.9-R0.1-SNAPSHOT + jar + provided + + + org.spigotmc + spigot + 1.9-R0.1-SNAPSHOT + jar + provided + + + net.milkbowl.vault + Vault + 1.5.6 + provided + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + 1.7 + 1.7 + + + + + + \ No newline at end of file diff --git a/src/main/java/scriptblock/BlockCoords.java b/src/main/java/scriptblock/BlockCoords.java new file mode 100644 index 0000000..9bc2752 --- /dev/null +++ b/src/main/java/scriptblock/BlockCoords.java @@ -0,0 +1,27 @@ +package scriptblock; + +public class BlockCoords { + public String world; + public int x; + public int y; + public int z; + private String coords; + private String fullCoords; + + public BlockCoords(String world, int x, int y, int z) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.coords = x + "," + y + "," + z; + this.fullCoords = world + "," + this.coords; + } + + public String getCoords() { + return this.coords; + } + + public String getFullCoords() { + return this.fullCoords; + } +} diff --git a/src/main/java/scriptblock/SLAPI.java b/src/main/java/scriptblock/SLAPI.java new file mode 100644 index 0000000..6f0e58e --- /dev/null +++ b/src/main/java/scriptblock/SLAPI.java @@ -0,0 +1,22 @@ +package scriptblock; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +public class SLAPI { + public static void save(Object obj, String path) throws Exception { + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path)); + oos.writeObject(obj); + oos.flush(); + oos.close(); + } + + public static Object load(String path) throws Exception { + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path)); + Object result = ois.readObject(); + ois.close(); + return result; + } +} diff --git a/src/main/java/scriptblock/ScriptBlock.java b/src/main/java/scriptblock/ScriptBlock.java new file mode 100644 index 0000000..25c387b --- /dev/null +++ b/src/main/java/scriptblock/ScriptBlock.java @@ -0,0 +1,97 @@ +package scriptblock; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.logging.Logger; + +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.permission.Permission; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import scriptblock.listeners.PlayerInteractBlock; +import scriptblock.listeners.PlayerWalkBlock; +import scriptblock.managers.ScriptManager; + +public class ScriptBlock extends JavaPlugin { + private static ScriptBlock instance; + public static Logger log; + private ArrayList scriptManagerList = new ArrayList(); + private PlayerInteractBlock playerInteractBlock; + private PlayerWalkBlock playerWalkBlock; + private PluginManager pm; + private Permission perm; + private Economy eco; + + public void onEnable() { + instance = this; + this.pm = this.getServer().getPluginManager(); + log = this.getServer().getLogger(); + this.hookVault(); + this.playerInteractBlock = new PlayerInteractBlock(this); + this.playerWalkBlock = new PlayerWalkBlock(this); + this.register(this.playerInteractBlock, this); + this.register(this.playerWalkBlock, this); + log.info("[ScriptBlock] Enabled !!!"); + } + + public void onDisable() { + long t = System.currentTimeMillis(); + Iterator var4 = (Iterator)this.scriptManagerList.iterator(); + + while(var4.hasNext()) { + ScriptManager scriptManager = (ScriptManager)var4.next(); + scriptManager.getFileManager().saveDisabledTime(t); + } + + instance = null; + log.info("[ScriptBlock] Disabled !!!"); + } + + public void register(ScriptManager scriptManager, JavaPlugin plugin) { + this.scriptManagerList.add(scriptManager); + this.pm.registerEvents(scriptManager, plugin); + } + + public void hookVault() { + if(this.pm.isPluginEnabled("Vault")) { + RegisteredServiceProvider permissionProvider = this.getServer().getServicesManager().getRegistration(Permission.class); + if(permissionProvider != null) { + this.perm = (Permission)permissionProvider.getProvider(); + log.info("[ScriptBlock] " + this.perm.getName() + " found !"); + } else { + log.info("[ScriptBlock] No Permissions Plugin found !"); + log.info("[ScriptBlock] Do Not use (@bypass:\'group\') Option !"); + } + + RegisteredServiceProvider economyProvider = this.getServer().getServicesManager().getRegistration(Economy.class); + if(economyProvider != null) { + this.eco = (Economy)economyProvider.getProvider(); + log.info("[ScriptBlock] " + this.eco.getName() + " found !"); + } else { + log.info("[ScriptBlock] NO Economy Plugin found !"); + log.info("[ScriptBlock] Do not use \'$cost:\' Option"); + } + } else { + log.info("[ScriptBlock] Vault is not Installed ! "); + log.info("[ScriptBlock] Permission, and Economy Options won\'t work !"); + } + + } + + public Permission getPerm() { + return this.perm; + } + + public Economy getEco() { + return this.eco; + } + + public static ScriptBlock getInstance() { + return instance; + } + + public ArrayList getScriptManagerList() { + return this.scriptManagerList; + } +} diff --git a/src/main/java/scriptblock/command/BindScript.java b/src/main/java/scriptblock/command/BindScript.java new file mode 100644 index 0000000..359c086 --- /dev/null +++ b/src/main/java/scriptblock/command/BindScript.java @@ -0,0 +1,80 @@ +package scriptblock.command; + +import java.util.LinkedList; +import java.util.logging.Logger; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import scriptblock.BlockCoords; +import scriptblock.ScriptBlock; +import scriptblock.command.CommandCreate; +import scriptblock.command.CommandHandler; +import scriptblock.managers.FileManager; +import scriptblock.managers.MapManager; +import scriptblock.managers.PermManager; +import scriptblock.managers.ScriptManager; + +public abstract class BindScript { + protected ScriptBlock scriptBlock; + protected Logger log; + protected JavaPlugin plugin; + protected ScriptManager scriptManager; + protected CommandHandler.CommandType commandType; + protected FileManager fileManager; + protected MapManager mapManager; + protected PermManager permManager; + protected Player commandSender; + protected String statusCancelled; + protected String[] noAccessPermMsg; + + public BindScript(ScriptManager scriptManager, Player commandSender) { + this(scriptManager, commandSender, (CommandHandler.CommandType)null); + } + + public BindScript(ScriptManager scriptManager, Player commandSender, CommandHandler.CommandType commandType) { + this.scriptBlock = ScriptBlock.getInstance(); + this.log = ScriptBlock.log; + this.plugin = scriptManager.getPlugin(); + this.scriptManager = scriptManager; + this.commandType = commandType; + this.mapManager = scriptManager.getMapManager(); + this.fileManager = scriptManager.getFileManager(); + this.permManager = scriptManager.getPermManager(); + this.commandSender = commandSender; + this.statusCancelled = new String(ChatColor.RED + "[" + this.plugin.getName() + "] " + commandType.name() + " status cancelled !"); + this.noAccessPermMsg = new String[]{this.permManager.noPermMsg, ChatColor.RED + "[" + this.plugin.getName() + "] You can\'t \"" + commandType.name() + "\" scripts you don\'t own!"}; + } + + public abstract boolean onEvent(BlockCoords var1); + + protected boolean canAccessScript(BlockCoords blockCoords) { + LinkedList commandList = (LinkedList)this.mapManager.blocksMap.get(blockCoords.getFullCoords()); + String perm = new String("modify." + this.commandType.name()); + if(commandList == null) { + return true; + } else { + String firstLine = (String)commandList.getFirst(); + if(firstLine.startsWith(CommandCreate.authorNode)) { + firstLine = firstLine.replaceFirst(CommandCreate.authorNode, ""); + String[] scriptInfos = firstLine.split("/"); + String authorName = scriptInfos[0]; + String authorGroup = scriptInfos[1]; + if(!this.commandSender.getName().equals(authorName) && !this.permManager.hasSBPerm(this.commandSender, perm + "." + authorGroup, false)) { + this.commandSender.sendMessage(this.noAccessPermMsg); + return false; + } else { + return true; + } + } else if(this.permManager.hasSBPerm(this.commandSender, perm, false)) { + return true; + } else { + this.commandSender.sendMessage(this.noAccessPermMsg); + return false; + } + } + } + + public CommandHandler.CommandType getCommandType() { + return this.commandType; + } +} diff --git a/src/main/java/scriptblock/command/CommandAdd.java b/src/main/java/scriptblock/command/CommandAdd.java new file mode 100644 index 0000000..45dd916 --- /dev/null +++ b/src/main/java/scriptblock/command/CommandAdd.java @@ -0,0 +1,106 @@ +package scriptblock.command; + +import java.util.LinkedList; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import scriptblock.BlockCoords; +import scriptblock.SLAPI; +import scriptblock.command.CommandCreate; +import scriptblock.command.CommandHandler; +import scriptblock.command.CreateManager; +import scriptblock.managers.ScriptManager; + +public class CommandAdd extends CreateManager { + private String[] commandBody; + + public CommandAdd(ScriptManager scriptManager, String[] commandBody, Player commandSender, CommandHandler.CommandType commandType) { + super(scriptManager, commandSender, commandType); + this.commandBody = commandBody; + } + + public boolean isValid() { + if(this.commandBody.length == 0) { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] You must add argument !"); + return false; + } else { + String playerName = this.commandSender.getName(); + boolean alreadyExist = false; + Object obj = this.mapManager.commandsWaitingMap.get(playerName); + if(obj != null) { + alreadyExist = true; + if(obj instanceof CommandCreate) { + CommandCreate tempList = (CommandCreate)obj; + this.commandList = tempList.commandList; + } else if(obj instanceof CommandAdd) { + CommandAdd tempList1 = (CommandAdd)obj; + this.commandList = tempList1.commandList; + } else { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] ERROR in CommandAdd !"); + } + } else { + this.commandList = new LinkedList(); + } + + LinkedList tempList2 = new LinkedList(); + String text = this.ArrayToString(this.commandBody); + tempList2 = this.CommandScript(text, tempList2); + if(!this.opCheck(tempList2)) { + return false; + } else if(this.optionCheck(tempList2)) { + this.commandList.addAll(tempList2); + if(alreadyExist) { + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Command Successfully added to the Script !"); + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Click on a block to bind the Script to it..."); + return false; + } else { + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Use /sbadd command to add another script or..."); + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Click on a block to add the Script to it !"); + return true; + } + } else { + return false; + } + } + } + + public boolean onEvent(BlockCoords blockcoords) { + if(this.mapManager.blocksMap.containsKey(blockcoords.getFullCoords())) { + this.add(blockcoords); + return true; + } else { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] There is no script on this block."); + this.commandSender.sendMessage(this.statusCancelled); + return true; + } + } + + public boolean add(BlockCoords blockcoords) { + if(!this.canAccessScript(blockcoords)) { + this.commandSender.sendMessage(this.statusCancelled); + return true; + } else { + String world = blockcoords.world; + String FullBlockCoords = blockcoords.getFullCoords(); + String blockCoords = blockcoords.getCoords(); + LinkedList finalList = (LinkedList)this.mapManager.blocksMap.get(FullBlockCoords); + finalList.addAll(this.commandList); + this.mapManager.blocksMap.put(FullBlockCoords, finalList); + this.fileManager.getScriptConfig().setProperty(world + "." + blockCoords + ".", finalList); + this.fileManager.getScriptConfig().save(); + if(this.mapManager.cooldownMap.containsKey(FullBlockCoords)) { + this.mapManager.cooldownMap.remove(FullBlockCoords); + + try { + SLAPI.save(this.mapManager.cooldownMap, this.fileManager.getCooldownDataFile().getPath()); + this.log.info("cooldown Saved to " + this.fileManager.getCooldownDataFile().getName() + " !"); + } catch (Exception var7) { + this.log.info("[ERROR] while saving cooldownBlockMap to " + this.fileManager.getCooldownDataFile().getName() + " ![ERROR]"); + this.log.info("at " + var7.getMessage()); + } + } + + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Text Successfully bound !"); + return true; + } + } +} diff --git a/src/main/java/scriptblock/command/CommandCreate.java b/src/main/java/scriptblock/command/CommandCreate.java new file mode 100644 index 0000000..f2b63be --- /dev/null +++ b/src/main/java/scriptblock/command/CommandCreate.java @@ -0,0 +1,55 @@ +package scriptblock.command; + +import java.util.Iterator; +import java.util.LinkedList; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import scriptblock.BlockCoords; +import scriptblock.command.CommandHandler; +import scriptblock.command.CreateManager; +import scriptblock.managers.ScriptManager; + +public class CommandCreate extends CreateManager { + public static String authorNode = "Author:"; + private String[] body; + + public CommandCreate(ScriptManager scriptManager, String[] cmdBody, Player commandSender, CommandHandler.CommandType commandType) { + super(scriptManager, commandSender, commandType); + this.body = cmdBody; + } + + public boolean isValid() { + if(this.body.length <= 0) { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] You must add arguments !"); + return false; + } else { + String playerName = this.commandSender.getName(); + Iterator var3 = this.scriptBlock.getScriptManagerList().iterator(); + + while(var3.hasNext()) { + ScriptManager text = (ScriptManager)var3.next(); + if(text.getMapManager().commandsWaitingMap.containsKey(playerName)) { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] You must validate your previous action !"); + return false; + } + } + + String text1 = this.ArrayToString(this.body); + this.commandList = new LinkedList(); + this.commandList = this.CommandScript(text1, this.commandList); + if(!this.opCheck(this.commandList)) { + return false; + } else if(this.optionCheck(this.commandList)) { + this.commandList.add(0, authorNode + playerName + "/" + this.scriptBlock.getPerm().getPrimaryGroup(this.commandSender)); + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Click on a block to bind the text to it..."); + return true; + } else { + return false; + } + } + } + + public boolean onEvent(BlockCoords blockcoords) { + return this.create(blockcoords); + } +} diff --git a/src/main/java/scriptblock/command/CommandHandler.java b/src/main/java/scriptblock/command/CommandHandler.java new file mode 100644 index 0000000..0be6237 --- /dev/null +++ b/src/main/java/scriptblock/command/CommandHandler.java @@ -0,0 +1,143 @@ +package scriptblock.command; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import scriptblock.command.CommandAdd; +import scriptblock.command.CommandCreate; +import scriptblock.command.CommandRemove; +import scriptblock.command.CommandView; +import scriptblock.managers.FileManager; +import scriptblock.managers.MapManager; +import scriptblock.managers.PermManager; +import scriptblock.managers.ScriptManager; + +public class CommandHandler implements CommandExecutor { + public JavaPlugin plugin; + public ScriptManager scriptManager; + public Player commandsender; + public String[] body; + protected MapManager mapManager; + private PermManager perm; + private String pluginCommand; + // $FF: synthetic field + private static int[] $SWITCH_TABLE$scriptblock$command$CommandHandler$CommandType; + + public CommandHandler(ScriptManager scriptManager, String pluginCommand) { + this.scriptManager = scriptManager; + this.pluginCommand = pluginCommand; + this.mapManager = scriptManager.getMapManager(); + this.plugin = scriptManager.getPlugin(); + this.perm = scriptManager.getPermManager(); + this.plugin.getCommand(pluginCommand + scriptManager.getName()).setExecutor(this); + } + + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] body) { + if(sender instanceof Player) { + this.body = body; + this.commandsender = (Player)sender; + String playerName = this.commandsender.getName(); + CommandHandler.CommandType[] var9; + int var8 = (var9 = CommandHandler.CommandType.values()).length; + + for(int var7 = 0; var7 < var8; var7++) { + CommandHandler.CommandType commandType = var9[var7]; + if(body.length > 0 && body[0].equalsIgnoreCase(commandType.name())) { + if(this.perm.hasSBPerm(this.commandsender, "command." + commandType.name(), true)) { + body[0] = null; + switch($SWITCH_TABLE$scriptblock$command$CommandHandler$CommandType()[commandType.ordinal()]) { + case 1: + CommandCreate commandCreate = new CommandCreate(this.scriptManager, body, this.commandsender, commandType); + if(commandCreate.isValid()) { + this.mapManager.commandsWaitingMap.put(playerName, commandCreate); + } + break; + case 2: + CommandAdd commandAdd = new CommandAdd(this.scriptManager, body, this.commandsender, commandType); + if(commandAdd.isValid()) { + this.mapManager.commandsWaitingMap.put(playerName, commandAdd); + } + break; + case 3: + CommandRemove commandRemove = new CommandRemove(this.scriptManager, this.commandsender, commandType); + if(commandRemove.isValid()) { + this.mapManager.commandsWaitingMap.put(playerName, commandRemove); + } + break; + case 4: + CommandView commandView = new CommandView(this.scriptManager, this.commandsender, commandType); + if(commandView.isValid()) { + this.mapManager.commandsWaitingMap.put(playerName, commandView); + } + break; + case 5: + FileManager fileManager = this.scriptManager.getFileManager(); + fileManager.loadScriptFile(); + fileManager.loadConfigFile(); + this.commandsender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] " + fileManager.getScriptDataFile().getName() + " is now reloaded !"); + this.commandsender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] " + fileManager.getConfigFile().getName() + " is now reloaded !"); + } + } + + return true; + } + } + } + + return false; + } + + // $FF: synthetic method + static int[] $SWITCH_TABLE$scriptblock$command$CommandHandler$CommandType() { + int[] var10000 = $SWITCH_TABLE$scriptblock$command$CommandHandler$CommandType; + if($SWITCH_TABLE$scriptblock$command$CommandHandler$CommandType != null) { + return var10000; + } else { + int[] var0 = new int[CommandHandler.CommandType.values().length]; + + try { + var0[CommandHandler.CommandType.add.ordinal()] = 2; + } catch (NoSuchFieldError var5) { + ; + } + + try { + var0[CommandHandler.CommandType.create.ordinal()] = 1; + } catch (NoSuchFieldError var4) { + ; + } + + try { + var0[CommandHandler.CommandType.reload.ordinal()] = 5; + } catch (NoSuchFieldError var3) { + ; + } + + try { + var0[CommandHandler.CommandType.remove.ordinal()] = 3; + } catch (NoSuchFieldError var2) { + ; + } + + try { + var0[CommandHandler.CommandType.view.ordinal()] = 4; + } catch (NoSuchFieldError var1) { + ; + } + + $SWITCH_TABLE$scriptblock$command$CommandHandler$CommandType = var0; + return var0; + } + } + + public static enum CommandType { + create, + add, + remove, + view, + reload; + } +} diff --git a/src/main/java/scriptblock/command/CommandRemove.java b/src/main/java/scriptblock/command/CommandRemove.java new file mode 100644 index 0000000..8e27e17 --- /dev/null +++ b/src/main/java/scriptblock/command/CommandRemove.java @@ -0,0 +1,55 @@ +package scriptblock.command; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import scriptblock.BlockCoords; +import scriptblock.SLAPI; +import scriptblock.command.BindScript; +import scriptblock.command.CommandHandler; +import scriptblock.managers.ScriptManager; + +public class CommandRemove extends BindScript { + public CommandRemove(ScriptManager scriptManager, Player commandsender, CommandHandler.CommandType commandType) { + super(scriptManager, commandsender, commandType); + } + + public boolean isValid() { + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Click on a block to remove the script..."); + return true; + } + + public boolean onEvent(BlockCoords blockCoords) { + if(this.mapManager.blocksMap.containsKey(blockCoords.getFullCoords())) { + if(!this.canAccessScript(blockCoords)) { + this.commandSender.sendMessage(this.statusCancelled); + return true; + } else { + this.mapManager.blocksMap.remove(blockCoords.getFullCoords()); + this.fileManager.getScriptConfig().removeProperty(blockCoords.world + "." + blockCoords.getCoords() + "."); + this.fileManager.getScriptConfig().save(); + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Text Successfully removed !"); + if(this.mapManager.cooldownMap.containsKey(blockCoords.getFullCoords())) { + this.mapManager.cooldownMap.remove(blockCoords.getFullCoords()); + + try { + SLAPI.save(this.mapManager.cooldownMap, this.fileManager.getCooldownDataFile().getPath()); + this.log.info("cooldown removed from CoolDownData.dat!"); + } catch (Exception var3) { + this.log.info("[ERROR] while saving cooldownBlockMap to CoolDownData.dat ![ERROR]"); + this.log.info("at " + var3.getMessage()); + } + } + + if(this.mapManager.delayList.contains(blockCoords.getFullCoords())) { + this.mapManager.delayList.remove(blockCoords.getFullCoords()); + } + + return true; + } + } else { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] There is no Script bound to this !"); + this.commandSender.sendMessage(this.statusCancelled); + return true; + } + } +} diff --git a/src/main/java/scriptblock/command/CommandView.java b/src/main/java/scriptblock/command/CommandView.java new file mode 100644 index 0000000..0665e7c --- /dev/null +++ b/src/main/java/scriptblock/command/CommandView.java @@ -0,0 +1,44 @@ +package scriptblock.command; + +import java.util.Iterator; +import java.util.LinkedList; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import scriptblock.BlockCoords; +import scriptblock.command.BindScript; +import scriptblock.command.CommandHandler; +import scriptblock.managers.ScriptManager; + +public class CommandView extends BindScript { + public CommandView(ScriptManager scriptManager, Player commandsender, CommandHandler.CommandType commandType) { + super(scriptManager, commandsender, commandType); + } + + public boolean isValid() { + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Click on a block to view the Script..."); + return true; + } + + public boolean onEvent(BlockCoords blockcoords) { + if(!this.canAccessScript(blockcoords)) { + this.commandSender.sendMessage(this.statusCancelled); + return true; + } else { + LinkedList script = (LinkedList)this.mapManager.blocksMap.get(blockcoords.getFullCoords()); + if(script == null) { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] There is no Script bound to this block !"); + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] View Status Cancelled !"); + return true; + } else { + Iterator var4 = script.iterator(); + + while(var4.hasNext()) { + String command = (String)var4.next(); + this.commandSender.sendMessage("[" + this.plugin.getName() + "] " + command); + } + + return true; + } + } + } +} diff --git a/src/main/java/scriptblock/command/CreateManager.java b/src/main/java/scriptblock/command/CreateManager.java new file mode 100644 index 0000000..3c0249c --- /dev/null +++ b/src/main/java/scriptblock/command/CreateManager.java @@ -0,0 +1,180 @@ +package scriptblock.command; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import scriptblock.BlockCoords; +import scriptblock.SLAPI; +import scriptblock.command.BindScript; +import scriptblock.command.CommandHandler; +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; + +public abstract class CreateManager extends BindScript { + protected LinkedList commandList; + + public CreateManager(ScriptManager scriptManager, Player player, CommandHandler.CommandType commandType) { + super(scriptManager, player, commandType); + String consoleMsg = "[" + this.plugin.getName() + "] " + this.commandSender.getName() + " performed command \"" + commandType.name() + "\"..."; + this.log.info(consoleMsg); + } + + protected abstract boolean isValid(); + + protected boolean create(BlockCoords blockcoords) { + String FullBlockCoords = blockcoords.getFullCoords(); + if(!this.canAccessScript(blockcoords)) { + return false; + } else { + this.mapManager.blocksMap.put(FullBlockCoords, this.commandList); + this.fileManager.getScriptConfig().setProperty(blockcoords.world + "." + blockcoords.getCoords() + ".", this.commandList); + this.fileManager.getScriptConfig().save(); + if(this.mapManager.cooldownMap.containsKey(FullBlockCoords)) { + this.mapManager.cooldownMap.remove(FullBlockCoords); + + try { + SLAPI.save(this.mapManager.cooldownMap, this.fileManager.getCooldownDataFile().getPath()); + this.log.info("cooldown Saved to CoolDownData.dat!"); + } catch (Exception var4) { + this.log.info("[ERROR] while saving cooldownBlockMap to CoolDownData.dat ![ERROR]"); + this.log.info("at " + var4.getMessage()); + } + } + + this.mapManager.delayList.remove(FullBlockCoords); + this.commandSender.sendMessage(ChatColor.GREEN + "[" + this.plugin.getName() + "] Text Successfully bound !"); + return true; + } + } + + public boolean optionCheck(LinkedList list) { + boolean haveOption = false; + + for(int i = 0; i < list.size(); ++i) { + String scriptLine = (String)list.get(i); + Iterator var6 = this.mapManager.optionsList.iterator(); + + while(var6.hasNext()) { + Option option = (Option)var6.next(); + if(scriptLine.startsWith(option.getSyntax())) { + haveOption = true; + String optionNode = new String("option." + option.getName()); + String param = null; + if(option instanceof Option.Permissible) { + param = scriptLine.replaceFirst(option.getSyntax(), ""); + if(param.contains(" /")) { + param = param.substring(0, param.indexOf(" /")); + } + } + + String permMessage = ChatColor.RED + "[" + this.plugin.getName() + "] You need permission to use: " + ChatColor.WHITE + option.getSyntax(); + String consoleMsg1 = "[" + this.plugin.getName() + "] Option \"" + option.getName() + "\" added"; + if(param != null) { + String perm = new String(optionNode + "." + param); + if(!this.permManager.hasSBPerm(this.commandSender, perm, false)) { + this.commandSender.sendMessage(permMessage + param + ChatColor.RED + " !!"); + list = null; + return false; + } + + if(option.showConsole()) { + this.log.info(consoleMsg1 + " with param \"" + param + "\" !"); + } + } else { + if(!this.permManager.hasSBPerm(this.commandSender, optionNode, false)) { + this.commandSender.sendMessage(permMessage + ChatColor.RED + " !!"); + list = null; + return false; + } + + if(option.showConsole()) { + this.log.info(consoleMsg1 + "..."); + } + } + break; + } + } + + if(!haveOption) { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] BAD SCRIPT !"); + list = null; + return false; + } + } + + return true; + } + + public boolean opCheck(LinkedList list) { + if(!this.commandSender.isOp() && this.ContainsOpCommands(list)) { + this.commandSender.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] Only Ops can Write Op\'s Commands !!!"); + list = null; + return false; + } else { + return true; + } + } + + protected boolean ContainsOpCommands(LinkedList commandList) { + String[] opCommands = new String[]{"op", "deop", "save-all", "save-off", "save-on", "stop", "ban-ip", "ban", "pardon-ip", "pardon", "gamemode", "kick", "whitelist", "?"}; + Iterator iter = commandList.iterator(); + + while(true) { + String n; + Option bypassOp; + do { + if(!iter.hasNext()) { + return false; + } + + n = (String)iter.next(); + new String(); + bypassOp = this.scriptManager.getOptionManager().bypassOp; + } while(!n.startsWith(bypassOp.getName())); + + for(int i = 0; i < opCommands.length; ++i) { + String m = n.replaceFirst(bypassOp.getSyntax(), ""); + m = m.toLowerCase(); + if(m.startsWith(opCommands[i])) { + return true; + } + } + } + } + + protected LinkedList CommandScript(String text, LinkedList commandList) { + new String(); + if(text.contains("[") && text.contains("]")) { + while(text.contains("[") && text.contains("]")) { + int a = text.indexOf("[") + 1; + int b = text.indexOf("]"); + String finalText = text.substring(a, b); + text = text.replace(finalText, ""); + text = text.replace("[]", ""); + commandList.add(finalText); + } + } else { + commandList.add(text); + } + + return commandList; + } + + protected String ArrayToString(String[] arg) { + new String(); + StringBuilder stringBuilder = new StringBuilder(); + Iterator iter = Arrays.asList(arg).iterator(); + + while(iter.hasNext()) { + String s = (String)iter.next(); + if(s != null && !s.isEmpty()) { + stringBuilder.append(" ").append(s); + } + } + + String text = stringBuilder.toString().replaceFirst(" ", ""); + return text; + } +} diff --git a/src/main/java/scriptblock/config/Configuration.java b/src/main/java/scriptblock/config/Configuration.java new file mode 100644 index 0000000..49a5238 --- /dev/null +++ b/src/main/java/scriptblock/config/Configuration.java @@ -0,0 +1,148 @@ +package scriptblock.config; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.HashMap; +import java.util.Map; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.DumperOptions.FlowStyle; +import org.yaml.snakeyaml.reader.UnicodeReader; +import scriptblock.config.ConfigurationException; +import scriptblock.config.ConfigurationNode; + +/** @deprecated */ +@Deprecated +public class Configuration extends ConfigurationNode { + private Yaml yaml; + private File file; + private String header = null; + + /** @deprecated */ + @Deprecated + public Configuration(File file) { + super(new HashMap()); + DumperOptions options = new DumperOptions(); + options.setIndent(4); + options.setDefaultFlowStyle(FlowStyle.BLOCK); + this.yaml = new Yaml(options); + this.file = file; + } + + public void load() { + FileInputStream stream = null; + + try { + stream = new FileInputStream(this.file); + this.read(this.yaml.load(new UnicodeReader(stream))); + } catch (IOException var18) { + this.root = new HashMap(); + + try { + if(stream != null) { + stream.close(); + } + } catch (IOException var17) { + ; + } + } catch (ConfigurationException var19) { + this.root = new HashMap(); + + try { + if(stream != null) { + stream.close(); + } + } catch (IOException var16) { + ; + } + } finally { + try { + if(stream != null) { + stream.close(); + } + } catch (IOException var15) { + ; + } + + } + + } + + public void setHeader(String[] headerLines) { + StringBuilder header = new StringBuilder(); + String[] var6 = headerLines; + int var5 = headerLines.length; + + for(int var4 = 0; var4 < var5; ++var4) { + String line = var6[var4]; + if(header.length() > 0) { + header.append("\r\n"); + } + + header.append(line); + } + + this.setHeader(header.toString()); + } + + public void setHeader(String header) { + this.header = header; + } + + public String getHeader() { + return this.header; + } + + public boolean save() { + FileOutputStream stream = null; + File parent = this.file.getParentFile(); + if(parent != null) { + parent.mkdirs(); + } + + try { + stream = new FileOutputStream(this.file); + OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); + if(this.header != null) { + writer.append(this.header); + writer.append("\r\n"); + } + + this.yaml.dump(this.root, writer); + return true; + } catch (IOException var12) { + ; + } finally { + try { + if(stream != null) { + stream.close(); + } + } catch (IOException var11) { + ; + } + + } + + return false; + } + + private void read(Object input) throws ConfigurationException { + try { + if(input == null) { + this.root = new HashMap(); + } else { + this.root = (Map)input; + } + + } catch (ClassCastException var3) { + throw new ConfigurationException("Root document must be an key-value structure"); + } + } + + public static ConfigurationNode getEmptyNode() { + return new ConfigurationNode(new HashMap()); + } +} diff --git a/src/main/java/scriptblock/config/ConfigurationException.java b/src/main/java/scriptblock/config/ConfigurationException.java new file mode 100644 index 0000000..bb289ef --- /dev/null +++ b/src/main/java/scriptblock/config/ConfigurationException.java @@ -0,0 +1,12 @@ +package scriptblock.config; + +public class ConfigurationException extends Exception { + private static final long serialVersionUID = -2442886939908724203L; + + public ConfigurationException() { + } + + public ConfigurationException(String msg) { + super(msg); + } +} diff --git a/src/main/java/scriptblock/config/ConfigurationNode.java b/src/main/java/scriptblock/config/ConfigurationNode.java new file mode 100644 index 0000000..d61f5f5 --- /dev/null +++ b/src/main/java/scriptblock/config/ConfigurationNode.java @@ -0,0 +1,324 @@ +package scriptblock.config; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.Map.Entry; + +public class ConfigurationNode { + protected Map root; + + protected ConfigurationNode(Map root) { + this.root = root; + } + + public Map getAll() { + return this.recursiveBuilder(this.root); + } + + protected Map recursiveBuilder(Map node) { + TreeMap map = new TreeMap(); + Set keys = node.keySet(); + Iterator var5 = keys.iterator(); + + while(true) { + while(var5.hasNext()) { + String k = (String)var5.next(); + Object tmp = node.get(k); + if(tmp instanceof Map) { + Map rec = this.recursiveBuilder((Map)tmp); + Set subkeys = rec.keySet(); + Iterator var10 = subkeys.iterator(); + + while(var10.hasNext()) { + String sk = (String)var10.next(); + map.put(k + "." + sk, rec.get(sk)); + } + } else { + map.put(k, tmp); + } + } + + return map; + } + } + + public Object getProperty(String path) { + if(!path.contains(".")) { + Object var8 = this.root.get(path); + return var8 == null?null:var8; + } else { + String[] parts = path.split("\\."); + Map node = this.root; + + for(int i = 0; i < parts.length; ++i) { + Object o = node.get(parts[i]); + if(o == null) { + return null; + } + + if(i == parts.length - 1) { + return o; + } + + try { + node = (Map)o; + } catch (ClassCastException var7) { + return null; + } + } + + return null; + } + } + + public void setProperty(String path, Object value) { + if(!path.contains(".")) { + this.root.put(path, value); + } else { + String[] parts = path.split("\\."); + Map node = this.root; + + for(int i = 0; i < parts.length; ++i) { + Object o = node.get(parts[i]); + if(i == parts.length - 1) { + node.put(parts[i], value); + return; + } + + if(o == null || !(o instanceof Map)) { + o = new HashMap(); + node.put(parts[i], o); + } + + node = (Map)o; + } + + } + } + + public String getString(String path) { + Object o = this.getProperty(path); + return o == null?null:o.toString(); + } + + public String getString(String path, String def) { + String o = this.getString(path); + if(o == null) { + this.setProperty(path, def); + return def; + } else { + return o; + } + } + + public int getInt(String path, int def) { + Integer o = castInt(this.getProperty(path)); + if(o == null) { + this.setProperty(path, Integer.valueOf(def)); + return def; + } else { + return o.intValue(); + } + } + + public double getDouble(String path, double def) { + Double o = castDouble(this.getProperty(path)); + if(o == null) { + this.setProperty(path, Double.valueOf(def)); + return def; + } else { + return o.doubleValue(); + } + } + + public boolean getBoolean(String path, boolean def) { + Boolean o = castBoolean(this.getProperty(path)); + if(o == null) { + this.setProperty(path, Boolean.valueOf(def)); + return def; + } else { + return o.booleanValue(); + } + } + + public List getKeys(String path) { + if(path == null) { + return new ArrayList(this.root.keySet()); + } else { + Object o = this.getProperty(path); + return o == null?null:(o instanceof Map?new ArrayList(((Map)o).keySet()):null); + } + } + + public List getKeys() { + return new ArrayList(this.root.keySet()); + } + + public List getList(String path) { + Object o = this.getProperty(path); + return o == null?null:(o instanceof List?(List)o:null); + } + + public List getStringList(String path, List def) { + List raw = this.getList(path); + if(raw == null) { + return (List)(def != null?def:new ArrayList()); + } else { + ArrayList list = new ArrayList(); + Iterator i$ = raw.iterator(); + + while(i$.hasNext()) { + Object o = i$.next(); + if(o != null) { + list.add(o.toString()); + } + } + + return list; + } + } + + public List getIntList(String path, List def) { + List raw = this.getList(path); + if(raw == null) { + return (List)(def != null?def:new ArrayList()); + } else { + ArrayList list = new ArrayList(); + Iterator i$ = raw.iterator(); + + while(i$.hasNext()) { + Object o = i$.next(); + Integer i = castInt(o); + if(i != null) { + list.add(i); + } + } + + return list; + } + } + + public List getDoubleList(String path, List def) { + List raw = this.getList(path); + if(raw == null) { + return (List)(def != null?def:new ArrayList()); + } else { + ArrayList list = new ArrayList(); + Iterator i$ = raw.iterator(); + + while(i$.hasNext()) { + Object o = i$.next(); + Double i = castDouble(o); + if(i != null) { + list.add(i); + } + } + + return list; + } + } + + public List getBooleanList(String path, List def) { + List raw = this.getList(path); + if(raw == null) { + return (List)(def != null?def:new ArrayList()); + } else { + ArrayList list = new ArrayList(); + Iterator i$ = raw.iterator(); + + while(i$.hasNext()) { + Object o = i$.next(); + Boolean tetsu = castBoolean(o); + if(tetsu != null) { + list.add(tetsu); + } + } + + return list; + } + } + + public List getNodeList(String path, List def) { + List raw = this.getList(path); + if(raw == null) { + return (List)(def != null?def:new ArrayList()); + } else { + ArrayList list = new ArrayList(); + Iterator i$ = raw.iterator(); + + while(i$.hasNext()) { + Object o = i$.next(); + if(o instanceof Map) { + list.add(new ConfigurationNode((Map)o)); + } + } + + return list; + } + } + + public ConfigurationNode getNode(String path) { + Object raw = this.getProperty(path); + return raw instanceof Map?new ConfigurationNode((Map)raw):null; + } + + public Map getNodes(String path) { + Object o = this.getProperty(path); + if(o == null) { + return null; + } else if(o instanceof Map) { + HashMap nodes = new HashMap(); + HashMap map = (HashMap)o; + Set set = map.entrySet(); + Iterator var7 = set.iterator(); + + while(var7.hasNext()) { + Entry entry = (Entry)var7.next(); + if(entry.getValue() instanceof Map) { + nodes.put(entry.getKey(), new ConfigurationNode((Map)entry.getValue())); + } + } + + return nodes; + } else { + return null; + } + } + + private static Integer castInt(Object o) { + return o == null?null:(o instanceof Byte?Integer.valueOf(((Byte)o).byteValue()):(o instanceof Integer?(Integer)o:(o instanceof Double?Integer.valueOf((int)((Double)o).doubleValue()):(o instanceof Float?Integer.valueOf((int)((Float)o).floatValue()):(o instanceof Long?Integer.valueOf((int)((Long)o).longValue()):null))))); + } + + private static Double castDouble(Object o) { + return o == null?null:(o instanceof Float?Double.valueOf((double)((Float)o).floatValue()):(o instanceof Double?(Double)o:(o instanceof Byte?Double.valueOf((double)((Byte)o).byteValue()):(o instanceof Integer?Double.valueOf((double)((Integer)o).intValue()):(o instanceof Long?Double.valueOf((double)((Long)o).longValue()):null))))); + } + + private static Boolean castBoolean(Object o) { + return o == null?null:(o instanceof Boolean?(Boolean)o:null); + } + + public void removeProperty(String path) { + if(!path.contains(".")) { + this.root.remove(path); + } else { + String[] parts = path.split("\\."); + Map node = this.root; + + for(int i = 0; i < parts.length; ++i) { + Object o = node.get(parts[i]); + if(i == parts.length - 1) { + node.remove(parts[i]); + return; + } + + node = (Map)o; + } + + } + } +} diff --git a/src/main/java/scriptblock/listeners/PlayerInteractBlock.java b/src/main/java/scriptblock/listeners/PlayerInteractBlock.java new file mode 100644 index 0000000..054e1ec --- /dev/null +++ b/src/main/java/scriptblock/listeners/PlayerInteractBlock.java @@ -0,0 +1,62 @@ +package scriptblock.listeners; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.Event.Result; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import scriptblock.BlockCoords; +import scriptblock.ScriptBlock; +import scriptblock.command.BindScript; +import scriptblock.managers.ScriptManager; +import scriptblock.options.OptionHandler; + +public class PlayerInteractBlock extends ScriptManager implements Listener { + private Player player; + private BlockCoords blockCoords; + + public PlayerInteractBlock(ScriptBlock scriptBlock) { + super(scriptBlock, "interact", "sb"); + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + this.player = event.getPlayer(); + Block block; + + if(event.hasBlock()) { + block = event.getClickedBlock(); + String world = this.player.getWorld().getName(); + int x = block.getX(); + int y = block.getY(); + int z = block.getZ(); + this.blockCoords = new BlockCoords(world, x, y, z); + String playerName = this.player.getName(); + BindScript blockInteract = (BindScript)this.mapManager.commandsWaitingMap.get(playerName); + if(blockInteract != null) { + if(blockInteract.onEvent(this.blockCoords)) { + this.mapManager.commandsWaitingMap.remove(playerName); + this.log.info("[" + this.plugin.getName() + "] " + playerName + " bound \"" + blockInteract.getCommandType().name() + "\" " + this.getName() + " Script..."); + this.log.info("[" + this.plugin.getName() + "] at " + this.blockCoords.getFullCoords()); + if(event.isBlockInHand()){ + event.setUseItemInHand(Result.DENY); + } + } + } else if(this.mapManager.blocksMap.containsKey(this.blockCoords.getFullCoords()) && this.permManager.hasSBPerm(this.player, "use", true)) { + if(this.haveCoolDown(this.player, this.blockCoords) || this.isDelayed(this.player, this.blockCoords)) { + return; + } + + this.log.info("[" + this.plugin.getName() + "] " + playerName + " triggered " + this.getName() + " ScriptBlock..."); + this.log.info("[" + this.plugin.getName() + "] at coords " + this.blockCoords.getFullCoords()); + OptionHandler read = new OptionHandler(this, this.player, this.blockCoords); + read.readScript(0); + if(event.isBlockInHand()){ + event.setUseItemInHand(Result.DENY); + } + } + } + + } +} diff --git a/src/main/java/scriptblock/listeners/PlayerWalkBlock.java b/src/main/java/scriptblock/listeners/PlayerWalkBlock.java new file mode 100644 index 0000000..61efaf9 --- /dev/null +++ b/src/main/java/scriptblock/listeners/PlayerWalkBlock.java @@ -0,0 +1,77 @@ +package scriptblock.listeners; + +import java.util.Hashtable; +import java.util.Map; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import scriptblock.BlockCoords; +import scriptblock.ScriptBlock; +import scriptblock.command.BindScript; +import scriptblock.managers.ScriptManager; +import scriptblock.options.OptionHandler; + +public class PlayerWalkBlock extends ScriptManager implements Listener { + private Map oldBlockCoords = new Hashtable(); + private Player player; + private BlockCoords blockCoords; + + public PlayerWalkBlock(ScriptBlock scriptBlock) { + super(scriptBlock, "walk", "sb"); + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + this.player = event.getPlayer(); + Block block = event.getClickedBlock(); + if(event.hasBlock()) { + String playerName = this.player.getName(); + BindScript blockInteract = (BindScript)this.mapManager.commandsWaitingMap.get(playerName); + if(blockInteract != null) { + String world = this.player.getWorld().getName(); + int x = block.getX(); + int y = block.getY(); + int z = block.getZ(); + this.blockCoords = new BlockCoords(world, x, y, z); + if(blockInteract.onEvent(this.blockCoords)) { + this.mapManager.commandsWaitingMap.remove(playerName); + this.log.info("[" + this.plugin.getName() + "] " + playerName + " bound \"" + blockInteract.getCommandType().name() + "\" " + this.getName() + " Script..."); + this.log.info("[" + this.plugin.getName() + "] at " + this.blockCoords.getFullCoords()); + } + } + } + + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + this.player = event.getPlayer(); + World world = this.player.getWorld(); + int X = this.player.getLocation().getBlockX(); + int Y = this.player.getLocation().getBlockY() - 1; + int Z = this.player.getLocation().getBlockZ(); + if(world.getBlockAt(X, Y, Z).getTypeId() != 0) { + String playerName = this.player.getName(); + String worldName = world.getName(); + this.blockCoords = new BlockCoords(worldName, X, Y, Z); + if(!this.oldBlockCoords.containsKey(playerName) || !((String)this.oldBlockCoords.get(playerName)).equals(this.blockCoords.getFullCoords())) { + this.oldBlockCoords.put(playerName, this.blockCoords.getFullCoords()); + if(this.mapManager.blocksMap.containsKey(this.blockCoords.getFullCoords()) && this.permManager.hasSBPerm(this.player, "use", false)) { + if(this.haveCoolDown(this.player, this.blockCoords) || this.isDelayed(this.player, this.blockCoords)) { + return; + } + + this.log.info("[" + this.plugin.getName() + "] " + playerName + " triggered " + this.getName() + " ScriptBlock..."); + this.log.info("[" + this.plugin.getName() + "] at coords " + this.blockCoords.getFullCoords()); + OptionHandler read = new OptionHandler(this, this.player, this.blockCoords); + read.readScript(0); + } + } + } + + } +} diff --git a/src/main/java/scriptblock/managers/ConfigParameters.java b/src/main/java/scriptblock/managers/ConfigParameters.java new file mode 100644 index 0000000..72f63e9 --- /dev/null +++ b/src/main/java/scriptblock/managers/ConfigParameters.java @@ -0,0 +1,48 @@ +package scriptblock.managers; + +import java.util.Iterator; +import scriptblock.config.Configuration; +import scriptblock.managers.FileManager; +import scriptblock.managers.MapManager; +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; + +public class ConfigParameters { + private final String showConsole = "ShowConsole"; + private final String sep = "."; + private ScriptManager scriptManager; + private MapManager mapManager; + private FileManager fileManager; + private Configuration config; + + public ConfigParameters(ScriptManager scriptManager) { + this.scriptManager = scriptManager; + this.mapManager = scriptManager.mapManager; + } + + public void init(FileManager fileManager) { + this.fileManager = fileManager; + this.config = fileManager.getConfig(); + } + + public void getPropFromConfig() { + Iterator var2 = this.mapManager.optionsList.iterator(); + + while(var2.hasNext()) { + Option option = (Option)var2.next(); + boolean debugMode = this.config.getBoolean("ShowConsole." + option.getName(), false); + option.setDebugMode(debugMode); + } + + } + + public void setDefaultsProps() { + Iterator var2 = this.mapManager.optionsList.iterator(); + + while(var2.hasNext()) { + Option option = (Option)var2.next(); + this.config.setProperty("ShowConsole." + option.getName(), Boolean.valueOf(false)); + } + + } +} diff --git a/src/main/java/scriptblock/managers/FileManager.java b/src/main/java/scriptblock/managers/FileManager.java new file mode 100644 index 0000000..d763fe2 --- /dev/null +++ b/src/main/java/scriptblock/managers/FileManager.java @@ -0,0 +1,211 @@ +package scriptblock.managers; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Logger; +import org.bukkit.plugin.java.JavaPlugin; +import scriptblock.SLAPI; +import scriptblock.ScriptBlock; +import scriptblock.config.Configuration; +import scriptblock.managers.ConfigParameters; +import scriptblock.managers.MapManager; + +public class FileManager { + private JavaPlugin plugin; + private File scriptBlockFolder; + private File scriptDataFolder; + private Logger log; + private MapManager mapManager; + private ConfigParameters configParam; + private File configFile; + private File scriptDataFile; + private File cooldownDataFile; + private Configuration config; + private Configuration scriptConfig; + + public FileManager(JavaPlugin plugin, MapManager mapManager, ConfigParameters configParam, String name) { + this.log = ScriptBlock.log; + this.plugin = plugin; + this.scriptBlockFolder = plugin.getDataFolder(); + this.scriptDataFolder = new File(this.scriptBlockFolder + "/BlocksData"); + this.scriptDataFolder.mkdirs(); + this.configFile = new File(this.scriptBlockFolder + File.separator + name + "_Config.yml"); + this.scriptDataFile = new File(this.scriptDataFolder.getPath() + File.separator + name + "_Scripts.yml"); + this.cooldownDataFile = new File(this.scriptDataFolder.getPath() + File.separator + name + "_Cooldowns.dat"); + this.config = new Configuration(this.configFile); + this.scriptConfig = new Configuration(this.scriptDataFile); + this.mapManager = mapManager; + this.configParam = configParam; + } + + public void init() { + this.loadConfigFile(); + this.loadScriptFile(); + this.loadCooldownFile(); + } + + public void loadScriptFile() { + if(this.scriptDataFile.exists()) { + if(this.scriptDataFile.length() > 0L) { + this.scriptConfig.load(); + Iterator var2 = this.scriptConfig.getKeys().iterator(); + + while(var2.hasNext()) { + String e = (String)var2.next(); + Iterator var4 = this.scriptConfig.getKeys(e + ".").iterator(); + + while(var4.hasNext()) { + String blockCoords = (String)var4.next(); + List macroList = this.scriptConfig.getList(e + "." + blockCoords + "."); + LinkedList commandList = new LinkedList(); + + for(int i = 0; i < macroList.size(); ++i) { + commandList.add(String.valueOf(macroList.get(i))); + } + + this.mapManager.blocksMap.put(e + "," + blockCoords, commandList); + } + } + + this.log.info("[" + this.plugin.getName() + "] " + this.scriptDataFile.getName() + " loaded !"); + } else { + this.log.info("[" + this.plugin.getName() + "] " + this.scriptDataFile.getName() + " is empty, loading aborded !"); + } + } else { + try { + this.scriptDataFile.createNewFile(); + } catch (IOException var8) { + var8.printStackTrace(); + } + + this.log.info("[" + this.plugin.getName() + "] " + this.scriptDataFile.getName() + " created !"); + } + + } + + public void loadCooldownFile() { + if(this.cooldownDataFile.exists()) { + if(this.cooldownDataFile.length() > 0L) { + try { + this.mapManager.cooldownMap = (HashMap)SLAPI.load(this.cooldownDataFile.getPath()); + this.log.info("[" + this.plugin.getName() + "] " + this.cooldownDataFile.getName() + " File Loaded !!!"); + } catch (Exception var6) { + this.log.info("[" + this.plugin.getName() + "] [ERROR] while loading " + this.cooldownDataFile.getName() + " File !"); + this.log.info("[" + this.plugin.getName() + "] at " + var6.getMessage()); + } + + long[] e = new long[1]; + if(this.mapManager.cooldownMap != null) { + e = (long[])this.mapManager.cooldownMap.get("disabledTime"); + Iterator var3 = this.mapManager.cooldownMap.keySet().iterator(); + + while(var3.hasNext()) { + String key = (String)var3.next(); + if(!key.equals("disabledTime")) { + long[] cooldownParams = (long[])this.mapManager.cooldownMap.get(key); + cooldownParams[2] += System.currentTimeMillis() - e[0]; + this.mapManager.cooldownMap.put(key, cooldownParams); + } + } + } + } else { + this.log.info("[" + this.plugin.getName() + "] " + this.cooldownDataFile.getName() + " is empty, loading aborded !"); + } + } else { + try { + this.cooldownDataFile.createNewFile(); + } catch (IOException var5) { + var5.printStackTrace(); + } + + this.log.info("[" + this.plugin.getName() + "] " + this.cooldownDataFile.getName() + " created !"); + } + + } + + public void loadConfigFile() { + this.configParam.init(this); + if(!this.configFile.exists()) { + try { + this.configFile.createNewFile(); + } catch (IOException var2) { + var2.printStackTrace(); + } + + this.configParam.setDefaultsProps(); + this.config.save(); + this.log.info("[" + this.plugin.getName() + "] " + this.configFile.getName() + " created !"); + } else { + this.config.load(); + this.configParam.getPropFromConfig(); + this.log.info("[" + this.plugin.getName() + "] " + this.configFile.getName() + " loaded !"); + } + + } + + public void saveDisabledTime(long time) { + String DisabledTimeKey = "disabledTime"; + long[] disabledTime = new long[]{time}; + this.mapManager.cooldownMap.put(DisabledTimeKey, disabledTime); + + try { + SLAPI.save(this.mapManager.cooldownMap, this.cooldownDataFile.getPath()); + } catch (Exception var6) { + this.log.info("[" + this.plugin.getName() + "] [ERROR] while saving the DisabledTime to " + this.cooldownDataFile.getName() + " !"); + this.log.info("[" + this.plugin.getName() + "] at " + var6.getMessage()); + } + + this.log.info("[" + this.plugin.getName() + "] Disabled Time Saved to " + this.cooldownDataFile.getName() + " !!!"); + } + + public static void YMLtoMap(Configuration config, HashMap BlocksMap) { + config.load(); + Iterator var3 = config.getKeys().iterator(); + + while(var3.hasNext()) { + String world = (String)var3.next(); + Iterator var5 = config.getKeys(world + ".").iterator(); + + while(var5.hasNext()) { + String blockCoords = (String)var5.next(); + List macroList = config.getList(world + "." + blockCoords + "."); + LinkedList commandList = new LinkedList(); + + for(int i = 0; i < macroList.size(); ++i) { + commandList.add(String.valueOf(macroList.get(i))); + } + + BlocksMap.put(world + "," + blockCoords, commandList); + } + } + + } + + public MapManager getMapManager() { + return this.mapManager; + } + + public Configuration getScriptConfig() { + return this.scriptConfig; + } + + public File getScriptDataFile() { + return this.scriptDataFile; + } + + public File getCooldownDataFile() { + return this.cooldownDataFile; + } + + public Configuration getConfig() { + return this.config; + } + + public File getConfigFile() { + return this.configFile; + } +} diff --git a/src/main/java/scriptblock/managers/MapManager.java b/src/main/java/scriptblock/managers/MapManager.java new file mode 100644 index 0000000..faf61da --- /dev/null +++ b/src/main/java/scriptblock/managers/MapManager.java @@ -0,0 +1,14 @@ +package scriptblock.managers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +public class MapManager { + public HashMap commandsWaitingMap = new HashMap(); + public HashMap blocksMap = new HashMap(); + public HashMap cooldownMap = new HashMap(); + public LinkedList optionsList = new LinkedList(); + public List delayList = new ArrayList(); +} diff --git a/src/main/java/scriptblock/managers/PermManager.java b/src/main/java/scriptblock/managers/PermManager.java new file mode 100644 index 0000000..9650649 --- /dev/null +++ b/src/main/java/scriptblock/managers/PermManager.java @@ -0,0 +1,118 @@ +package scriptblock.managers; + +import net.milkbowl.vault.permission.Permission; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class PermManager { + public static final String sep = "."; + public final String noPermMsg; + private Permission perm; + private final String scriptManagerName; + private final String pluginName; + private final String smanagerNode; + + public PermManager(Permission perm, String scriptManagerName, JavaPlugin plugin) { + this.perm = perm; + this.scriptManagerName = scriptManagerName; + this.pluginName = plugin.getName().toLowerCase(); + this.smanagerNode = this.pluginName + "." + scriptManagerName; + this.noPermMsg = new String(ChatColor.RED + "[" + plugin.getName() + "]" + " You don\'t have permission !"); + } + + public boolean playerInGroup(Player player, String group) { + return this.perm.playerInGroup(player, group); + } + + public boolean playerAddGroup(Player player, String group) { + return this.perm.playerAddGroup(player, group); + } + + public boolean playerRemoveGroup(Player player, String group) { + return this.perm.playerRemoveGroup(player, group); + } + + public boolean playerAdd(Player player, String permission) { + return this.perm.playerAdd(player, permission); + } + + public boolean playerAdd(String world, Player player, String permission) { + return this.perm.playerAdd(world, player.getName(), permission); + } + + public boolean playerRemove(Player player, String permission) { + return this.perm.playerRemove(player, permission); + } + + public boolean playerRemove(String world, Player player, String permission) { + return this.perm.playerRemove(world, player.getName(), permission); + } + + public boolean has(Player player, String permission) { + return this.perm.has(player, permission); + } + + private boolean hasSBmainPerm(Player player) { + return this.perm.has(player, this.pluginName + "." + "*"); + } + + private boolean hasScriptManagerPerm(Player player) { + return this.perm.has(player, this.smanagerNode + "." + "*") || this.hasSBmainPerm(player) || player.isOp(); + } + + public boolean hasSBPerm(Player player, String node, String type, boolean showMsg) { + return !this.perm.has(player, this.smanagerNode + "." + node + "." + type) && !this.perm.has(player, this.smanagerNode + "." + node + "." + "*") && !this.hasScriptManagerPerm(player)?(showMsg?this.noPerm(player):false):true; + } + + public boolean hasSBPerm(Player player, String[] typesArray, boolean showMsg) { + if(this.hasScriptManagerPerm(player)) { + return true; + } else { + StringBuilder permBuilder = (new StringBuilder()).append(this.smanagerNode); + + for(int i = 0; i < typesArray.length; ++i) { + String type = typesArray[i]; + permBuilder.append("." + type); + if(i == typesArray.length - 1 && this.perm.has(player, permBuilder.toString())) { + return true; + } + + if(this.perm.has(player, permBuilder.toString() + "." + "*")) { + return true; + } + } + + if(showMsg) { + return this.noPerm(player); + } else { + return false; + } + } + } + + public boolean hasSBPerm(Player player, String permNode, boolean showMsg) { + if(this.perm.has(player, this.smanagerNode + "." + permNode)) { + return true; + } else { + while(permNode.contains(".")) { + String lastnode = permNode.substring(permNode.lastIndexOf("."), permNode.length()); + permNode = permNode.replaceAll(lastnode, ""); + if(this.perm.has(player, this.smanagerNode + "." + permNode + "*")) { + return true; + } + } + + return this.hasScriptManagerPerm(player)?true:(showMsg?this.noPerm(player):false); + } + } + + private boolean noPerm(Player player) { + player.sendMessage(this.noPermMsg); + return false; + } + + public String getSmanagerNode() { + return this.smanagerNode; + } +} diff --git a/src/main/java/scriptblock/managers/ScriptManager.java b/src/main/java/scriptblock/managers/ScriptManager.java new file mode 100644 index 0000000..e5758ce --- /dev/null +++ b/src/main/java/scriptblock/managers/ScriptManager.java @@ -0,0 +1,98 @@ +package scriptblock.managers; + +import java.util.logging.Logger; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; +import scriptblock.BlockCoords; +import scriptblock.ScriptBlock; +import scriptblock.command.CommandHandler; +import scriptblock.managers.ConfigParameters; +import scriptblock.managers.FileManager; +import scriptblock.managers.MapManager; +import scriptblock.managers.PermManager; +import scriptblock.options.OptionManager; + +public abstract class ScriptManager implements Listener { + protected ScriptBlock scriptBlock = ScriptBlock.getInstance(); + protected Logger log; + protected JavaPlugin plugin; + private String name; + protected ConfigParameters configParam; + protected MapManager mapManager; + protected FileManager fileManager; + protected PermManager permManager; + protected OptionManager optionManager; + private CommandHandler commandHandler; + + public ScriptManager(JavaPlugin plugin, String eventName, String cmdName) { + this.log = ScriptBlock.log; + this.name = eventName; + this.plugin = plugin; + this.permManager = new PermManager(this.scriptBlock.getPerm(), this.name, plugin); + this.mapManager = new MapManager(); + this.optionManager = new OptionManager(this); + this.configParam = new ConfigParameters(this); + this.fileManager = new FileManager(plugin, this.mapManager, this.configParam, eventName); + this.commandHandler = new CommandHandler(this, cmdName); + this.init(); + } + + protected void init() { + this.optionManager.registerDefaultOptions(); + this.fileManager.init(); + } + + protected boolean haveCoolDown(Player player, BlockCoords blockCoords) { + long[] cooldownParams = (long[])this.mapManager.cooldownMap.get(blockCoords.getFullCoords()); + if(cooldownParams != null && cooldownParams[2] > System.currentTimeMillis()) { + int timeRemain = (int)((cooldownParams[2] - System.currentTimeMillis()) / 1000L); + short H = (short)(timeRemain / 3600); + byte mins = (byte)(timeRemain % 3600 / 60); + byte secs = (byte)(timeRemain % 3600 % 60); + player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] You must wait " + H + " H " + mins + " mins " + secs + " secs..."); + player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] to activate this again !"); + return true; + } else { + return false; + } + } + + protected boolean isDelayed(Player player, BlockCoords blockCoords) { + if(this.mapManager.delayList.contains(blockCoords.getFullCoords())) { + player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] You must wait to activate this again..."); + return true; + } else { + return false; + } + } + + public String getName() { + return this.name; + } + + public FileManager getFileManager() { + return this.fileManager; + } + + public MapManager getMapManager() { + return this.mapManager; + } + + public PermManager getPermManager() { + return this.permManager; + } + + public JavaPlugin getPlugin() { + return this.plugin; + } + + public OptionManager getOptionManager() { + return this.optionManager; + } + + public ConfigParameters getConfigParam() { + return this.configParam; + } +} diff --git a/src/main/java/scriptblock/options/Option.java b/src/main/java/scriptblock/options/Option.java new file mode 100644 index 0000000..09ef100 --- /dev/null +++ b/src/main/java/scriptblock/options/Option.java @@ -0,0 +1,35 @@ +package scriptblock.options; + +import scriptblock.options.OptionHandler; + +public abstract class Option { + private final String name; + private final String syntax; + private boolean inDebugMode; + + public Option(String name, String syntax) { + this.name = name; + this.syntax = syntax; + } + + public abstract boolean onOptionCall(OptionHandler var1); + + public String getName() { + return this.name; + } + + public String getSyntax() { + return this.syntax; + } + + public boolean showConsole() { + return this.inDebugMode; + } + + public void setDebugMode(boolean debugMode) { + this.inDebugMode = debugMode; + } + + public interface Permissible { + } +} diff --git a/src/main/java/scriptblock/options/OptionHandler.java b/src/main/java/scriptblock/options/OptionHandler.java new file mode 100644 index 0000000..5fddffa --- /dev/null +++ b/src/main/java/scriptblock/options/OptionHandler.java @@ -0,0 +1,169 @@ +package scriptblock.options; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.logging.Logger; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import scriptblock.BlockCoords; +import scriptblock.ScriptBlock; +import scriptblock.command.CommandCreate; +import scriptblock.managers.MapManager; +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; + +public class OptionHandler { + protected ScriptBlock scriptBlock = ScriptBlock.getInstance(); + protected Logger log; + private ScriptManager scriptManager; + private JavaPlugin plugin; + private LinkedList script; + private BlockCoords blockCoords; + private String scriptLine; + private Player player; + private int scriptLineIndex; + private MapManager mapManager; + // $FF: synthetic field + private static int[] $SWITCH_TABLE$scriptblock$options$OptionHandler$TextOpt; + + public OptionHandler(ScriptManager scriptManager, Player player, BlockCoords blockCoords) { + this.log = ScriptBlock.log; + this.scriptManager = scriptManager; + this.plugin = scriptManager.getPlugin(); + this.mapManager = scriptManager.getMapManager(); + this.blockCoords = blockCoords; + this.script = (LinkedList)this.mapManager.blocksMap.get(blockCoords.getFullCoords()); + this.player = player; + } + + public void readScript(int index) { + for(this.scriptLineIndex = index; this.scriptLineIndex < this.script.size(); ++this.scriptLineIndex) { + boolean haveOption = false; + this.scriptLine = (String)this.script.get(this.scriptLineIndex); + if(this.scriptLineIndex != 0 || !((String)this.script.get(this.scriptLineIndex)).startsWith(CommandCreate.authorNode)) { + OptionHandler.TextOpt[] var6; + int var5 = (var6 = OptionHandler.TextOpt.values()).length; + + for(int var4 = 0; var4 < var5; ++var4) { + OptionHandler.TextOpt option = var6[var4]; + if(this.scriptLine.contains(option.value)) { + ItemStack itemStack; + Material material; + switch($SWITCH_TABLE$scriptblock$options$OptionHandler$TextOpt()[option.ordinal()]) { + case 1: + this.scriptLine = this.scriptLine.replaceAll(OptionHandler.TextOpt.PLAYER.value, this.player.getName()); + break; + case 2: + itemStack = this.player.getItemInHand(); + if(itemStack != null) { + material = itemStack.getType(); + this.scriptLine = this.scriptLine.replaceAll(OptionHandler.TextOpt.ITEM_NAME.value, material.name()); + } else { + this.scriptLine = this.scriptLine.replaceAll(OptionHandler.TextOpt.ITEM_NAME.value, "NoName"); + } + break; + case 3: + itemStack = this.player.getItemInHand(); + if(itemStack != null) { + material = itemStack.getType(); + this.scriptLine = this.scriptLine.replaceAll(OptionHandler.TextOpt.ITEM_ID.value, String.valueOf(material.getId())); + } else { + this.scriptLine = this.scriptLine.replaceAll(OptionHandler.TextOpt.ITEM_ID.value, "0"); + } + } + } + } + + Iterator var10 = this.mapManager.optionsList.iterator(); + + while(var10.hasNext()) { + Option var9 = (Option)var10.next(); + if(this.scriptLine.startsWith(var9.getSyntax())) { + if(!var9.onOptionCall(this)) { + return; + } + + haveOption = true; + break; + } + } + + if(!haveOption) { + this.player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] BAD SCRIPT !"); + return; + } + } + } + + } + + public LinkedList getScript() { + return this.script; + } + + public BlockCoords getBlockCoords() { + return this.blockCoords; + } + + public String getScriptLine() { + return this.scriptLine; + } + + public Player getPlayer() { + return this.player; + } + + public ScriptManager getScriptManager() { + return this.scriptManager; + } + + public int getScriptLineIndex() { + return this.scriptLineIndex; + } + + // $FF: synthetic method + static int[] $SWITCH_TABLE$scriptblock$options$OptionHandler$TextOpt() { + int[] var10000 = $SWITCH_TABLE$scriptblock$options$OptionHandler$TextOpt; + if($SWITCH_TABLE$scriptblock$options$OptionHandler$TextOpt != null) { + return var10000; + } else { + int[] var0 = new int[OptionHandler.TextOpt.values().length]; + + try { + var0[OptionHandler.TextOpt.ITEM_ID.ordinal()] = 3; + } catch (NoSuchFieldError var3) { + ; + } + + try { + var0[OptionHandler.TextOpt.ITEM_NAME.ordinal()] = 2; + } catch (NoSuchFieldError var2) { + ; + } + + try { + var0[OptionHandler.TextOpt.PLAYER.ordinal()] = 1; + } catch (NoSuchFieldError var1) { + ; + } + + $SWITCH_TABLE$scriptblock$options$OptionHandler$TextOpt = var0; + return var0; + } + } + + public static enum TextOpt { + PLAYER(""), + ITEM_NAME(""), + ITEM_ID(""); + + public final String value; + + private TextOpt(String value) { + this.value = value; + } + } +} diff --git a/src/main/java/scriptblock/options/OptionManager.java b/src/main/java/scriptblock/options/OptionManager.java new file mode 100644 index 0000000..42364c4 --- /dev/null +++ b/src/main/java/scriptblock/options/OptionManager.java @@ -0,0 +1,101 @@ +package scriptblock.options; + +import java.util.LinkedList; +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; +import scriptblock.options.chat.ChatOptions; +import scriptblock.options.miscellaneous.Amount; +import scriptblock.options.miscellaneous.Cost; +import scriptblock.options.miscellaneous.ItemCost; +import scriptblock.options.permissions.BypassGroup; +import scriptblock.options.permissions.BypassOp; +import scriptblock.options.permissions.BypassPerm; +import scriptblock.options.permissions.PermOptions; +import scriptblock.options.time.Cooldown; +import scriptblock.options.time.Delay; + +public class OptionManager { + private ScriptManager scriptManager; + private LinkedList optionsList; + public Option cost; + public Option itemCost; + public Option amount; + public Option delay; + public Option cooldown; + public Option bypassOp; + public Option bypassGroup; + public Option bypassCsl; + public Option bypassPerm; + public Option permission; + public Option group; + public Option command; + public Option say; + public Option toPlayer; + public Option groupAdd; + public Option groupRemove; + public Option permAdd; + public Option permRemove; + + public OptionManager(ScriptManager scriptManager) { + this.scriptManager = scriptManager; + this.optionsList = scriptManager.getMapManager().optionsList; + } + + public void registerDefaultOptions() { + this.cost = new Cost(this.scriptManager); + this.itemCost = new ItemCost(this.scriptManager); + this.amount = new Amount(this.scriptManager); + this.delay = new Delay(this.scriptManager); + this.cooldown = new Cooldown(this.scriptManager); + this.bypassOp = new BypassOp(this.scriptManager); + this.bypassGroup = new BypassGroup(this.scriptManager); + this.bypassPerm = new BypassPerm(this.scriptManager); + this.bypassCsl = new PermOptions.BypassConsole(this.scriptManager); + this.permission = new PermOptions.Permission(this.scriptManager); + this.group = new PermOptions.Group(this.scriptManager); + this.command = new ChatOptions.Command(this.scriptManager); + this.say = new ChatOptions.Say(this.scriptManager); + this.toPlayer = new ChatOptions.ToPlayer(this.scriptManager); + this.groupAdd = new PermOptions.GroupAdd(this.scriptManager); + this.groupRemove = new PermOptions.GroupRemove(this.scriptManager); + this.permAdd = new PermOptions.PermAdd(this.scriptManager); + this.permRemove = new PermOptions.PermRemove(this.scriptManager); + this.addOption(this.cost); + this.addOption(this.itemCost); + this.addOption(this.amount); + this.addOption(this.delay); + this.addOption(this.cooldown); + this.addOption(this.bypassOp); + this.addOption(this.bypassGroup); + this.addOption(this.bypassPerm); + this.addOption(this.permission); + this.addOption(this.group); + this.addOption(this.command); + this.addOption(this.say); + this.addOption(this.toPlayer); + this.addOption(this.groupAdd); + this.addOption(this.groupRemove); + this.addOption(this.permAdd); + this.addOption(this.permRemove); + } + + public void addOption(Option option) { + this.optionsList.add(option); + } + + public void addOption(int index, Option option) { + this.optionsList.add(index, option); + } + + public void removeOption(int index) { + this.optionsList.remove(index); + } + + public LinkedList getOptionList() { + return this.optionsList; + } + + public void setOptionList(LinkedList optionList) { + this.optionsList = optionList; + } +} diff --git a/src/main/java/scriptblock/options/SBOption.java b/src/main/java/scriptblock/options/SBOption.java new file mode 100644 index 0000000..9b5dd0a --- /dev/null +++ b/src/main/java/scriptblock/options/SBOption.java @@ -0,0 +1,62 @@ +package scriptblock.options; + +import java.util.LinkedList; +import java.util.logging.Logger; +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.permission.Permission; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import scriptblock.BlockCoords; +import scriptblock.ScriptBlock; +import scriptblock.config.Configuration; +import scriptblock.managers.FileManager; +import scriptblock.managers.MapManager; +import scriptblock.managers.PermManager; +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; +import scriptblock.options.OptionHandler; + +public abstract class SBOption extends Option { + protected Logger log; + protected ScriptBlock scriptBlock; + protected JavaPlugin plugin; + protected ScriptManager scriptManager; + protected OptionHandler optionHandler; + protected PermManager permManager; + protected FileManager fileManager; + protected MapManager mapManager; + protected Configuration config; + protected Permission vaultPerm; + protected Economy eco; + protected Player player; + protected BlockCoords blockCoords; + protected LinkedList script; + protected String scriptLine; + protected int index; + + public SBOption(ScriptManager scriptManager, String name, String syntax) { + super(name, syntax); + this.log = ScriptBlock.log; + this.scriptBlock = ScriptBlock.getInstance(); + this.scriptManager = scriptManager; + this.plugin = scriptManager.getPlugin(); + this.fileManager = scriptManager.getFileManager(); + this.mapManager = scriptManager.getMapManager(); + this.permManager = scriptManager.getPermManager(); + this.vaultPerm = this.scriptBlock.getPerm(); + this.eco = this.scriptBlock.getEco(); + this.config = this.fileManager.getScriptConfig(); + } + + public boolean onOptionCall(OptionHandler optionHandler) { + this.optionHandler = optionHandler; + this.player = optionHandler.getPlayer(); + this.blockCoords = optionHandler.getBlockCoords(); + this.script = optionHandler.getScript(); + this.scriptLine = optionHandler.getScriptLine(); + this.index = optionHandler.getScriptLineIndex(); + return this.isValid(); + } + + public abstract boolean isValid(); +} diff --git a/src/main/java/scriptblock/options/chat/ChatOptions.java b/src/main/java/scriptblock/options/chat/ChatOptions.java new file mode 100644 index 0000000..2b35816 --- /dev/null +++ b/src/main/java/scriptblock/options/chat/ChatOptions.java @@ -0,0 +1,42 @@ +package scriptblock.options.chat; + +import scriptblock.managers.ScriptManager; +import scriptblock.options.SBOption; + +public class ChatOptions { + public static class Command extends SBOption { + public Command(ScriptManager scriptManager) { + super(scriptManager, "command", "@command /"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst(this.getSyntax(), ""); + this.player.performCommand(this.scriptLine); + return true; + } + } + + public static class Say extends SBOption { + public Say(ScriptManager scriptManager) { + super(scriptManager, "say", "@say "); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst(this.getSyntax(), ""); + this.player.chat(this.scriptLine); + return true; + } + } + + public static class ToPlayer extends SBOption { + public ToPlayer(ScriptManager scriptManager) { + super(scriptManager, "toplayer", "@player "); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst(this.getSyntax(), ""); + this.player.sendMessage(this.scriptLine); + return true; + } + } +} diff --git a/src/main/java/scriptblock/options/miscellaneous/Amount.java b/src/main/java/scriptblock/options/miscellaneous/Amount.java new file mode 100644 index 0000000..7ba6c14 --- /dev/null +++ b/src/main/java/scriptblock/options/miscellaneous/Amount.java @@ -0,0 +1,35 @@ +package scriptblock.options.miscellaneous; + +import scriptblock.managers.ScriptManager; +import scriptblock.options.SBOption; + +public class Amount extends SBOption { + public Amount(ScriptManager scriptManager) { + super(scriptManager, "amount", "@amount:"); + } + + public boolean isValid() { + String amount = this.scriptLine.replace(this.getSyntax(), ""); + int remain = Integer.parseInt(amount) - 1; + String world = this.blockCoords.world; + String coords = this.blockCoords.getCoords(); + String fullCoords = this.blockCoords.getFullCoords(); + if(remain > 0) { + this.scriptLine = this.scriptLine.replaceFirst(amount, String.valueOf(remain)); + this.script.set(this.index, this.scriptLine); + this.mapManager.blocksMap.put(coords, this.script); + this.config.removeProperty(world + "." + coords + "."); + this.config.setProperty(world + "." + coords + ".", this.script); + this.config.save(); + this.log.info("Block (" + fullCoords + ") Remaining Charge : " + remain); + } else { + this.mapManager.blocksMap.remove(fullCoords); + this.config.removeProperty(world + "." + coords); + this.config.save(); + this.log.info("[" + this.plugin.getName() + "] No More Charge at : " + fullCoords + "..."); + this.log.info("[" + this.plugin.getName() + "] " + fullCoords + " removed from BlocksData.yml !"); + } + + return true; + } +} diff --git a/src/main/java/scriptblock/options/miscellaneous/Cost.java b/src/main/java/scriptblock/options/miscellaneous/Cost.java new file mode 100644 index 0000000..4b05f80 --- /dev/null +++ b/src/main/java/scriptblock/options/miscellaneous/Cost.java @@ -0,0 +1,33 @@ +package scriptblock.options.miscellaneous; + +import org.bukkit.ChatColor; +import scriptblock.managers.ScriptManager; +import scriptblock.options.SBOption; + +public class Cost extends SBOption { + public Cost(ScriptManager scriptManager) { + super(scriptManager, "cost", "$cost:"); + } + + public boolean isValid() { + if(this.eco != null) { + this.scriptLine = this.scriptLine.replace(this.getSyntax(), ""); + double cost = Double.parseDouble(this.scriptLine); + String playerName = this.player.getName(); + if(this.eco.getBalance(playerName) >= cost) { + this.eco.withdrawPlayer(playerName, cost); + this.player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] Your Account has been debited of " + ChatColor.WHITE + this.eco.format(cost) + ChatColor.RED + " !"); + return true; + } else { + this.player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] You don\'t have enough money to use this !"); + return false; + } + } else { + this.log.info("Error while performing the Script on : " + this.blockCoords.getFullCoords()); + this.log.info("Reason : No Economy plugin detected !]"); + this.player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] Error ! No Economy Plugin Detected !"); + this.player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] Please, Contact your Administrator."); + return false; + } + } +} diff --git a/src/main/java/scriptblock/options/miscellaneous/ItemCost.java b/src/main/java/scriptblock/options/miscellaneous/ItemCost.java new file mode 100644 index 0000000..9a9ffc6 --- /dev/null +++ b/src/main/java/scriptblock/options/miscellaneous/ItemCost.java @@ -0,0 +1,61 @@ +package scriptblock.options.miscellaneous; + +import java.util.ArrayList; +import java.util.Iterator; +import org.bukkit.ChatColor; +import org.bukkit.inventory.ItemStack; +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; +import scriptblock.options.SBOption; + +public class ItemCost extends SBOption implements Option.Permissible { + public ItemCost(ScriptManager scriptManager) { + super(scriptManager, "itemcost", "$item:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replace(this.getSyntax(), ""); + String[] itemInfos = this.scriptLine.split(" "); + int requiredAmount = Integer.parseInt(itemInfos[1]); + short metaData = 0; + int requiredItemId; + if(itemInfos[0].contains(":")) { + String[] inventory = itemInfos[0].split(":"); + requiredItemId = Integer.parseInt(inventory[0]); + metaData = Short.parseShort(inventory[1]); + } else { + requiredItemId = Integer.parseInt(itemInfos[0]); + } + + ItemStack[] var11 = this.player.getInventory().getContents(); + boolean amount = false; + ArrayList validStackIndexList = new ArrayList(var11.length); + + for(int i = 0; i < var11.length; ++i) { + if(var11[i] != null && var11[i].getTypeId() == requiredItemId && var11[i].getDurability() == metaData) { + int var12 = var11[i].getAmount(); + requiredAmount -= var12; + if(requiredAmount <= 0) { + int index; + for(Iterator var10 = validStackIndexList.iterator(); var10.hasNext(); var11[index] = null) { + index = ((Integer)var10.next()).intValue(); + } + + if(requiredAmount == 0) { + var11[i] = null; + } else { + var11[i] = new ItemStack(requiredItemId, requiredAmount * -1, metaData); + } + + this.player.getInventory().setContents(var11); + return true; + } + + validStackIndexList.add(Integer.valueOf(i)); + } + } + + this.player.sendMessage(ChatColor.RED + "[" + this.plugin.getName() + "] You don\'t have the required item(s) to use this !"); + return false; + } +} diff --git a/src/main/java/scriptblock/options/permissions/BypassGroup.java b/src/main/java/scriptblock/options/permissions/BypassGroup.java new file mode 100644 index 0000000..37d7384 --- /dev/null +++ b/src/main/java/scriptblock/options/permissions/BypassGroup.java @@ -0,0 +1,29 @@ +package scriptblock.options.permissions; + +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; +import scriptblock.options.SBOption; + +public class BypassGroup extends SBOption implements Option.Permissible { + public BypassGroup(ScriptManager scriptManager) { + super(scriptManager, "bypass_group", "@bypassGROUP:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst(this.getSyntax(), ""); + String access = this.scriptLine.substring(0, this.scriptLine.indexOf(" /")); + this.scriptLine = this.scriptLine.replaceFirst(access + " /", ""); + if(!this.vaultPerm.playerInGroup(this.player, access)) { + try { + this.vaultPerm.playerAddGroup(this.player, access); + this.player.performCommand(this.scriptLine); + } finally { + this.vaultPerm.playerRemoveGroup(this.player, access); + } + } else { + this.player.performCommand(this.scriptLine); + } + + return true; + } +} diff --git a/src/main/java/scriptblock/options/permissions/BypassOp.java b/src/main/java/scriptblock/options/permissions/BypassOp.java new file mode 100644 index 0000000..059b947 --- /dev/null +++ b/src/main/java/scriptblock/options/permissions/BypassOp.java @@ -0,0 +1,26 @@ +package scriptblock.options.permissions; + +import scriptblock.managers.ScriptManager; +import scriptblock.options.SBOption; + +public class BypassOp extends SBOption { + public BypassOp(ScriptManager scriptManager) { + super(scriptManager, "bypass_op", "@bypass /"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst(this.getSyntax(), ""); + if(!this.player.isOp()) { + try { + this.player.setOp(true); + this.player.performCommand(this.scriptLine); + } finally { + this.player.setOp(false); + } + } else { + this.player.performCommand(this.scriptLine); + } + + return true; + } +} diff --git a/src/main/java/scriptblock/options/permissions/BypassPerm.java b/src/main/java/scriptblock/options/permissions/BypassPerm.java new file mode 100644 index 0000000..2d712dc --- /dev/null +++ b/src/main/java/scriptblock/options/permissions/BypassPerm.java @@ -0,0 +1,36 @@ +package scriptblock.options.permissions; + +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; +import scriptblock.options.SBOption; + +public class BypassPerm extends SBOption implements Option.Permissible { + private boolean hadPerm; + + public BypassPerm(ScriptManager scriptManager) { + super(scriptManager, "bypass_perm", "@bypassPERM:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst(this.getSyntax(), ""); + String access = this.scriptLine.substring(0, this.scriptLine.indexOf(" /")); + this.scriptLine = this.scriptLine.replaceFirst(access + " /", ""); + if(!this.vaultPerm.playerHas(this.player, access)) { + this.vaultPerm.playerAdd(this.player, access); + } else { + this.hadPerm = true; + } + + try { + this.player.performCommand(this.scriptLine); + } finally { + if(!this.hadPerm) { + this.vaultPerm.playerRemove(this.player, access); + } + + } + + this.hadPerm = false; + return true; + } +} diff --git a/src/main/java/scriptblock/options/permissions/PermOptions.java b/src/main/java/scriptblock/options/permissions/PermOptions.java new file mode 100644 index 0000000..a584b47 --- /dev/null +++ b/src/main/java/scriptblock/options/permissions/PermOptions.java @@ -0,0 +1,118 @@ +package scriptblock.options.permissions; + +import org.bukkit.ChatColor; +import org.bukkit.Server; +import scriptblock.managers.ScriptManager; +import scriptblock.options.Option; +import scriptblock.options.SBOption; + +public class PermOptions { + public static class BypassConsole extends SBOption { + public BypassConsole(ScriptManager scriptManager) { + super(scriptManager, "console", "@CONSOLE /"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceAll(this.getSyntax(), ""); + Server server = this.scriptBlock.getServer(); + server.dispatchCommand(server.getConsoleSender(), this.scriptLine); + return true; + } + } + + public static class Group extends SBOption implements Option.Permissible { + public Group(ScriptManager scriptManager) { + super(scriptManager, "group", "@group:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replace(this.getSyntax(), ""); + if(!this.permManager.playerInGroup(this.player, this.scriptLine)) { + this.player.sendMessage(ChatColor.RED + "[ScriptBlock] Only members of the " + this.scriptLine + " group can use this !!"); + return false; + } else { + return true; + } + } + } + + public static class GroupAdd extends SBOption implements Option.Permissible { + public GroupAdd(ScriptManager scriptManager) { + super(scriptManager, "group_add", "@groupADD:"); + } + + public boolean isValid() { + String group = this.scriptLine.replaceFirst(this.getSyntax(), ""); + if(!this.permManager.playerInGroup(this.player, group)) { + this.permManager.playerAddGroup(this.player, group); + } + + return true; + } + } + + public static class GroupRemove extends SBOption implements Option.Permissible { + public GroupRemove(ScriptManager scriptManager) { + super(scriptManager, "group_remove", "@groupREMOVE:"); + } + + public boolean isValid() { + String group = this.scriptLine.replaceFirst(this.getSyntax(), ""); + this.permManager.playerRemoveGroup(this.player, group); + return true; + } + } + + public static class PermAdd extends SBOption implements Option.Permissible { + public PermAdd(ScriptManager scriptManager) { + super(scriptManager, "perm_add", "@permADD:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replace(this.getSyntax(), ""); + if(!this.scriptBlock.getPerm().has(this.player, this.scriptLine)) { + if(!this.scriptLine.contains("/")) { + this.permManager.playerAdd(this.player, this.scriptLine); + } else { + String world = this.scriptLine.substring(0, this.scriptLine.indexOf("/")); + this.scriptLine = this.scriptLine.replaceFirst(world + "/", ""); + this.permManager.playerAdd(world, this.player, this.scriptLine); + } + } + + return true; + } + } + + public static class PermRemove extends SBOption implements Option.Permissible { + public PermRemove(ScriptManager scriptManager) { + super(scriptManager, "perm_remove", "@permREMOVE:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replace(this.getSyntax(), ""); + if(!this.scriptBlock.getPerm().has(this.player, this.scriptLine)) { + if(!this.scriptLine.contains("/")) { + this.permManager.playerAdd(this.player, this.scriptLine); + } else { + String world = this.scriptLine.substring(0, this.scriptLine.indexOf("/")); + this.scriptLine = this.scriptLine.replaceFirst(world + "/", ""); + this.permManager.playerAdd(world, this.player, this.scriptLine); + } + } + + return true; + } + } + + public static class Permission extends SBOption implements Option.Permissible { + public Permission(ScriptManager scriptManager) { + super(scriptManager, "permission", "@perm:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replace(this.getSyntax(), ""); + return this.permManager.has(this.player, this.scriptLine); + } + } +} diff --git a/src/main/java/scriptblock/options/time/Cooldown.java b/src/main/java/scriptblock/options/time/Cooldown.java new file mode 100644 index 0000000..02315a5 --- /dev/null +++ b/src/main/java/scriptblock/options/time/Cooldown.java @@ -0,0 +1,29 @@ +package scriptblock.options.time; + +import scriptblock.SLAPI; +import scriptblock.managers.ScriptManager; +import scriptblock.options.SBOption; + +public class Cooldown extends SBOption { + public Cooldown(ScriptManager scriptManager) { + super(scriptManager, "cooldown", "@cooldown:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst(this.getSyntax(), ""); + long delay = Long.parseLong(this.scriptLine) * 60000L; + long[] cooldownParams = new long[]{System.currentTimeMillis(), delay, 0L}; + cooldownParams[2] = cooldownParams[0] + cooldownParams[1]; + this.mapManager.cooldownMap.put(this.blockCoords.getFullCoords(), cooldownParams); + + try { + SLAPI.save(this.mapManager.cooldownMap, this.fileManager.getCooldownDataFile().getPath()); + this.log.info("CoolDown Data saved !"); + } catch (Exception var5) { + this.log.info("[ERROR] while saving CooldownBlockList to " + this.fileManager.getCooldownDataFile().getName() + " ![ERROR]"); + this.log.info("at " + var5.getMessage()); + } + + return true; + } +} diff --git a/src/main/java/scriptblock/options/time/Delay.java b/src/main/java/scriptblock/options/time/Delay.java new file mode 100644 index 0000000..cd80069 --- /dev/null +++ b/src/main/java/scriptblock/options/time/Delay.java @@ -0,0 +1,23 @@ +package scriptblock.options.time; + +import scriptblock.managers.ScriptManager; +import scriptblock.options.SBOption; + +public class Delay extends SBOption implements Runnable { + public Delay(ScriptManager scriptManager) { + super(scriptManager, "delay", "@delay:"); + } + + public boolean isValid() { + this.scriptLine = this.scriptLine.replaceFirst("@delay:", ""); + long delay = Long.parseLong(this.scriptLine) * 20L; + this.mapManager.delayList.add(this.blockCoords.getFullCoords()); + this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this, delay); + return false; + } + + public void run() { + this.mapManager.delayList.remove(this.blockCoords.getFullCoords()); + this.optionHandler.readScript(this.index + 1); + } +} diff --git a/plugin.yml b/src/main/resources/plugin.yml similarity index 92% rename from plugin.yml rename to src/main/resources/plugin.yml index e976519..f8ee471 100644 --- a/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,14 +1,14 @@ -name: ScriptBlock -main: scriptblock.ScriptBlock -version: 0.8.7 -description: Allow you to add Commands Script to any Blocks. -author: Shereis -depend: [Vault] -softdepend: [bPermissions, PermissionsEx, iConomy, BOSEconomy, Currency, MultiCurrency] -commands: - sbinteract : - description: - usage: - sbwalk: - description: +name: ScriptBlock +main: scriptblock.ScriptBlock +version: 0.8.72 +description: Allow you to add Commands Script to any Blocks. +author: Shereis +depend: [Vault] +softdepend: [bPermissions, PermissionsEx, iConomy, BOSEconomy, Currency, MultiCurrency] +commands: + sbinteract : + description: + usage: + sbwalk: + description: usage: \ No newline at end of file diff --git a/src/scriptblock/BlockCoords.java b/src/scriptblock/BlockCoords.java deleted file mode 100644 index 2fdd133..0000000 --- a/src/scriptblock/BlockCoords.java +++ /dev/null @@ -1,28 +0,0 @@ -package scriptblock; - -public class BlockCoords { - - public String world; - public int x; - public int y; - public int z; - - private String coords ; - private String fullCoords ; - - public BlockCoords(String world, int x, int y, int z) - { - this.world = world ; - this.x = x ; - this.y = y ; - this.z = z ; - this.coords = ( x+","+y+","+z ) ; - this.fullCoords = ( world+","+coords ) ; - } - - public String getCoords() - { return coords ; } - - public String getFullCoords() - { return fullCoords ; } -} diff --git a/src/scriptblock/SLAPI.java b/src/scriptblock/SLAPI.java deleted file mode 100644 index 14bcde1..0000000 --- a/src/scriptblock/SLAPI.java +++ /dev/null @@ -1,27 +0,0 @@ -package scriptblock; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -/** SLAPI = Saving/Loading API - * API for Saving and Loading Objects. - * @author Tomsik68 - */ -public class SLAPI -{ - public static void save(Object obj,String path) throws Exception - { - ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path)); - oos.writeObject(obj); - oos.flush(); - oos.close(); - } - public static Object load(String path) throws Exception - { - ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path)); - Object result = ois.readObject(); - ois.close(); - return result; - } -} \ No newline at end of file diff --git a/src/scriptblock/ScriptBlock.java b/src/scriptblock/ScriptBlock.java deleted file mode 100644 index e75f16c..0000000 --- a/src/scriptblock/ScriptBlock.java +++ /dev/null @@ -1,133 +0,0 @@ -package scriptblock; - -import java.util.ArrayList; -import java.util.logging.Logger; - -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.permission.Permission; - -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - -import scriptblock.listeners.PlayerInteractBlock; -import scriptblock.listeners.PlayerWalkBlock; -import scriptblock.managers.ConfigParameters; -import scriptblock.managers.ScriptManager; - -public class ScriptBlock extends JavaPlugin { - - private static ScriptBlock instance ; - - public static Logger log = Logger.getLogger("Minecraft") ; - - private ArrayList scriptManagerList = new ArrayList () ; - - private PlayerInteractBlock playerInteractBlock ; - private PlayerWalkBlock playerWalkBlock ; - - private PluginManager pm ; - private Permission perm; - private Economy eco ; - - - @Override - public void onEnable() { - - //Initialization - - instance = this ; - pm = getServer().getPluginManager() ; - hookVault() ; - - - //Listeners Initialization... - playerInteractBlock = new PlayerInteractBlock(this) ; - playerWalkBlock = new PlayerWalkBlock(this) ; - - //Events Registration - - register(playerInteractBlock, this) ; - register(playerWalkBlock, this) ; - - log.info("[ScriptBlock] Enabled !!!"); - } - - @Override - public void onDisable() - { - //Saving the Time at witch the server Shut Down. - - long t = System.currentTimeMillis() ; - - for (ScriptManager scriptManager : scriptManagerList ) - { scriptManager.getFileManager().saveDisabledTime(t) ; } - - instance = null ; - log.info("[ScriptBlock] Disabled !!!"); - } - - public void register(ScriptManager scriptManager, JavaPlugin plugin) - { - scriptManagerList.add(scriptManager) ; - pm.registerEvents(scriptManager, plugin); - } - - - public void hookVault() - { - if ( pm.isPluginEnabled("Vault") ){ //TODO remove this ? - - //Permission Plugin Registration - RegisteredServiceProvider < Permission > permissionProvider - = getServer().getServicesManager().getRegistration( net.milkbowl.vault.permission.Permission.class ) ; - - if (permissionProvider != null) { - perm = permissionProvider.getProvider(); - log.info("[ScriptBlock] "+perm.getName()+" found !"); - } - else { - log.info("[ScriptBlock] No Permissions Plugin found !"); - log.info("[ScriptBlock] Do Not use (@bypass:'group') Option !"); - } - - //Economy Plugin Registration - RegisteredServiceProvider < Economy > economyProvider - = getServer().getServicesManager().getRegistration( net.milkbowl.vault.economy.Economy.class ) ; - - if (economyProvider != null) { - eco = economyProvider.getProvider(); - log.info("[ScriptBlock] "+eco.getName()+" found !"); - } - - else { - log.info("[ScriptBlock] NO Economy Plugin found !") ; - log.info("[ScriptBlock] Do not use '$cost:' Option") ; - } - - } - else { - log.info("[ScriptBlock] Vault is not Installed ! "); - log.info("[ScriptBlock] Permission, and Economy Options won't work !") ; - } - - } - - public Permission getPerm() { - return perm; - } - - public Economy getEco() { - return eco; - } - - public static ScriptBlock getInstance() { - return instance; - } - - public ArrayList getScriptManagerList() { - return scriptManagerList; - } - - -} diff --git a/src/scriptblock/command/BindScript.java b/src/scriptblock/command/BindScript.java deleted file mode 100644 index 51bd459..0000000 --- a/src/scriptblock/command/BindScript.java +++ /dev/null @@ -1,98 +0,0 @@ -package scriptblock.command; - -import java.util.LinkedList; -import java.util.logging.Logger; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import scriptblock.BlockCoords; -import scriptblock.ScriptBlock; -import scriptblock.command.CommandHandler.CommandType; -import scriptblock.managers.FileManager; -import scriptblock.managers.MapManager; -import scriptblock.managers.PermManager; -import scriptblock.managers.ScriptManager; - -public abstract class BindScript -{ - protected ScriptBlock scriptBlock = ScriptBlock.getInstance() ; - protected Logger log = ScriptBlock.log ; - protected JavaPlugin plugin ; - - protected ScriptManager scriptManager; - protected CommandType commandType; - - - protected FileManager fileManager; - protected MapManager mapManager ; - protected PermManager permManager ; - - protected Player commandSender ; - - protected String statusCancelled ; - protected String[] noAccessPermMsg ; - - - public BindScript(ScriptManager scriptManager, Player commandSender) - { this(scriptManager, commandSender, null) ; } - - public BindScript(ScriptManager scriptManager, Player commandSender, CommandType commandType) - { - this.plugin = scriptManager.getPlugin() ; - this.scriptManager = scriptManager ; - this.commandType = commandType ; - this.mapManager = scriptManager.getMapManager() ; - this.fileManager = scriptManager.getFileManager() ; - this.permManager = scriptManager.getPermManager() ; - this.commandSender = commandSender ; - - this.statusCancelled = new String( ChatColor.RED + "["+plugin.getName()+"] "+commandType.name()+" status cancelled !" ) ; - this.noAccessPermMsg = - new String[] { permManager.noPermMsg , - ( ChatColor.RED + "["+plugin.getName()+"] You can't \""+commandType.name()+"\" scripts you don't own!" ) } ; - } - - public abstract boolean onEvent(BlockCoords blockcoords) ; - - - protected boolean canAccessScript(BlockCoords blockCoords) - { - LinkedList commandList = mapManager.blocksMap.get( blockCoords.getFullCoords() ) ; - - String perm = new String( "modify" + PermManager.sep + commandType.name() ) ; - - if ( commandList == null ) return true ; - - String firstLine = commandList.getFirst() ; - - if ( firstLine.startsWith(CommandCreate.authorNode) ) - { - - firstLine = firstLine.replaceFirst(CommandCreate.authorNode, "") ; - String[] scriptInfos = firstLine.split("/"); - String authorName = scriptInfos[0] ; - String authorGroup = scriptInfos[1] ; - - if ( !commandSender.getName().equals(authorName) && !permManager.hasSBPerm(commandSender, perm + PermManager.sep + authorGroup , false ) ) - { - commandSender.sendMessage(noAccessPermMsg) ; - return false ; - } - else - return true ; - } - - - if (permManager.hasSBPerm(commandSender, perm, false) )return true ; - - else { - commandSender.sendMessage(noAccessPermMsg) ; - return false ; - - } - } - - public CommandType getCommandType() - { return commandType; } -} diff --git a/src/scriptblock/command/CommandAdd.java b/src/scriptblock/command/CommandAdd.java deleted file mode 100644 index c7ef760..0000000 --- a/src/scriptblock/command/CommandAdd.java +++ /dev/null @@ -1,137 +0,0 @@ -package scriptblock.command; - -import java.util.LinkedList; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import scriptblock.SLAPI; - -import scriptblock.BlockCoords; -import scriptblock.command.CommandHandler.CommandType; -import scriptblock.managers.ScriptManager; - - -@SuppressWarnings("deprecation") -public class CommandAdd extends CreateManager { - - private String[] commandBody; - - public CommandAdd(ScriptManager scriptManager, String[] commandBody, Player commandSender, CommandType commandType) - { - super(scriptManager, commandSender, commandType) ; - this.commandBody = commandBody ; - } - - public boolean isValid() - { - if (commandBody.length == 0) - { - commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] You must add argument !") ; - return false ; - } - - String playerName = commandSender.getName() ; - boolean alreadyExist = false ; - Object obj = mapManager.commandsWaitingMap.get(playerName) ; - - if ( obj != null ) - { - alreadyExist = true ; - - //TODO remove unecessary code VVVVVV - if (obj instanceof CommandCreate) - { - CommandCreate commandCreate = (CommandCreate) obj ; - commandList = commandCreate.commandList ; - } - else if (obj instanceof CommandAdd) - { - CommandAdd commandAdd = (CommandAdd) obj ; - commandList = commandAdd.commandList ; - } - else { commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] ERROR in CommandAdd !") ; } - - } - else { commandList = new LinkedList(); } - - LinkedList tempList = new LinkedList() ; - String text = ArrayToString(commandBody); - tempList = CommandScript(text, tempList); - - - if ( !opCheck(tempList) ) - { return false ; } - - else if ( optionCheck(tempList) ) - { commandList.addAll( tempList ) ; } - - else return false ; - - if (alreadyExist) - { - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Command Successfully added to the Script !"); - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Click on a block to bind the Script to it..."); - return false ; - } - else - { - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Use /sbadd command to add another script or..."); - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Click on a block to add the Script to it !"); - return true ; - } - } - - - @Override - public boolean onEvent(BlockCoords blockcoords) - { - if ( mapManager.blocksMap.containsKey( blockcoords.getFullCoords() )) { - add( blockcoords ) ; - return true ; - } - else { - - commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] There is no script on this block."); - commandSender.sendMessage(statusCancelled) ; - return true; - } - } - - public boolean add( BlockCoords blockcoords ) - { - if ( !canAccessScript(blockcoords) ) - { commandSender.sendMessage(statusCancelled) ; return true ; } - - String world = blockcoords.world ; - String FullBlockCoords = blockcoords.getFullCoords() ; - String blockCoords = blockcoords.getCoords() ; - - LinkedList finalList = mapManager.blocksMap.get( FullBlockCoords ) ; - finalList.addAll(commandList) ; - mapManager.blocksMap.put(FullBlockCoords, finalList) ; - - //Saving blocksMap... - - fileManager.getScriptConfig().setProperty(world+"."+blockCoords+".", finalList ); - fileManager.getScriptConfig().save(); - - //Removing CoolDown and delay... - - if (mapManager.cooldownMap.containsKey( FullBlockCoords )) - { - mapManager.cooldownMap.remove(FullBlockCoords); - try { - SLAPI.save(mapManager.cooldownMap, fileManager.getCooldownDataFile().getPath() ); - log.info("cooldown Saved to "+fileManager.getCooldownDataFile().getName()+" !"); - } - catch (Exception e) { - log.info("[ERROR] while saving cooldownBlockMap to "+fileManager.getCooldownDataFile().getName()+" ![ERROR]"); - log.info("at "+e.getMessage()); - } - } - - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Text Successfully bound !"); - return true ; - } - -} diff --git a/src/scriptblock/command/CommandCreate.java b/src/scriptblock/command/CommandCreate.java deleted file mode 100644 index 44c946e..0000000 --- a/src/scriptblock/command/CommandCreate.java +++ /dev/null @@ -1,60 +0,0 @@ -package scriptblock.command; - -import java.util.LinkedList; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import scriptblock.BlockCoords; -import scriptblock.command.CommandHandler.CommandType; -import scriptblock.managers.ScriptManager; - -public class CommandCreate extends CreateManager { - - public static String authorNode = "Author:" ; - - private String[] body ; - - public CommandCreate(ScriptManager scriptManager, String[] cmdBody, Player commandSender, CommandType commandType ) - { - super(scriptManager, commandSender, commandType ) ; - this.body = cmdBody ; - } - - public boolean isValid() - { - if (body.length > 0) { - - String playerName = commandSender.getName() ; - - for ( ScriptManager scriptManager : scriptBlock.getScriptManagerList() ) - { - if ( !scriptManager.getMapManager().commandsWaitingMap.containsKey(playerName) ) - { continue ; } - - else { - commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] You must validate your previous action !"); - return false ; - } - } - - String text = ArrayToString(body); - commandList = new LinkedList(); - commandList = CommandScript(text, commandList); - - if ( !opCheck(commandList) ) return false ; - else if ( optionCheck(commandList) ) - { - commandList.add( 0 , authorNode+playerName+"/"+scriptBlock.getPerm().getPrimaryGroup(commandSender) ) ; - commandSender.sendMessage( ChatColor.GREEN + "["+plugin.getName()+"] Click on a block to bind the text to it...") ; - return true ; - } - else return false ; - } - else { commandSender.sendMessage( ChatColor.RED + "["+plugin.getName()+"] You must add arguments !") ; } - - return false ; - } - - @Override - public boolean onEvent(BlockCoords blockcoords) - { return create(blockcoords); } -} diff --git a/src/scriptblock/command/CommandHandler.java b/src/scriptblock/command/CommandHandler.java deleted file mode 100644 index af7965d..0000000 --- a/src/scriptblock/command/CommandHandler.java +++ /dev/null @@ -1,130 +0,0 @@ -package scriptblock.command; - -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import scriptblock.managers.FileManager; -import scriptblock.managers.MapManager; -import scriptblock.managers.PermManager; -import scriptblock.managers.ScriptManager; - -public class CommandHandler implements CommandExecutor{ - - - public JavaPlugin plugin; - public ScriptManager scriptManager; - -// public final String[] permArray ; - - public Player commandsender ; - public String[] body ; - - protected MapManager mapManager; - private PermManager perm ; - private String pluginCommand; - - - - public CommandHandler(ScriptManager scriptManager, String pluginCommand) - { - this.scriptManager = scriptManager ; - this.pluginCommand = pluginCommand ; - this.mapManager = scriptManager.getMapManager() ; - this.plugin = scriptManager.getPlugin() ; - this.perm = scriptManager.getPermManager() ; -// this.permArray = new String[] { scriptManager.getName() , "command" , null } ; - - //Registering commands to Bukkit. -// for ( CommandType command : CommandType.values() ) - { plugin.getCommand( pluginCommand+scriptManager.getName() ).setExecutor(this) ; } - } - - public enum CommandType - { - create, - add, - remove , - view, - reload ; - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] body) - { - if (sender instanceof Player) - { - this.body = body ; - this.commandsender = (Player) sender ; - - String playerName = commandsender.getName() ; - - for ( CommandType commandType : CommandType.values() ) - { - if ( body.length > 0 && body[0].equalsIgnoreCase( commandType.name() ) ) - { -// permArray[2] = commandType.name() ; - - if ( perm.hasSBPerm(commandsender, "command" + PermManager.sep + commandType.name() , true) ) - { - body[0] = null ; - - switch(commandType) - { - case create : - - CommandCreate commandCreate = new CommandCreate( scriptManager, body, commandsender, commandType ); - if ( commandCreate.isValid() ) - { mapManager.commandsWaitingMap.put(playerName, commandCreate); } - - break ; - - case add : - - CommandAdd commandAdd = new CommandAdd ( scriptManager, body, commandsender, commandType ); - if ( commandAdd.isValid() ) - { mapManager.commandsWaitingMap.put(playerName, commandAdd); } - - break ; - - case remove : - - CommandRemove commandRemove = new CommandRemove( scriptManager, commandsender, commandType ) ; - if ( commandRemove.isValid() ) - { mapManager.commandsWaitingMap.put(playerName, commandRemove); } - - break ; - - case view : - - CommandView commandView = new CommandView(scriptManager, commandsender, commandType) ; - if ( commandView.isValid() ) - { mapManager.commandsWaitingMap.put(playerName, commandView); } - - break ; - - case reload : - - FileManager fileManager = scriptManager.getFileManager() ; - fileManager.loadScriptFile() ; - fileManager.loadConfigFile() ; - commandsender.sendMessage(ChatColor.GREEN+ "["+plugin.getName()+"] "+fileManager.getScriptDataFile().getName()+" is now reloaded !"); - commandsender.sendMessage(ChatColor.GREEN+ "["+plugin.getName()+"] "+fileManager.getConfigFile().getName()+" is now reloaded !"); - - break ; - - } - } - - return true ; - - } - } - } - - return false; - } -} diff --git a/src/scriptblock/command/CommandRemove.java b/src/scriptblock/command/CommandRemove.java deleted file mode 100644 index 7b013d5..0000000 --- a/src/scriptblock/command/CommandRemove.java +++ /dev/null @@ -1,63 +0,0 @@ -package scriptblock.command; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import scriptblock.BlockCoords; -import scriptblock.SLAPI; -import scriptblock.command.CommandHandler.CommandType; -import scriptblock.managers.ScriptManager; - -@SuppressWarnings("deprecation") -public class CommandRemove extends BindScript{ - - public CommandRemove(ScriptManager scriptManager, Player commandsender, CommandType commandType) - { super(scriptManager, commandsender, commandType) ; } - - public boolean isValid() - { - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Click on a block to remove the script..."); - return true; - } - - @Override - public boolean onEvent(BlockCoords blockCoords) { - - if ( mapManager.blocksMap.containsKey( blockCoords.getFullCoords() )) - { - if ( !canAccessScript(blockCoords) ) - { commandSender.sendMessage(statusCancelled) ; return true ; } - - mapManager.blocksMap.remove( blockCoords.getFullCoords() ); - - //Saving blocksMap - fileManager.getScriptConfig().removeProperty(blockCoords.world+"."+blockCoords.getCoords()+"."); - fileManager.getScriptConfig().save(); - - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Text Successfully removed !"); - } - else { - commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] There is no Script bound to this !"); - commandSender.sendMessage(statusCancelled); - return true ; - } - - //Removing CoolDown and delay... - if (mapManager.cooldownMap.containsKey( blockCoords.getFullCoords() )){ - mapManager.cooldownMap.remove( blockCoords.getFullCoords() ); - - try { - SLAPI.save( mapManager.cooldownMap, fileManager.getCooldownDataFile().getPath() ); - log.info("cooldown removed from CoolDownData.dat!"); - } - catch (Exception e){ - log.info("[ERROR] while saving cooldownBlockMap to CoolDownData.dat ![ERROR]"); - log.info("at "+e.getMessage() ); - } - } - - if ( mapManager.delayList.contains( blockCoords.getFullCoords() )) mapManager.delayList.remove( blockCoords.getFullCoords() ); - - return true ; - } - -} diff --git a/src/scriptblock/command/CommandView.java b/src/scriptblock/command/CommandView.java deleted file mode 100644 index bf52ea9..0000000 --- a/src/scriptblock/command/CommandView.java +++ /dev/null @@ -1,42 +0,0 @@ -package scriptblock.command; - -import java.util.LinkedList; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import scriptblock.BlockCoords; -import scriptblock.command.CommandHandler.CommandType; -import scriptblock.managers.ScriptManager; - -public class CommandView extends BindScript { - - public CommandView(ScriptManager scriptManager, Player commandsender, CommandType commandType) - { super(scriptManager, commandsender, commandType); } - - public boolean isValid() - { - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Click on a block to view the Script..."); - return true ; - } - - @Override - public boolean onEvent(BlockCoords blockcoords) - { - if ( !canAccessScript(blockcoords) ) - { commandSender.sendMessage(statusCancelled) ; return true ; } - - LinkedList script = mapManager.blocksMap.get( blockcoords.getFullCoords() ); - if ( script != null ) - { - for (String command : script){ - commandSender.sendMessage("["+plugin.getName()+"] "+command); - } - return true ; - } - else { - commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] There is no Script bound to this block !"); - commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] View Status Cancelled !"); - return true ; - } - } -} diff --git a/src/scriptblock/command/CreateManager.java b/src/scriptblock/command/CreateManager.java deleted file mode 100644 index 5c8c2a5..0000000 --- a/src/scriptblock/command/CreateManager.java +++ /dev/null @@ -1,235 +0,0 @@ -package scriptblock.command; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import scriptblock.BlockCoords; -import scriptblock.SLAPI; -import scriptblock.command.CommandHandler.CommandType; -import scriptblock.managers.PermManager; -import scriptblock.managers.ScriptManager; -import scriptblock.options.Option; -import scriptblock.options.Option.Permissible; - -@SuppressWarnings("deprecation") -public abstract class CreateManager extends BindScript { - - protected LinkedList < String > commandList ; - - public CreateManager(ScriptManager scriptManager, Player player, CommandType commandType) - { - super(scriptManager, player, commandType); - - String consoleMsg = ("["+plugin.getName()+"] "+commandSender.getName()+" performed command \""+commandType.name()+"\"...") ; - log.info(consoleMsg) ; - } - - - protected abstract boolean isValid() ; - - protected boolean create(BlockCoords blockcoords) - { - String FullBlockCoords = blockcoords.getFullCoords() ; - - if ( !canAccessScript(blockcoords) ) return false ; - - mapManager.blocksMap.put(FullBlockCoords, commandList) ; - - //Saving blocksMap to yml . - - fileManager.getScriptConfig().setProperty(blockcoords.world+"."+blockcoords.getCoords()+".", commandList); - fileManager.getScriptConfig().save(); - - //Removing CoolDown and delay... - if ( mapManager.cooldownMap.containsKey(FullBlockCoords) ) - { - mapManager.cooldownMap.remove(FullBlockCoords); - try { - SLAPI.save( mapManager.cooldownMap, fileManager.getCooldownDataFile().getPath() ); - log.info("cooldown Saved to CoolDownData.dat!"); - } - catch (Exception e){ - log.info("[ERROR] while saving cooldownBlockMap to CoolDownData.dat ![ERROR]"); - log.info("at "+e.getMessage()); - } - } - - mapManager.delayList.remove(FullBlockCoords) ; - commandSender.sendMessage(ChatColor.GREEN + "["+plugin.getName()+"] Text Successfully bound !"); - return true ; - } - - - - - //TODO Check it ! There is some error inside !!! - public boolean optionCheck(LinkedList list) - { - boolean haveOption = false ; - - for (int i = 0 ; i < list.size() ; i++) - { - String scriptLine = list.get(i) ; - for ( Option option : mapManager.optionsList ) - { - - if ( scriptLine.startsWith( option.getSyntax() ) ) - { - haveOption = true ; - - String optionNode = new String ( "option" + PermManager.sep + option.getName() ) ; - String param = null ; - - if ( option instanceof Permissible ) - { - param = scriptLine.replaceFirst( option.getSyntax(),"" ) ; - - if ( param.contains(" /") ) - { param = param.substring( 0, param.indexOf(" /") ) ; } - } - - - String permMessage = ( ChatColor.RED+"["+plugin.getName()+"] You need permission to use: "+ - ChatColor.WHITE + option.getSyntax() ) ; - - String consoleMsg1 = ( "["+plugin.getName()+"] Option \""+option.getName()+"\" added" ) ; - - if ( param != null ) - { - String perm = new String( optionNode + PermManager.sep + param ); - if ( permManager.hasSBPerm( commandSender, perm , false) ) - { - if( option.showConsole() ) - { log.info(consoleMsg1+" with param \""+param+"\" !") ; } - - break ; - } - else { - commandSender.sendMessage( permMessage + param + ChatColor.RED + " !!" ); - list = null ; - return false ; - } - } - else { - - if ( permManager.hasSBPerm( commandSender, optionNode, false) ) - { - if ( option.showConsole() ) { log.info(consoleMsg1+"...") ; } - break ; //TODO test this - } - - else { - commandSender.sendMessage( permMessage + ChatColor.RED + " !!" ); - list = null ; - return false ; - } - } - } - } - - if (!haveOption) - { - commandSender.sendMessage(ChatColor.RED+"["+plugin.getName()+"] BAD SCRIPT !"); - list = null ; - return false ; - } - } - - return true ; - } - - - public boolean opCheck(LinkedList list) - { - if ( !commandSender.isOp() ){ - if ( ContainsOpCommands(list) ){ - - commandSender.sendMessage(ChatColor.RED + "["+plugin.getName()+"] Only Ops can Write Op's Commands !!!"); - list = null ; - return false; - } - } - return true ; - } - - /** Method to check if the commandList contain bypass Ops command or not ! */ - - protected boolean ContainsOpCommands(LinkedList commandList) - { - String[] opCommands = { "op","deop","save-all", - "save-off","save-on","stop", - "ban-ip","ban","pardon-ip", - "pardon","gamemode","kick", - "whitelist","?" } ; - - Iterator iter = commandList.iterator() ; - - while (iter.hasNext()) - { - String n = iter.next() ; - String m = new String() ; - Option bypassOp = scriptManager.getOptionManager().bypassOp ; - - if ( n.startsWith( bypassOp.getName() ) ) - { - for(int i = 0; i < opCommands.length ; i++) - { - m = n.replaceFirst( bypassOp.getSyntax(), ""); - m = m.toLowerCase(); - - if (m.startsWith(opCommands[i])) - { return true ; } - } - } - } - return false; - } - -/** Method to extract commands that are cercled by [] in a String and add it to a list.*/ - - protected LinkedList CommandScript(String text, LinkedList commandList) - { - String finalText = new String() ; - - if (text.contains("[") && text.contains("]")) - { - while (text.contains("[") && text.contains("]")) - { - int a = text.indexOf("[")+1 ; - int b = text.indexOf("]") ; - finalText = text.substring(a, b) ; //extract the command from the text - text = text.replace(finalText, "") ; //removing the extracted command from the text - text = text.replace("[]", "") ; //removing the [] that was used to isolated the extracted command - - commandList.add(finalText); //Register command to a list - } - } - else commandList.add(text); - - return commandList; - } - -/** Method to Convert Array in a String*/ - - protected String ArrayToString(String[] arg) - { - String text = new String() ; - StringBuilder stringBuilder = new StringBuilder() ; - Iterator iter = Arrays.asList(arg).iterator() ; - - while(iter.hasNext()) - { - String s = iter.next() ; - if ( s != null && !s.isEmpty() ) - stringBuilder.append(" ").append(s) ; - } - - text = stringBuilder.toString().replaceFirst(" ", "") ; - - return text ; - } - - -} diff --git a/src/scriptblock/listeners/PlayerInteractBlock.java b/src/scriptblock/listeners/PlayerInteractBlock.java deleted file mode 100644 index 6aadf3d..0000000 --- a/src/scriptblock/listeners/PlayerInteractBlock.java +++ /dev/null @@ -1,68 +0,0 @@ -package scriptblock.listeners; - -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerInteractEvent; - -import scriptblock.BlockCoords; -import scriptblock.ScriptBlock; -import scriptblock.command.BindScript; -import scriptblock.managers.ScriptManager; -import scriptblock.options.OptionHandler; - -public class PlayerInteractBlock extends ScriptManager implements Listener{ - - public PlayerInteractBlock(ScriptBlock scriptBlock) - { super(scriptBlock, "interact","sb"); } - - private Player player ; - private BlockCoords blockCoords ; - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) - { - player = event.getPlayer(); - Block block = event.getClickedBlock(); - - //Getting the Block Coordinates. - if ( event.hasBlock() ) - { - String world = player.getWorld().getName() ; - - int x = block.getX(); - int y = block.getY(); - int z = block.getZ(); - - blockCoords = new BlockCoords(world, x, y, z) ; - String playerName = player.getName() ; - - BindScript blockInteract = mapManager.commandsWaitingMap.get( playerName ) ; - - if ( blockInteract != null ) { - if ( blockInteract.onEvent( blockCoords ) ) - { - mapManager.commandsWaitingMap.remove(playerName) ; - log.info("["+plugin.getName()+"] "+playerName+" bound \""+blockInteract.getCommandType().name()+"\" "+getName()+" Script..." ) ; - log.info("["+plugin.getName()+"] at "+blockCoords.getFullCoords() ) ; - } - } - - else if ( mapManager.blocksMap.containsKey( blockCoords.getFullCoords() ) && permManager.hasSBPerm(player, "use", true) ) - { - if ( haveCoolDown(player, blockCoords) || isDelayed(player, blockCoords) ) return ; - - else { - - log.info("["+plugin.getName()+"] "+playerName+" triggered "+getName()+" ScriptBlock..." ) ; - log.info("["+plugin.getName()+"] at coords "+blockCoords.getFullCoords() ) ; - - OptionHandler read = new OptionHandler(this, player, blockCoords) ; - read.readScript(0) ; - } - } - } - } - -} diff --git a/src/scriptblock/listeners/PlayerWalkBlock.java b/src/scriptblock/listeners/PlayerWalkBlock.java deleted file mode 100644 index 59ac7df..0000000 --- a/src/scriptblock/listeners/PlayerWalkBlock.java +++ /dev/null @@ -1,96 +0,0 @@ -package scriptblock.listeners; - -import java.util.Hashtable; -import java.util.Map; - -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; - -import scriptblock.BlockCoords; -import scriptblock.ScriptBlock; -import scriptblock.command.BindScript; -import scriptblock.managers.ScriptManager; -import scriptblock.options.OptionHandler; - -public class PlayerWalkBlock extends ScriptManager implements Listener { - - private Map oldBlockCoords = new Hashtable() ; - - private Player player ; - private BlockCoords blockCoords ; - - public PlayerWalkBlock(ScriptBlock scriptBlock) - { super(scriptBlock, "walk", "sb" ); } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) - { - player = event.getPlayer(); - Block block = event.getClickedBlock(); - - if ( event.hasBlock() ) - { - String playerName = player.getName() ; - BindScript blockInteract = mapManager.commandsWaitingMap.get( playerName ) ; - - if ( blockInteract != null ) { - String world = player.getWorld().getName() ; - - int x = block.getX(); - int y = block.getY(); - int z = block.getZ(); - - blockCoords = new BlockCoords(world, x, y, z) ; - - if ( blockInteract.onEvent( blockCoords ) ) - { - mapManager.commandsWaitingMap.remove(playerName) ; - log.info("["+plugin.getName()+"] "+playerName+" bound \""+blockInteract.getCommandType().name()+"\" "+getName()+" Script..." ) ; - log.info("["+plugin.getName()+"] at "+blockCoords.getFullCoords() ) ; - } - } - } - } - - @EventHandler - public void onPlayerMove(PlayerMoveEvent event) - { - player = event.getPlayer() ; - - World world = player.getWorld() ; - int X = player.getLocation().getBlockX() ; - int Y = player.getLocation().getBlockY() - 1; - int Z = player.getLocation().getBlockZ() ; - - - - if (world.getBlockAt(X, Y, Z).getTypeId() != 0) - { - String playerName = player.getName() ; - String worldName = world.getName() ; - - blockCoords = new BlockCoords(worldName, X, Y, Z); - - if (!oldBlockCoords.containsKey(playerName) || !oldBlockCoords.get(playerName).equals( blockCoords.getFullCoords() )) - { - oldBlockCoords.put(playerName, blockCoords.getFullCoords()); - if ( mapManager.blocksMap.containsKey( blockCoords.getFullCoords() ) && permManager.hasSBPerm(player, "use", false) ) - { - if ( haveCoolDown(player, blockCoords) || isDelayed(player, blockCoords) ) return ; - - log.info("["+plugin.getName()+"] "+playerName+" triggered "+getName()+" ScriptBlock..." ) ; - log.info("["+plugin.getName()+"] at coords "+blockCoords.getFullCoords() ) ; - - OptionHandler read = new OptionHandler(this, player, blockCoords) ; - read.readScript(0) ; - } - } - } - } - -} diff --git a/src/scriptblock/managers/ConfigParameters.java b/src/scriptblock/managers/ConfigParameters.java deleted file mode 100644 index 78163d9..0000000 --- a/src/scriptblock/managers/ConfigParameters.java +++ /dev/null @@ -1,49 +0,0 @@ -package scriptblock.managers; - -import org.bukkit.util.config.Configuration; - -import scriptblock.options.Option; - -@SuppressWarnings("deprecation") -public class ConfigParameters { - - private final String showConsole = "ShowConsole" ; - private final String sep = "." ; - - private ScriptManager scriptManager; - private MapManager mapManager; - - private FileManager fileManager; - private Configuration config; - - - public ConfigParameters(ScriptManager scriptManager) - { - this.scriptManager = scriptManager ; - this.mapManager = scriptManager.mapManager ; - } - - public void init(FileManager fileManager) - { - this.fileManager = fileManager ; - this.config = fileManager.getConfig() ; - } - - public void getPropFromConfig() - { - for (Option option : mapManager.optionsList ) - { - boolean debugMode = config.getBoolean(showConsole+sep+option.getName(), false) ; - option.setDebugMode(debugMode) ; - } - } - - public void setDefaultsProps() - { - for (Option option : mapManager.optionsList ) - { - config.setProperty(showConsole+sep+option.getName(), false) ; - } - } - -} diff --git a/src/scriptblock/managers/FileManager.java b/src/scriptblock/managers/FileManager.java deleted file mode 100644 index 57e74dd..0000000 --- a/src/scriptblock/managers/FileManager.java +++ /dev/null @@ -1,237 +0,0 @@ -package scriptblock.managers; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Logger; - -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.config.Configuration; - -import scriptblock.SLAPI; -import scriptblock.ScriptBlock; - -@SuppressWarnings("deprecation") -public class FileManager { - - private JavaPlugin plugin ; - - private File scriptBlockFolder ; - private File scriptDataFolder ; - - private Logger log = ScriptBlock.log ; - - private MapManager mapManager; - private ConfigParameters configParam; - private File configFile ; - private File scriptDataFile; - private File cooldownDataFile ; - private Configuration config ; - private Configuration scriptConfig ; - - /* TODO Remove disabled Time on cooldowns ! and recode it. - * - * - * - * - * - */ - - - public FileManager(JavaPlugin plugin, MapManager mapManager ,ConfigParameters configParam,String name) - { - this.plugin = plugin ; - -// if ( ScriptBlockFolder == null && scriptDataFolder == null) - { - scriptBlockFolder = plugin.getDataFolder() ; - scriptDataFolder = new File( scriptBlockFolder+"/BlocksData" ) ; - scriptDataFolder.mkdirs() ; - } - - configFile = new File( scriptBlockFolder+File.separator+name+"_Config.yml") ; - scriptDataFile = new File ( scriptDataFolder.getPath()+File.separator+name+"_Scripts.yml" ) ; - cooldownDataFile = new File ( scriptDataFolder.getPath()+File.separator+name+"_Cooldowns.dat" ); - config = new Configuration(configFile) ; - scriptConfig = new Configuration(scriptDataFile) ; - - this.mapManager = mapManager ; - this.configParam = configParam ; - - } - - public void init() - { - loadConfigFile() ; - loadScriptFile() ; - loadCooldownFile() ; - } - - public void loadScriptFile() - { - // Checking if "scriptData".yml Save File content is null, and loading it if not. - - if ( scriptDataFile.exists() ){ - if ( scriptDataFile.length() > 0 ){ - - //Loading Existent BlockMap. - - scriptConfig.load(); - - for (String world : scriptConfig.getKeys()) { - for (String blockCoords : scriptConfig.getKeys(world+".") ) - { - List macroList = scriptConfig.getList(world+"."+blockCoords+".") ; - LinkedList commandList = new LinkedList() ; - - for( int i = 0; i < macroList.size() ; i++ ) - { commandList.add( String.valueOf( macroList.get(i) ) ); } - - mapManager.blocksMap.put(world+","+blockCoords, commandList ) ; - } - } - - log.info("["+plugin.getName()+"] "+scriptDataFile.getName()+" loaded !"); - } - else { log.info("["+plugin.getName()+"] "+scriptDataFile.getName()+" is empty, loading aborded !"); } - } - else { - - try { scriptDataFile.createNewFile() ; } - catch (IOException e) { e.printStackTrace(); } - - log.info("["+plugin.getName()+"] "+scriptDataFile.getName()+" created !") ; - } - - } - - @SuppressWarnings("unchecked") - public void loadCooldownFile() - { - // Checking if CoolDownData.dat Save File content is null, and loading it if not. - - if ( cooldownDataFile.exists() ){ - if ( cooldownDataFile.length() > 0 ) { - - //loading cooldownBlockMap - try { - - mapManager.cooldownMap = ( HashMap ) SLAPI.load ( cooldownDataFile.getPath() ); - log.info("["+plugin.getName()+"] "+cooldownDataFile.getName()+" File Loaded !!!"); - - } catch (Exception e) { - - log.info("["+plugin.getName()+"] [ERROR] while loading "+cooldownDataFile.getName()+" File !"); - log.info("["+plugin.getName()+"] at "+e.getMessage()); - } - - //Cooldowns Update. - long[] disabledTime = new long[1] ; - - if (mapManager.cooldownMap != null){ - - disabledTime = mapManager.cooldownMap.get("disabledTime"); - - for (String key : mapManager.cooldownMap.keySet()){ - if ( !key.equals("disabledTime") ){ - - long[] cooldownParams = mapManager.cooldownMap.get(key); - cooldownParams[2] = cooldownParams[2] + (System.currentTimeMillis() - disabledTime[0] ); - mapManager.cooldownMap.put(key, cooldownParams); - } - } - } - } - - else { log.info("["+plugin.getName()+"] "+cooldownDataFile.getName()+" is empty, loading aborded !"); } - } - else { - - try { cooldownDataFile.createNewFile() ; } - catch (IOException e) { e.printStackTrace(); } - - log.info("["+plugin.getName()+"] "+cooldownDataFile.getName()+" created !") ; - } - } - - public void loadConfigFile() - { - configParam.init(this) ; - - if ( !configFile.exists() ) - { - try { configFile.createNewFile() ; } - catch (IOException e) { e.printStackTrace(); } - - configParam.setDefaultsProps() ; - config.save() ; - log.info("["+plugin.getName()+"] "+configFile.getName()+" created !") ; - } - else { - config.load() ; - configParam.getPropFromConfig() ; - - log.info("["+plugin.getName()+"] "+configFile.getName()+" loaded !") ; - } - } - - public void saveDisabledTime(long time) - { - String DisabledTimeKey = "disabledTime"; - long[] disabledTime = new long[1] ; - - disabledTime[0] = time ; - mapManager.cooldownMap.put(DisabledTimeKey, disabledTime); - - try { SLAPI.save( mapManager.cooldownMap , cooldownDataFile.getPath() ); } - catch (Exception e) { - log.info("["+plugin.getName()+"] [ERROR] while saving the DisabledTime to "+cooldownDataFile.getName()+" !"); - log.info("["+plugin.getName()+"] at "+ e.getMessage()); - } - log.info("["+plugin.getName()+"] Disabled Time Saved to "+cooldownDataFile.getName()+" !!!"); - } - - - /** This method allow you to Merge yml Save to the desired Map. */ - - public static void YMLtoMap(Configuration config, HashMap > BlocksMap) - { - config.load(); - - for (String world : config.getKeys()){ - for (String blockCoords : config.getKeys(world+".") ){ - - List macroList = config.getList(world+"."+blockCoords+".") ; - LinkedList commandList = new LinkedList() ; - - for( int i = 0; i < macroList.size() ; i++ ) - { commandList.add( String.valueOf( macroList.get(i) ) ); } - - BlocksMap.put(world+","+blockCoords, commandList ) ; - } - } - } - - - - public MapManager getMapManager() - { return mapManager; } - - public Configuration getScriptConfig() - { return scriptConfig; } - - public File getScriptDataFile() - { return scriptDataFile; } - - public File getCooldownDataFile() - { return cooldownDataFile; } - - public Configuration getConfig() - { return config; } - - public File getConfigFile() - { return configFile; } - -} diff --git a/src/scriptblock/managers/MapManager.java b/src/scriptblock/managers/MapManager.java deleted file mode 100644 index 1b98f70..0000000 --- a/src/scriptblock/managers/MapManager.java +++ /dev/null @@ -1,29 +0,0 @@ -package scriptblock.managers; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; - -import scriptblock.command.BindScript; -import scriptblock.options.Option; - - -public class MapManager { - - public HashMap < String, BindScript > commandsWaitingMap ; - public HashMap < String, LinkedList > blocksMap ; - public HashMap < String, long[] > cooldownMap ; - public LinkedList< Option > optionsList ; - public List delayList ; - - public MapManager() - { - this.commandsWaitingMap = new HashMap() ; - this.blocksMap = new HashMap < String , LinkedList < String>> () ; - this.cooldownMap = new HashMap < String, long[]>() ; - this.optionsList = new LinkedList < Option >() ; - this.delayList = new ArrayList< String >() ; - } - -} diff --git a/src/scriptblock/managers/PermManager.java b/src/scriptblock/managers/PermManager.java deleted file mode 100644 index 04b1781..0000000 --- a/src/scriptblock/managers/PermManager.java +++ /dev/null @@ -1,149 +0,0 @@ -package scriptblock.managers; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import scriptblock.ScriptBlock; - -import net.milkbowl.vault.permission.Permission; - -public class PermManager { - - public final static String sep = "." ; - public final String noPermMsg ; - - private Permission perm; - - private final String scriptManagerName; - private final String pluginName ; - private final String smanagerNode ; - - - - public PermManager(Permission perm, String scriptManagerName , JavaPlugin plugin) - { - this.perm = perm ; - this.scriptManagerName = scriptManagerName ; - this.pluginName = plugin.getName().toLowerCase(); - this.smanagerNode = pluginName+sep+scriptManagerName ; - this.noPermMsg = new String(ChatColor.RED +"["+plugin.getName()+"]"+" You don't have permission !") ; - } -/* - public boolean hasSBPerm(Player player, String node, boolean message) - { - if ( perm.has(player, name+sep+node) || perm.has(player, name+sep+"*") || player.isOp() ) return true ; - else if (message) return noPerm(player) ; - else return false ; - } -*/ - public boolean playerInGroup(Player player, String group) - { return perm.playerInGroup(player, group) ; } - - public boolean playerAddGroup(Player player, String group) - { return perm.playerAddGroup(player, group) ; } - - public boolean playerRemoveGroup(Player player , String group) - { return perm.playerRemoveGroup(player, group) ; } - - public boolean playerAdd(Player player, String permission) - { return perm.playerAdd(player, permission) ; } - - public boolean playerAdd(String world, Player player, String permission) - { return perm.playerAdd(world, player.getName() , permission) ; } - - public boolean playerRemove(Player player, String permission) - { return perm.playerRemove(player, permission) ; } - - public boolean playerRemove(String world, Player player, String permission) - { return perm.playerRemove(world, player.getName(), permission) ; } - - public boolean has(Player player, String permission) - { return perm.has(player, permission) ; } - - private boolean hasSBmainPerm(Player player) - { return perm.has(player, pluginName + sep + "*") ; } - - private boolean hasScriptManagerPerm(Player player) - { - if (perm.has(player, smanagerNode + sep + "*") || hasSBmainPerm(player) || player.isOp() ) return true ; - else return false ; - } - - public boolean hasSBPerm(Player player, String node, String type, boolean showMsg ) - { - if ( perm.has(player, smanagerNode + sep + node + sep + type ) - || perm.has( player, smanagerNode + sep + node + sep + "*" ) - || hasScriptManagerPerm(player) ) - { return true ; } - - else if (showMsg) { return noPerm(player) ; } - else return false ; - } - - public boolean hasSBPerm(Player player, String[] typesArray, boolean showMsg) - { - if ( hasScriptManagerPerm(player) ) return true ; - - StringBuilder permBuilder = new StringBuilder().append(smanagerNode) ; - - for (int i = 0; i < typesArray.length ; i++ ) - { - String type = typesArray[i] ; - permBuilder.append(sep+type) ; - - if (i == (typesArray.length-1) && perm.has( player, permBuilder.toString() ) ) - { return true ; } - - else if ( perm.has(player, permBuilder.toString()+sep+"*" ) ) return true ; - - } - - if (showMsg) { return noPerm(player) ; } - else return false ; - } - - - public boolean hasSBPerm(Player player, String permNode, boolean showMsg) - { - if ( perm.has( player, smanagerNode + sep + permNode ) ) return true ; - - String lastnode ; - while ( permNode.contains(sep) ) - { - lastnode = permNode.substring( permNode.lastIndexOf(sep), permNode.length() ) ; - permNode = permNode.replaceAll(lastnode, "") ; - - if ( perm.has( player, smanagerNode + sep + permNode + "*") ) return true ; - } - - if ( hasScriptManagerPerm(player) ) return true ; - else if (showMsg) { return noPerm(player) ; } - else return false ; - } - -/* - public boolean hasSBPerm(Player player, String[] typesArray, boolean showMsg) - { - StringBuilder permBuilder = new StringBuilder().append(name) ; - for (String type : typesArray) - { permBuilder.append(sep+type) ; } - - if (permHas(player,)) - - if (showMsg) { return noPerm(player) ; } - else return false ; - - } -*/ - - private boolean noPerm(Player player) - { - player.sendMessage(noPermMsg) ; - return false ; - } - public String getSmanagerNode() { - return smanagerNode; - } - -} diff --git a/src/scriptblock/managers/ScriptManager.java b/src/scriptblock/managers/ScriptManager.java deleted file mode 100644 index 23521b8..0000000 --- a/src/scriptblock/managers/ScriptManager.java +++ /dev/null @@ -1,105 +0,0 @@ -package scriptblock.managers; - - -import java.util.logging.Logger; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; - -import scriptblock.BlockCoords; -import scriptblock.ScriptBlock; -import scriptblock.command.CommandHandler; -import scriptblock.options.OptionManager; - -public abstract class ScriptManager implements Listener { - - protected ScriptBlock scriptBlock = ScriptBlock.getInstance() ; - protected Logger log = ScriptBlock.log ; - - protected JavaPlugin plugin; - - private String name ; - - protected ConfigParameters configParam ; - protected MapManager mapManager ; - protected FileManager fileManager ; - protected PermManager permManager ; - protected OptionManager optionManager; - - private CommandHandler commandHandler ; - - public ScriptManager(JavaPlugin plugin, String eventName,String cmdName) - { - this.name = eventName ; - this.plugin = plugin ; - this.permManager = new PermManager(scriptBlock.getPerm(), this.name , plugin ) ; - this.mapManager = new MapManager() ; - this.optionManager = new OptionManager(this) ; - this.configParam = new ConfigParameters(this) ; - this.fileManager = new FileManager(plugin, mapManager, configParam ,eventName) ; - this.commandHandler = new CommandHandler(this, cmdName) ; - init() ; - } - - protected void init() - { - optionManager.registerDefaultOptions() ; - fileManager.init() ; - } - - protected boolean haveCoolDown(Player player, BlockCoords blockCoords) - { - long[] cooldownParams = mapManager.cooldownMap.get( blockCoords.getFullCoords() ); - - if ( cooldownParams != null ) { - if ( cooldownParams[2] > System.currentTimeMillis() ) { - - int timeRemain = (int) ((cooldownParams[2] - System.currentTimeMillis()) /1000) ; - - short H = (short) (timeRemain / 3600) ; - byte mins = (byte) ( (timeRemain % 3600) / 60); - byte secs = (byte) ( (timeRemain % 3600) % 60) ; - - player.sendMessage(ChatColor.RED+"["+plugin.getName()+"] You must wait "+H+" H "+mins+" mins "+secs+" secs..."); - player.sendMessage(ChatColor.RED+"["+plugin.getName()+"] to activate this again !"); - - return true; - } - } - return false ; - } - - protected boolean isDelayed(Player player,BlockCoords blockCoords) - { - if ( mapManager.delayList.contains( blockCoords.getFullCoords() ) ) { - - player.sendMessage(ChatColor.RED+"["+plugin.getName()+"] You must wait to activate this again..."); - return true ; - } - else { return false ; } - } - - public String getName() - { return name; } - - public FileManager getFileManager() - { return fileManager; } - - public MapManager getMapManager() - { return mapManager; } - - public PermManager getPermManager() - { return permManager; } - - public JavaPlugin getPlugin() - { return plugin; } - - public OptionManager getOptionManager() - { return optionManager; } - - public ConfigParameters getConfigParam() - { return configParam; } -} - diff --git a/src/scriptblock/options/Option.java b/src/scriptblock/options/Option.java deleted file mode 100644 index cb582df..0000000 --- a/src/scriptblock/options/Option.java +++ /dev/null @@ -1,32 +0,0 @@ -package scriptblock.options; - -public abstract class Option { - - private final String name ; - private final String syntax ; - private boolean inDebugMode ; - - public Option(String name, String syntax) - { - this.name = name ; - this.syntax = syntax ; - } - - public abstract boolean onOptionCall(OptionHandler optionHandler) ; - - public String getName() - { return name; } - - public String getSyntax() - { return syntax; } - - public boolean showConsole() - { return inDebugMode ; } - - public void setDebugMode(boolean debugMode) - { this.inDebugMode = debugMode ; } - - public abstract interface Permissible {} -} - - diff --git a/src/scriptblock/options/OptionHandler.java b/src/scriptblock/options/OptionHandler.java deleted file mode 100644 index 635cb51..0000000 --- a/src/scriptblock/options/OptionHandler.java +++ /dev/null @@ -1,153 +0,0 @@ -package scriptblock.options; - -import java.util.LinkedList; -import java.util.logging.Logger; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import scriptblock.BlockCoords; -import scriptblock.ScriptBlock; -import scriptblock.command.CommandCreate; -import scriptblock.managers.MapManager; -import scriptblock.managers.ScriptManager; - -public class OptionHandler { - - protected ScriptBlock scriptBlock = ScriptBlock.getInstance() ; - protected Logger log = ScriptBlock.log ; - - private ScriptManager scriptManager; - private JavaPlugin plugin; - - private LinkedList script; - - private BlockCoords blockCoords ; - private String scriptLine; - private Player player ; - private int scriptLineIndex; - - private MapManager mapManager; - - - public OptionHandler(ScriptManager scriptManager, Player player, BlockCoords blockCoords) - { - this.scriptManager = scriptManager ; - this.plugin = scriptManager.getPlugin() ; - this.mapManager = scriptManager.getMapManager() ; - this.blockCoords = blockCoords ; - this.script = mapManager.blocksMap.get( blockCoords.getFullCoords() ) ; - this.player = player ; - } - - public enum TextOpt { - - PLAYER(""), - ITEM_NAME(""), - ITEM_ID(""); - - public final String value ; - - private TextOpt(String value) - {this.value = value ; } - } - - - public void readScript(int index) - { - scriptLineIndex = index ; - - for (; scriptLineIndex < script.size() ; scriptLineIndex++) - { - boolean haveOption = false ; - scriptLine = script.get(scriptLineIndex) ; - - if (scriptLineIndex == 0 && script.get(scriptLineIndex).startsWith( CommandCreate.authorNode ) ) continue ; - - for ( TextOpt textOpt : TextOpt.values() ) - { - if ( scriptLine.contains(textOpt.value) ) - { - switch(textOpt) - { - case PLAYER : - - scriptLine = scriptLine.replaceAll(TextOpt.PLAYER.value, player.getName() ) ; - break ; - - case ITEM_NAME : - { - ItemStack itemStack = player.getItemInHand() ; - if ( itemStack != null ) - { - Material material = itemStack.getType() ; - scriptLine = scriptLine.replaceAll(TextOpt.ITEM_NAME.value, material.name() ) ; - } - else {scriptLine = scriptLine.replaceAll(TextOpt.ITEM_NAME.value, "NoName" ) ; } - - break ; - } - - case ITEM_ID : - { - ItemStack itemStack = player.getItemInHand() ; - if ( itemStack != null ) - { - Material material = itemStack.getType() ; - scriptLine = scriptLine.replaceAll( TextOpt.ITEM_ID.value, String.valueOf( material.getId() ) ) ; - } - else { scriptLine = scriptLine.replaceAll( TextOpt.ITEM_ID.value, "0" ) ; } - - break ; - } - - - } - } - } - - for (Option option : mapManager.optionsList ) - { - if (scriptLine.startsWith( option.getSyntax() ) ) - { - if ( !option.onOptionCall( this ) ) return ; - - haveOption = true ; - break ; - } - } - - if (!haveOption) { - player.sendMessage(ChatColor.RED+"["+plugin.getName()+"] BAD SCRIPT !"); - return ; - } - - } - } - - - public LinkedList getScript() - { return script; } - - - public BlockCoords getBlockCoords() - { return blockCoords; } - - - public String getScriptLine() - { return scriptLine; } - - - public Player getPlayer() - { return player; } - - - public ScriptManager getScriptManager() - { return scriptManager; } - - - public int getScriptLineIndex() - { return scriptLineIndex; } -} diff --git a/src/scriptblock/options/OptionManager.java b/src/scriptblock/options/OptionManager.java deleted file mode 100644 index c36fdd5..0000000 --- a/src/scriptblock/options/OptionManager.java +++ /dev/null @@ -1,106 +0,0 @@ -package scriptblock.options; - -import java.util.LinkedList; - -import scriptblock.managers.ScriptManager; -import scriptblock.options.miscellaneous.Amount; -import scriptblock.options.miscellaneous.Cost; -import scriptblock.options.miscellaneous.ItemCost; -import scriptblock.options.permissions.BypassGroup; -import scriptblock.options.permissions.BypassOp; -import scriptblock.options.permissions.BypassPerm; -import scriptblock.options.time.Cooldown; -import scriptblock.options.time.Delay; - -import static scriptblock.options.permissions.PermOptions.*; -import static scriptblock.options.chat.ChatOptions.*; - - -public class OptionManager { - - private ScriptManager scriptManager; - private LinkedList