diff --git a/src/main/java/org/mcsg/survivalgames/CommandHandler.java b/src/main/java/org/mcsg/survivalgames/CommandHandler.java index 432190f..8307175 100644 --- a/src/main/java/org/mcsg/survivalgames/CommandHandler.java +++ b/src/main/java/org/mcsg/survivalgames/CommandHandler.java @@ -12,26 +12,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.mcsg.survivalgames.MessageManager.PrefixType; -import org.mcsg.survivalgames.commands.AddWall; -import org.mcsg.survivalgames.commands.CreateArena; -import org.mcsg.survivalgames.commands.DelArena; -import org.mcsg.survivalgames.commands.Disable; -import org.mcsg.survivalgames.commands.Enable; -import org.mcsg.survivalgames.commands.Flag; -import org.mcsg.survivalgames.commands.ForceStart; -import org.mcsg.survivalgames.commands.Join; -import org.mcsg.survivalgames.commands.Leave; -import org.mcsg.survivalgames.commands.LeaveQueue; -import org.mcsg.survivalgames.commands.ListArenas; -import org.mcsg.survivalgames.commands.ListPlayers; -import org.mcsg.survivalgames.commands.ResetSpawns; -import org.mcsg.survivalgames.commands.SetLobbySpawn; -import org.mcsg.survivalgames.commands.SetLobbyWall; -import org.mcsg.survivalgames.commands.SetSpawn; -import org.mcsg.survivalgames.commands.Spectate; -import org.mcsg.survivalgames.commands.SubCommand; -import org.mcsg.survivalgames.commands.Teleport; -import org.mcsg.survivalgames.commands.Vote; +import org.mcsg.survivalgames.commands.*; @@ -69,6 +50,13 @@ private void loadCommands() { commands.put("leavequeue", new LeaveQueue()); commands.put("list", new ListPlayers()); commands.put("tp", new Teleport()); + commands.put("delwall", new DelWall()); + if(SurvivalGames.dbcon2){ + commands.put("addsign", new AddSign()); + commands.put("addhead", new AddHead()); + commands.put("delsign", new DelSign()); + commands.put("delhead", new DelHead()); + } // commands.put("sponsor", new Sponsor()); } @@ -94,6 +82,15 @@ private void loadHelpInfo() { helpinfo.put("lq", 1); helpinfo.put("leavequeue", 1); helpinfo.put("list", 1); + helpinfo.put("tp", 2); + helpinfo.put("delwall", 3); + if(SurvivalGames.dbcon2){ + helpinfo.put("addsign", 3); + helpinfo.put("addhead", 3); + helpinfo.put("delsign", 3); + helpinfo.put("delhead", 3); + } + //helpinfo.put("sponsor", 1); } diff --git a/src/main/java/org/mcsg/survivalgames/LobbyManager.java b/src/main/java/org/mcsg/survivalgames/LobbyManager.java index 0d2170c..8ce07da 100644 --- a/src/main/java/org/mcsg/survivalgames/LobbyManager.java +++ b/src/main/java/org/mcsg/survivalgames/LobbyManager.java @@ -45,6 +45,9 @@ public void loadSign(int a) { try{ SurvivalGames.debug("sg-system.lobby.signs." + a + ".world"); World w = Bukkit.getWorld(s.getString("sg-system.lobby.signs." + a + ".world")); + if(!s.getBoolean("sg-system.lobby.signs." + a+ ".enabled", true)){ + return; + } int x1 = s.getInt("sg-system.lobby.signs." + a + ".x1"); int y1 = s.getInt("sg-system.lobby.signs." + a + ".y1"); int z1 = s.getInt("sg-system.lobby.signs." + a + ".z1"); diff --git a/src/main/java/org/mcsg/survivalgames/SettingsManager.java b/src/main/java/org/mcsg/survivalgames/SettingsManager.java index 7889148..7e3f468 100644 --- a/src/main/java/org/mcsg/survivalgames/SettingsManager.java +++ b/src/main/java/org/mcsg/survivalgames/SettingsManager.java @@ -7,6 +7,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; +import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -369,4 +370,29 @@ public void loadFile(String file){ } } + + public boolean modifyList(String type, Location loc, int pos) { + FileConfiguration cfg = SettingsManager.getInstance().getSystemConfig(); + List objs = cfg.getStringList(type); + String conStr = loc.getWorld().getName() + ";" + loc.getX() + ";" + loc.getY() + ";" + loc.getZ(); + for (String str : objs) { + if (str.startsWith(conStr)) { + if (pos == 0) { + objs.remove(str); + cfg.set(type, objs); + getInstance().saveConfig(); + return true; + } else { + return false; + } + } + } + if (pos == 0) { + return false; + } + objs.add(conStr + ";" + pos); + cfg.set(type, objs); + getInstance().saveConfig(); + return true; + } } \ No newline at end of file diff --git a/src/main/java/org/mcsg/survivalgames/SurvivalGames.java b/src/main/java/org/mcsg/survivalgames/SurvivalGames.java index 16c9a0f..6d100fc 100644 --- a/src/main/java/org/mcsg/survivalgames/SurvivalGames.java +++ b/src/main/java/org/mcsg/survivalgames/SurvivalGames.java @@ -23,146 +23,270 @@ import org.mcsg.survivalgames.util.DatabaseManager; import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.block.Skull; +import org.bukkit.scheduler.BukkitScheduler; public class SurvivalGames extends JavaPlugin { - public static Logger logger; - private static File datafolder; - private static boolean disabling = false; - public static boolean dbcon = false; - public static boolean config_todate = false; - public static int config_version = 3; - - public static List < String > auth = Arrays.asList(new String[] { - "Double0negative", "iMalo", "Medic0987", "alex_markey", "skitscape", "AntVenom", "YoshiGenius", "pimpinpsp", "WinryR", "Jazed2011", - "KiwiPantz", "blackracoon", "CuppingCakes", "4rr0ws", "Fawdz", "Timothy13", "rich91", "ModernPrestige", "Snowpool", "egoshk", - "nickm140", "chaseoes", "Oceangrass", "GrailMore", "iAngelic", "Lexonia", "ChaskyT", "Anon232" - }); - - SurvivalGames p = this; - public void onDisable() { - disabling = false; - PluginDescriptionFile pdfFile = p.getDescription(); - SettingsManager.getInstance().saveSpawns(); - SettingsManager.getInstance().saveSystemConfig(); - for (Game g: GameManager.getInstance().getGames()) { - try{ - g.disable(); - }catch(Exception e){ - //will throw useless "tried to register task blah blah error." Use the method below to reset the arena without a task. - } - QueueManager.getInstance().rollback(g.getID(), true); - } - - logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has now been disabled and reset"); - } - - public void onEnable() { - logger = p.getLogger(); - - //ensure that all worlds are loaded. Fixes some issues with Multiverse loading after this plugin had started - getServer().getScheduler().scheduleSyncDelayedTask(this, new Startup(), 10); - try { - new Metrics(this).start(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - } - - class Startup implements Runnable { - public void run() { - datafolder = p.getDataFolder(); - - PluginManager pm = getServer().getPluginManager(); - setCommands(); - - SettingsManager.getInstance().setup(p); - MessageManager.getInstance().setup(); - GameManager.getInstance().setup(p); - - try { // try loading everything that uses SQL. - FileConfiguration c = SettingsManager.getInstance().getConfig(); - if (c.getBoolean("stats.enabled")) DatabaseManager.getInstance().setup(p); - QueueManager.getInstance().setup(); - StatsManager.getInstance().setup(p, c.getBoolean("stats.enabled")); - dbcon = true; - } catch (Exception e) { - dbcon = false; - e.printStackTrace(); - logger.severe("!!!Failed to connect to the database. Please check the settings and try again!!!"); - return; - } finally { - LobbyManager.getInstance().setup(p); - } - - ChestRatioStorage.getInstance().setup(); - HookManager.getInstance().setup(); - pm.registerEvents(new PlaceEvent(), p); - pm.registerEvents(new BreakEvent(), p); - pm.registerEvents(new DeathEvent(), p); - pm.registerEvents(new MoveEvent(), p); - pm.registerEvents(new CommandCatch(), p); - pm.registerEvents(new SignClickEvent(), p); - pm.registerEvents(new ChestReplaceEvent(), p); - pm.registerEvents(new LogoutEvent(), p); - pm.registerEvents(new JoinEvent(p), p); - pm.registerEvents(new TeleportEvent(), p); - pm.registerEvents(LoggingManager.getInstance(), p); - pm.registerEvents(new SpectatorEvents(), p); - pm.registerEvents(new BandageUse(), p); - pm.registerEvents(new KitEvents(), p); - - for (Player p: Bukkit.getOnlinePlayers()) { - if (GameManager.getInstance().getBlockGameId(p.getLocation()) != -1) { - p.teleport(SettingsManager.getInstance().getLobbySpawn()); - } - } - - // new Webserver().start(); - } - } - - public void setCommands() { - getCommand("survivalgames").setExecutor(new CommandHandler(p)); - } - - - - - public static File getPluginDataFolder() { - return datafolder; - } - - public static boolean isDisabling() { - return disabling; - } - - public WorldEditPlugin getWorldEdit() { - Plugin worldEdit = getServer().getPluginManager().getPlugin("WorldEdit"); - if (worldEdit instanceof WorldEditPlugin) { - return (WorldEditPlugin) worldEdit; - } else { - return null; - } - } - - public static void $(String msg){ - logger.log(Level.INFO, msg); - } - - public static void $(Level l, String msg){ - logger.log(l, msg); - } - - public static void debug(String msg){ - if(SettingsManager.getInstance().getConfig().getBoolean("debug", false)) - $(msg); - } - - public static void debug(int a) { - if(SettingsManager.getInstance().getConfig().getBoolean("debug", false)) - debug(a+""); - } + + public static Logger logger; + private static File datafolder; + private static boolean disabling = false; + public static boolean dbcon = false; + public static boolean dbcon2 = false; + public static boolean config_todate = false; + public static int config_version = 3; + private static ResultSet rs; + public static List< String> auth = Arrays.asList(new String[]{ + "Double0negative", "iMalo", "Medic0987", "alex_markey", "skitscape", "AntVenom", "YoshiGenius", "pimpinpsp", "WinryR", "Jazed2011", + "KiwiPantz", "blackracoon", "CuppingCakes", "4rr0ws", "Fawdz", "Timothy13", "rich91", "ModernPrestige", "Snowpool", "egoshk", + "nickm140", "chaseoes", "Oceangrass", "GrailMore", "iAngelic", "Lexonia", "ChaskyT", "Anon232", "DragonCz" + }); + SurvivalGames p = this; + + @Override + public void onDisable() { + disabling = false; + PluginDescriptionFile pdfFile = p.getDescription(); + SettingsManager.getInstance().saveSpawns(); + SettingsManager.getInstance().saveSystemConfig(); + for (Game g : GameManager.getInstance().getGames()) { + try { + g.disable(); + } catch (Exception e) { + //will throw useless "tried to register task blah blah error." Use the method below to reset the arena without a task. + } + QueueManager.getInstance().rollback(g.getID(), true); + } + + logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has now been disabled and reset"); + } + + @Override + public void onEnable() { + logger = p.getLogger(); + + //ensure that all worlds are loaded. Fixes some issues with Multiverse loading after this plugin had started + getServer().getScheduler().scheduleSyncDelayedTask(this, new Startup(), 10); + try { + new Metrics(this).start(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + + class Startup implements Runnable { + + public void run() { + datafolder = p.getDataFolder(); + + PluginManager pm = getServer().getPluginManager(); + setCommands(); + + SettingsManager.getInstance().setup(p); + MessageManager.getInstance().setup(); + GameManager.getInstance().setup(p); + + try { // try loading everything that uses SQL. + FileConfiguration c = SettingsManager.getInstance().getConfig(); + if (c.getBoolean("stats.enabled")) { + DatabaseManager.getInstance().setup(p); + dbcon2 = true; + } + QueueManager.getInstance().setup(); + StatsManager.getInstance().setup(p, c.getBoolean("stats.enabled")); + if (dbcon2) { + getServer().getScheduler().runTaskTimerAsynchronously(p, new HofUpdater(), 10, 100); + } + dbcon = true; + } catch (Exception e) { + dbcon = false; + e.printStackTrace(); + logger.severe("!!!Failed to connect to the database. Please check the settings and try again!!!"); + return; + } finally { + LobbyManager.getInstance().setup(p); + } + + ChestRatioStorage.getInstance().setup(); + HookManager.getInstance().setup(); + pm.registerEvents(new PlaceEvent(), p); + pm.registerEvents(new BreakEvent(), p); + pm.registerEvents(new DeathEvent(), p); + pm.registerEvents(new MoveEvent(), p); + pm.registerEvents(new CommandCatch(), p); + pm.registerEvents(new SignClickEvent(), p); + pm.registerEvents(new ChestReplaceEvent(), p); + pm.registerEvents(new LogoutEvent(), p); + pm.registerEvents(new JoinEvent(p), p); + pm.registerEvents(new TeleportEvent(), p); + pm.registerEvents(LoggingManager.getInstance(), p); + pm.registerEvents(new SpectatorEvents(), p); + pm.registerEvents(new BandageUse(), p); + pm.registerEvents(new KitEvents(), p); + + for (Player p : Bukkit.getOnlinePlayers()) { + if (GameManager.getInstance().getBlockGameId(p.getLocation()) != -1) { + p.teleport(SettingsManager.getInstance().getLobbySpawn()); + } + } + + // new Webserver().start(); + } + } + + public void setCommands() { + getCommand("survivalgames").setExecutor(new CommandHandler(p)); + } + + public static File getPluginDataFolder() { + return datafolder; + } + + public static boolean isDisabling() { + return disabling; + } + + public WorldEditPlugin getWorldEdit() { + Plugin worldEdit = getServer().getPluginManager().getPlugin("WorldEdit"); + if (worldEdit instanceof WorldEditPlugin) { + return (WorldEditPlugin) worldEdit; + } else { + return null; + } + } + + public static void $(String msg) { + $(Level.INFO, msg); + } + + public static void $(Level l, String msg) { + logger.log(l, msg); + } + + public static void debug(String msg) { + if (SettingsManager.getInstance().getConfig().getBoolean("debug", false)) { + $(msg); + } + } + + public static void debug(int a) { + if (SettingsManager.getInstance().getConfig().getBoolean("debug", false)) { + debug(a + ""); + } + } + + public static Map sortByValue(Map map) { + List> list = new LinkedList>(map.entrySet()); + Collections.sort(list, new Comparator>() { + + public int compare(Map.Entry m1, Map.Entry m2) { + return (m2.getValue()[2]).compareTo(m1.getValue()[2]); + } + }); + Map result = new LinkedHashMap(); + for (Map.Entry entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + return result; + } + + public void updateHof(ResultSet rs) { + Map stats = new HashMap(); + try { + while (rs.next()) { + if (stats.containsKey(rs.getString("player"))) { + stats.put(rs.getString("player"), new Integer[]{ + stats.get(rs.getString("player"))[0] + rs.getInt("kills"), + stats.get(rs.getString("player"))[1] + rs.getInt("death"), + stats.get(rs.getString("player"))[2] + rs.getInt("points") + }); + } else { + stats.put(rs.getString("player"), new Integer[]{rs.getInt("kills"), rs.getInt("death"), rs.getInt("points")}); + } + } + } catch (SQLException ex) { + MessageManager.getInstance().logMessage(MessageManager.PrefixType.WARNING, ex.getMessage()); + } + FileConfiguration cfg = SettingsManager.getInstance().getSystemConfig(); + stats = sortByValue(stats); + if (cfg.contains("hof.head")) { + for (String str : cfg.getStringList("hof.head")) { + World w = Bukkit.getServer().getWorld(str.split(";")[0]); + if (w == null) { + continue; + } + Integer pos = Integer.decode(str.split(";")[4]); + if (stats.keySet().toArray().length < pos) { + continue; + } + double x = Double.parseDouble(str.split(";")[1]); + double y = Double.parseDouble(str.split(";")[2]); + double z = Double.parseDouble(str.split(";")[3]); + Block bl = w.getBlockAt(new Location(w, x, y, z)); + if (bl == null) { + continue; + } else if (!(bl.getState() instanceof Skull)) { + continue; + } + Skull s = (Skull) bl.getState(); + s.setOwner(stats.keySet().toArray()[pos - 1].toString()); + s.update(); + } + } + if (cfg.contains("hof.sign")) { + for (String str : cfg.getStringList("hof.sign")) { + World w = Bukkit.getServer().getWorld(str.split(";")[0]); + if (w == null) { + continue; + } + Integer pos = Integer.decode(str.split(";")[4]); + if (stats.keySet().toArray().length < pos) { + continue; + } + double x = Double.parseDouble(str.split(";")[1]); + double y = Double.parseDouble(str.split(";")[2]); + double z = Double.parseDouble(str.split(";")[3]); + Block bl = w.getBlockAt(new Location(w, x, y, z)); + if (bl == null) { + continue; + } else if (!(bl.getState() instanceof Sign)) { + continue; + } + Sign s = (Sign) bl.getState(); + String playerName = stats.keySet().toArray()[pos - 1].toString(); + s.setLine(0, "Position: " + pos); + s.setLine(1, playerName); + s.setLine(2, "K/D : " + stats.get(playerName)[0] + "/" + stats.get(playerName)[1]); + s.setLine(3, "Points: " + stats.get(playerName)[2]); + s.update(); + } + } + } + + public class HofUpdater implements Runnable { + + public void run() { + try { + PreparedStatement st = DatabaseManager.getInstance().createStatement("SELECT player, kills, death, points FROM " + SettingsManager.getSqlPrefix() + "playerstats;"); + ResultSet rs2 = st.executeQuery(); + if (rs2 != rs) { + updateHof(rs2); + rs = rs2; + } + } catch (SQLException ex) { + MessageManager.getInstance().logMessage(MessageManager.PrefixType.WARNING, ex.getMessage()); + } + } + } } \ No newline at end of file diff --git a/src/main/java/org/mcsg/survivalgames/commands/AddHead.java b/src/main/java/org/mcsg/survivalgames/commands/AddHead.java new file mode 100644 index 0000000..bc267c1 --- /dev/null +++ b/src/main/java/org/mcsg/survivalgames/commands/AddHead.java @@ -0,0 +1,53 @@ +package org.mcsg.survivalgames.commands; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.mcsg.survivalgames.MessageManager; +import org.mcsg.survivalgames.SettingsManager; + +public class AddHead implements SubCommand { + + public boolean onCommand(Player player, String[] args) { + if (!player.hasPermission(permission()) && !player.isOp()) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player); + return true; + } + if (args.length != 1) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.notspecified", player, "input-" + SettingsManager.getInstance().getMessageConfig().getString("messages.words.position", "Position")); + return true; + } + int pos = 0; + try { + pos = Integer.parseInt(args[0]); + if (pos <= 0) { + return false; + } + } catch (NumberFormatException e) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.notanumber", player, "input-" + args[1]); + return true; + } + Block bl = player.getTargetBlock(null, 0); + if (bl != null && bl.getType() == Material.SKULL) { + if (SettingsManager.getInstance().modifyList("head", bl.getLocation(), pos)) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.INFO, "info.success", player, "command-'addhead'"); + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "info.unsuccess", player, "command-'addhead'"); + } + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.wrongtarget", player, "type-head"); + return true; + } + return true; + } + + @Override + public String help(Player p) { + return "/sg addhead - " + SettingsManager.getInstance().getMessageConfig().getString("messages.help.addhead", "The head you are looking at will show skin of player on position "); + } + + @Override + public String permission() { + return "sg.admin.addhead"; + } +} diff --git a/src/main/java/org/mcsg/survivalgames/commands/AddSign.java b/src/main/java/org/mcsg/survivalgames/commands/AddSign.java new file mode 100644 index 0000000..1b3d526 --- /dev/null +++ b/src/main/java/org/mcsg/survivalgames/commands/AddSign.java @@ -0,0 +1,53 @@ +package org.mcsg.survivalgames.commands; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.mcsg.survivalgames.MessageManager; +import org.mcsg.survivalgames.SettingsManager; + +public class AddSign implements SubCommand { + + public boolean onCommand(Player player, String[] args) { + if (!player.hasPermission(permission()) && !player.isOp()) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player); + return true; + } + if (args.length != 1) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.notspecified", player, "input-" + SettingsManager.getInstance().getMessageConfig().getString("messages.words.position", "Position")); + return true; + } + int pos = 0; + try { + pos = Integer.parseInt(args[0]); + if (pos <= 0) { + return false; + } + } catch (NumberFormatException e) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.notanumber", player, "input-" + args[1]); + return true; + } + Block bl = player.getTargetBlock(null, 0); + if (bl != null && (bl.getType() == Material.WALL_SIGN || bl.getType() == Material.SIGN_POST)) { + if (SettingsManager.getInstance().modifyList("sign", bl.getLocation(), pos)) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.INFO, "info.success", player, "command-'addsign'"); + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "info.unsuccess", player, "command-'addsign'"); + } + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.wrongtarget", player, "type-sign"); + return true; + } + return true; + } + + @Override + public String help(Player p) { + return "/sg addsign - " + SettingsManager.getInstance().getMessageConfig().getString("messages.help.addsign", "The sign you are looking at will show stats of player on position"); + } + + @Override + public String permission() { + return "sg.admin.addsign"; + } +} diff --git a/src/main/java/org/mcsg/survivalgames/commands/DelHead.java b/src/main/java/org/mcsg/survivalgames/commands/DelHead.java new file mode 100644 index 0000000..4ea124f --- /dev/null +++ b/src/main/java/org/mcsg/survivalgames/commands/DelHead.java @@ -0,0 +1,43 @@ +package org.mcsg.survivalgames.commands; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.mcsg.survivalgames.MessageManager; +import org.mcsg.survivalgames.SettingsManager; + +public class DelHead implements SubCommand { + + public boolean onCommand(Player player, String[] args) { + if (!player.hasPermission(permission()) && !player.isOp()) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player); + return true; + } + if (args.length != 0) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.input", player, "message-" + SettingsManager.getInstance().getMessageConfig().getString("messages.error.argumentsnotneeded", "§cArguments not needed!")); + return true; + } + Block bl = player.getTargetBlock(null, 0); + if (bl != null && bl.getType() == Material.SKULL) { + if (SettingsManager.getInstance().modifyList("head", bl.getLocation(), 0)) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.INFO, "info.success", player, "command-'delhead'"); + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "info.unsuccess", player, "command-'delhead'"); + } + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.wrongtarget", player, "type-head"); + return true; + } + return true; + } + + @Override + public String help(Player p) { + return "/sg delsign - " + SettingsManager.getInstance().getMessageConfig().getString("messages.help.delhead", "Stops the head from updating the player skin"); + } + + @Override + public String permission() { + return "sg.admin.delhead"; + } +} diff --git a/src/main/java/org/mcsg/survivalgames/commands/DelSign.java b/src/main/java/org/mcsg/survivalgames/commands/DelSign.java new file mode 100644 index 0000000..8235712 --- /dev/null +++ b/src/main/java/org/mcsg/survivalgames/commands/DelSign.java @@ -0,0 +1,43 @@ +package org.mcsg.survivalgames.commands; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.mcsg.survivalgames.MessageManager; +import org.mcsg.survivalgames.SettingsManager; + +public class DelSign implements SubCommand { + + public boolean onCommand(Player player, String[] args) { + if (!player.hasPermission(permission()) && !player.isOp()) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player); + return true; + } + if (args.length != 0) { + MessageManager.getInstance().sendMessage(MessageManager.PrefixType.ERROR, "error.argumentsnotneeded", player); + return true; + } + Block bl = player.getTargetBlock(null, 0); + if (bl != null && (bl.getType() == Material.WALL_SIGN || bl.getType() == Material.SIGN_POST)) { + if (SettingsManager.getInstance().modifyList("sign", bl.getLocation(), 0)) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.INFO, "info.success", player, "command-'delsign'"); + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "info.unsuccess", player, "command-'delsign'"); + } + } else { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.wrongtarget", player, "type-sign"); + return true; + } + return true; + } + + @Override + public String help(Player p) { + return "/sg delsign - " + SettingsManager.getInstance().getMessageConfig().getString("messages.help.delsign", "Stops the sign from updating the player stats"); + } + + @Override + public String permission() { + return "sg.admin.delsign"; + } +} diff --git a/src/main/java/org/mcsg/survivalgames/commands/DelWall.java b/src/main/java/org/mcsg/survivalgames/commands/DelWall.java new file mode 100644 index 0000000..e740677 --- /dev/null +++ b/src/main/java/org/mcsg/survivalgames/commands/DelWall.java @@ -0,0 +1,63 @@ +package org.mcsg.survivalgames.commands; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.bukkit.selections.Selection; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.mcsg.survivalgames.GameManager; +import org.mcsg.survivalgames.LobbyManager; +import org.mcsg.survivalgames.MessageManager; +import org.mcsg.survivalgames.SettingsManager; + +public class DelWall implements SubCommand { + + @Override + public boolean onCommand(Player player, String[] args) { + if (!player.hasPermission(permission()) && !player.isOp()) { + MessageManager.getInstance().sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player); + return true; + } + FileConfiguration scfg = SettingsManager.getInstance().getSystemConfig(); + if (!scfg.getBoolean("sg-system.lobby.sign.set", false)) { + return true; + } + WorldEditPlugin we = GameManager.getInstance().getWorldEdit(); + Selection sel = we.getSelection(player); + if (sel == null) { + player.sendMessage(ChatColor.RED + "You must make a WorldEdit Selection first"); + return true; + } + if ((sel.getNativeMaximumPoint().getBlockX() - sel.getNativeMinimumPoint().getBlockX()) != 0 && (sel.getNativeMinimumPoint().getBlockZ() - sel.getNativeMaximumPoint().getBlockZ() != 0)) { + player.sendMessage(ChatColor.RED + " Must be in a straight line!"); + return true; + } + + for (int i = 0; i < scfg.getInt("sg-system.lobby.signno", 0) + 1; i++) { + Vector max = sel.getNativeMaximumPoint(); + Vector min = sel.getNativeMinimumPoint(); + String path = "sg-system.lobby.signs." + i + "."; + if (scfg.getInt(path + "x1", 0) == max.getBlockX() + && scfg.getInt(path + "y1", 0) == max.getBlockY() + && scfg.getInt(path + "z1", 0) == max.getBlockZ() + && scfg.getInt(path + "x2", 0) == min.getBlockX() + && scfg.getInt(path + "y2", 0) == min.getBlockY() + && scfg.getInt(path + "z2", 0) == min.getBlockZ()) { + scfg.set(path + "enabled", false); + return true; + } + } + return true; + } + + @Override + public String help(Player p) { + return "/sg addwall - " + SettingsManager.getInstance().getMessageConfig().getString("messages.help.delwall", "Add a lobby stats wall for Arena "); + } + + @Override + public String permission() { + return "sg.admin.delwall"; + } +} diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 72f6802..c7924f7 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -1 +1 @@ -version: 0 prefix: main: '&6[&4&lSG&6]' states: info: '' warning: '&c[Warning] ' error: '&4[Error] ' messages: game: playerjoingame: '&a{$player} joined the game! {$activeplayers}/{$maxplayers}' playerleavegame: '&b{$player} left the arena!' playervote: '&b{$player} voted to start the game!' countdown: '&6Game starting in {$t}' goodluck: '&6Good luck!' playersremaining: '&2There are &e{$activeplayers} &2remaining!' playerwin: '&e{$player} &3killed&e {$victim} &3to win the Survival Games on &3arena {$arena}' disablegame: '&cGame disabled!' spectate: '&aYou are now spectating! Use /sg leave to return to the lobby' graceperiodend: '&5Grace period has ended!' restockchest: '&5Chest have been restocked!' playerjoinqueue: '&aAdded to queue. You are {$queuesize} in line' playercheckqueue: '&aYou are number {$queuepos} in line' disabled: '&cArena has been disabled!' error: gamefull: '&cArena {$arena} is full!' alreadyingame: '&cArena already ingame' nopermission: '&cYou do not have permission to preform this action' gamedisabled: '&cArena {$arena} is disabled!' joinmultiplegames: '&cCannot join multiple games!' notenoughtplayers: '&cNot enought players to start!' gamedosentexist: '&cArena {$arena} dosen''t exist!' input: '&cInput error: {$message}' notingame: '&cMust be in a game to preform this action!' command: '&cThe command {$command} returned an error' nolobbyspawn: '&cLobby spawn is not set!' death: DEFAULT: '&e{$player} &2died!' BLOCK_EXPLOSION: '&e{$player} &2exploded!' ENTITY_EXPLOSION: '&e{$player} &2exploded!' DROWNING: '&e{$player} &2drowned!' FALL: '&e{$player} &2hit the ground to hard!' FIRE: '&e{$player} &2burned to death!' FIRE_TICK: '&e{$player} &2burned to death!' LAVA: '&e{$player} &2burned in lava!' LIGHTING: '&e{$player} &2was electrocuted!' MAGIC: '&e{$player} &2was killed by &faa&2magic&ff' POISON: '&e{$player} &2was posioned' PROJECTILE: '&e{$player} &2was shot' STARVATION: '&e{$player} &2starved to death!' SUICIDE: '&e{$player} &2killed themselfs' VOID: '&e{$player} &2fell into void' WITHER: '&e{$player} &2was killed by a wither!' CREEPER: '&e{$player} &2was creeper bombed!' SKELETON: '&e{$player} &2was shot by a skeleton!' ZOMBIE: '&e{$player} &2was killed by a zombie!' PIG_ZOMBIE: '&3{$player} &2was killed by a pig zombie!' SPIDER: '&e{$player} &2was killed by a spider!' CAVE_SPIDER: '&e{$player} &2was killed by a cave spider!' GHAST: '&e{$player} &2was killed by a ghast!' PLAYER: '&e{$player} &2was killed by &e{$killer} &2with a {$item}!' killstreak: level1: '&e{$player}&7 got a Double Kill!' level2: '&e{$player}&9 got a Multi Kill!' level3: '&e{$player}&5 got an Ultra Kill!' level4: '&e{$player}&4 got an Unbelievable Kill!' level5: '&a7l{$player} Unbelievable+!' \ No newline at end of file +version: 0 prefix: main: '&6[&4&lSG&6]' states: info: '' warning: '&c[Warning] ' error: '&4[Error] ' messages: game: playerjoingame: '&a{$player} joined the game! {$activeplayers}/{$maxplayers}' playerleavegame: '&b{$player} left the arena!' playervote: '&b{$player} voted to start the game!' countdown: '&6Game starting in {$t}' goodluck: '&6Good luck!' playersremaining: '&2There are &e{$activeplayers} &2remaining!' playerwin: '&e{$player} &3killed&e {$victim} &3to win the Survival Games on &3arena {$arena}' disablegame: '&cGame disabled!' spectate: '&aYou are now spectating! Use /sg leave to return to the lobby' graceperiodend: '&5Grace period has ended!' restockchest: '&5Chest have been restocked!' playerjoinqueue: '&aAdded to queue. You are {$queuesize} in line' playercheckqueue: '&aYou are number {$queuepos} in line' disabled: '&cArena has been disabled!' info: success: '&e{$command} &aexecuted successfuly.' unsuccess: '&e{$command} &cexecuted unsuccessfuly.' words: position: 'Position' error: gamefull: '&cArena {$arena} is full!' alreadyingame: '&cArena already ingame' nopermission: '&cYou do not have permission to preform this action' gamedisabled: '&cArena {$arena} is disabled!' joinmultiplegames: '&cCannot join multiple games!' notenoughtplayers: '&cNot enought players to start!' gamedosentexist: '&cArena {$arena} dosen''t exist!' input: '&cInput error: {$message}' notingame: '&cMust be in a game to preform this action!' command: '&cThe command {$command} returned an error' nolobbyspawn: '&cLobby spawn is not set!' notanumber: '&e{$input} &cis not a number!' notspecified: '&c{input} not specified!' wrongtarget: '&cThe block you are looking at is not {$type}.' argumentsnotneeded: '&cArguments not needed!' notspecified: '&c{input} not specified!' death: DEFAULT: '&e{$player} &2died!' BLOCK_EXPLOSION: '&e{$player} &2exploded!' ENTITY_EXPLOSION: '&e{$player} &2exploded!' DROWNING: '&e{$player} &2drowned!' FALL: '&e{$player} &2hit the ground to hard!' FIRE: '&e{$player} &2burned to death!' FIRE_TICK: '&e{$player} &2burned to death!' LAVA: '&e{$player} &2burned in lava!' LIGHTING: '&e{$player} &2was electrocuted!' MAGIC: '&e{$player} &2was killed by &faa&2magic&ff' POISON: '&e{$player} &2was posioned' PROJECTILE: '&e{$player} &2was shot' STARVATION: '&e{$player} &2starved to death!' SUICIDE: '&e{$player} &2killed themselfs' VOID: '&e{$player} &2fell into void' WITHER: '&e{$player} &2was killed by a wither!' CREEPER: '&e{$player} &2was creeper bombed!' SKELETON: '&e{$player} &2was shot by a skeleton!' ZOMBIE: '&e{$player} &2was killed by a zombie!' PIG_ZOMBIE: '&3{$player} &2was killed by a pig zombie!' SPIDER: '&e{$player} &2was killed by a spider!' CAVE_SPIDER: '&e{$player} &2was killed by a cave spider!' GHAST: '&e{$player} &2was killed by a ghast!' PLAYER: '&e{$player} &2was killed by &e{$killer} &2with a {$item}!' killstreak: level1: '&e{$player}&7 got a Double Kill!' level2: '&e{$player}&9 got a Multi Kill!' level3: '&e{$player}&5 got an Ultra Kill!' level4: '&e{$player}&4 got an Unbelievable Kill!' level5: '&a7l{$player} Unbelievable+!' help: delhead: 'Stops the head from updating the player skin' delsign: 'Stops the sign from updating the player stats' addhead: 'The head you are looking at will show skin of player on position ' addsign: 'The sign you are looking at will show stats of player on position' delwall: 'Add a lobby stats wall for Arena ' \ No newline at end of file