From 77226026c07091a00511d884974d101391cfae8f Mon Sep 17 00:00:00 2001 From: kaenganxt Date: Sun, 26 Oct 2014 16:01:58 +0100 Subject: [PATCH] Add toggle double jump command/item --- src/de/anura/core/AnuraCore.java | 13 +++++++++++++ src/de/anura/core/Features.java | 33 ++++++++++++++++++++++++++++++++ src/plugin.yml | 5 ++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/de/anura/core/AnuraCore.java b/src/de/anura/core/AnuraCore.java index 7526bf9..bbabeff 100644 --- a/src/de/anura/core/AnuraCore.java +++ b/src/de/anura/core/AnuraCore.java @@ -160,6 +160,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; @@ -306,6 +307,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/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