Add toggle double jump command/item
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -42,6 +42,7 @@ public class Features implements Listener {
|
||||
|
||||
private final HashMap<Player, ArrayList<Feature>> playerFeatures = new HashMap<>();
|
||||
private final HashMap<Player, Boolean> canDoubleJump = new HashMap<>();
|
||||
private final HashMap<Player, HashMap<Feature, Boolean>> 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<Feature>());
|
||||
featureEnabled.put(P, new HashMap<Feature, Boolean>());
|
||||
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;
|
||||
|
||||
@@ -69,4 +69,7 @@ commands:
|
||||
usage: /<command> <player> <enable|disable>
|
||||
updatecommandblocks:
|
||||
description: Updates command blocks at the given positions
|
||||
usage: /<command> {<x1>, <y1>, <z1>}...
|
||||
usage: /<command> {<x1>, <y1>, <z1>}...
|
||||
toggledbljump:
|
||||
description: Toggles the double jump
|
||||
usage: /<command>
|
||||
Reference in New Issue
Block a user