diff --git a/src/de/anura/core/AnuraCore.java b/src/de/anura/core/AnuraCore.java index 41f69ec..a2026a0 100644 --- a/src/de/anura/core/AnuraCore.java +++ b/src/de/anura/core/AnuraCore.java @@ -164,6 +164,7 @@ public class AnuraCore extends JavaPlugin implements PluginMessageListener { Inventories.registerInventory("FEATURES", "features_inv", ChatColor.DARK_BLUE); Inventories.putIntoInventory("FEATURES", 2, Inventories.buildItems(Material.LEATHER_BOOTS, "inv_lobby_double_jump", ChatColor.DARK_AQUA)); + Inventories.registerAction("FEATURES", 2, Inventories.Action.COMMAND, "toggledbljump"); Inventories.registerInventory("LANGUAGE", "Select language", ChatColor.DARK_BLUE); int i = 0; @@ -177,7 +178,8 @@ public class AnuraCore extends JavaPlugin implements PluginMessageListener { Inventories.buildInvItem("COMPASS", Material.COMPASS, "select_game", ChatColor.DARK_AQUA); Inventories.buildInvItem("SIGN", Material.SIGN, "Change language", ChatColor.DARK_GREEN); Inventories.buildInvItem("PAPER", Material.PAPER, "features_item", ChatColor.BLUE); - Inventories.buildInvItem("DOOR", Material.WOOD_DOOR, "to_spawn", ChatColor.YELLOW); + Inventories.buildInvItem("DOOR", Material.WOOD_DOOR, "to_to_spawn", ChatColor.YELLOW); + Inventories.buildInvItem("EYE", Material.EYE_OF_ENDER, "inv_to_lobby", ChatColor.YELLOW); if (getConfig().getString("server-name").equals("lobby")) { Inventories.setItemInPlayerInv("COMPASS", 0); Inventories.setItemInPlayerInv("SIGN", 1); @@ -188,6 +190,7 @@ public class AnuraCore extends JavaPlugin implements PluginMessageListener { Inventories.registerItemAction("SIGN", Inventories.Action.OPEN_INV, "LANGUAGE"); Inventories.registerItemAction("PAPER", Inventories.Action.OPEN_INV, "FEATURES"); Inventories.registerItemAction("DOOR", Inventories.Action.COMMAND, "spawn"); + Inventories.registerItemAction("EYE", Inventories.Action.SERVER, "lobby"); this.pots = new FlowerPots(); ResultSet rs = sql.querySelect("SELECT id, X, Y, Z, world, type, waitTime FROM corePots"); @@ -324,6 +327,18 @@ public class AnuraCore extends JavaPlugin implements PluginMessageListener { } return true; } + else if(cmd.getName().equalsIgnoreCase("toggledbljump")) { + if(!(sender instanceof Player)) { + API.statusMsg(sender, "only_player_cmd", false); + return true; + } + if (P.getAllowFlight()) { + features.disableFeature(P, Features.Feature.DOUBLE_JUMP); + } else { + features.enableFeature(P, Features.Feature.DOUBLE_JUMP); + } + return true; + } else if(cmd.getName().equalsIgnoreCase("updatecommandblocks")) { if(!(sender instanceof BlockCommandSender)) diff --git a/src/de/anura/core/Features.java b/src/de/anura/core/Features.java index 97c2790..19bd397 100644 --- a/src/de/anura/core/Features.java +++ b/src/de/anura/core/Features.java @@ -42,6 +42,7 @@ public class Features implements Listener { private final HashMap> playerFeatures = new HashMap<>(); private final HashMap canDoubleJump = new HashMap<>(); + private final HashMap> featureEnabled = new HashMap<>(); public void updateFeatures(Player P) { @@ -50,11 +51,13 @@ public class Features implements Listener { ResultSet rs = API.getMySql().querySelect("SELECT featureId FROM coreFeatures WHERE playerId = (SELECT id FROM players WHERE uuid = '"+P.getUniqueId().toString()+"')"); resetPlayerFeatures(P); playerFeatures.put(P, new ArrayList()); + featureEnabled.put(P, new HashMap()); while(rs.next()) { if(Feature.getById(rs.getInt("featureId")) != null) { this.addFeature(P, Feature.getById(rs.getInt("featureId"))); + featureEnabled.get(P).put(Feature.DOUBLE_JUMP, true); } } } catch (SQLException ex) { @@ -78,6 +81,36 @@ public class Features implements Listener { } } + public void disableFeature(Player P, Feature f) { + if(!mainLobby()) return; + if (f == Feature.DOUBLE_JUMP) { + if (!hasFeature(P, f)) { + API.statusMsg(P, "dont_have_dbl_jump", false); + return; + } + featureEnabled.get(P).put(f, false); + canDoubleJump.put(P, false); + API.statusMsg(P, "dbl_jump_off", true); + if (P.getGameMode() != GameMode.CREATIVE) { + P.setAllowFlight(false); + } + } + } + + public void enableFeature(Player P, Feature f) { + if(!mainLobby()) return; + if (f == Feature.DOUBLE_JUMP) { + if (!hasFeature(P, f)) { + API.statusMsg(P, "dont_have_dbl_jump", false); + return; + } + featureEnabled.get(P).put(f, true); + P.setAllowFlight(true); + canDoubleJump.put(P, true); + API.statusMsg(P, "dbl_jump_on", true); + } + } + public boolean hasFeature(Player P, Feature f) { if(!mainLobby()) return false; diff --git a/src/de/anura/core/Inventories.java b/src/de/anura/core/Inventories.java index b2d8c46..debf9be 100644 --- a/src/de/anura/core/Inventories.java +++ b/src/de/anura/core/Inventories.java @@ -43,6 +43,7 @@ public class Inventories implements Listener { private static final HashMap> items = new HashMap<>(); private static final HashMap> itemActions = new HashMap<>(); private static final HashMap itemPositions = new HashMap<>(); + public static final HashMap checkInteracts = new HashMap<>(); public static void registerInventory(String type, String name, ChatColor nameColor) { HashMap langInvs = new HashMap<>(); @@ -174,6 +175,7 @@ public class Inventories implements Listener { @EventHandler public void onInvClick(InventoryClickEvent event) { + if (checkInteracts.containsKey((Player)event.getWhoClicked()) && !checkInteracts.get((Player)event.getWhoClicked())) return; final Player player = (Player) event.getWhoClicked(); Inventory inventory = event.getClickedInventory(); String invName = inventory.getName(); @@ -204,6 +206,7 @@ public class Inventories implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (checkInteracts.containsKey((Player)event.getPlayer()) && !checkInteracts.get((Player)event.getPlayer())) return; if (event.hasItem()) { if (event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR) || event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK)) { final Player P = event.getPlayer(); diff --git a/src/plugin.yml b/src/plugin.yml index 2797fbc..6735878 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -69,4 +69,7 @@ commands: usage: / updatecommandblocks: description: Updates command blocks at the given positions - usage: / {, , }... \ No newline at end of file + usage: / {, , }... + toggledbljump: + description: Toggles the double jump + usage: / \ No newline at end of file