Skip to content

Commit b246882

Browse files
committed
Fix Godmode showing the incorrect toggle state
1 parent 03a9b0f commit b246882

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/main/java/simplexity/adminhax/commands/hax/Fly.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,5 @@ private void switchFlyState(Player player) {
6464
Util.flipPDCState(player, flyStatus, false);
6565
player.setAllowFlight(false);
6666
player.setFlying(false);
67-
return;
6867
}
6968
}

src/main/java/simplexity/adminhax/commands/withargs/GodMode.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class GodMode extends AbstractArgsCommands {
1212
public static final String GET_ARG = "get";
1313
public static final String TOGGLE_ARG = "toggle";
14-
private NamespacedKey godModeStatus = Util.GODMODE_STATUS;
14+
private final NamespacedKey godModeStatus = Util.GODMODE_STATUS;
1515

1616
public GodMode(Permission DEFAULT_PERMISSION, String DEFAULT_ARG) {
1717
super(DEFAULT_PERMISSION, DEFAULT_ARG);
@@ -51,8 +51,14 @@ public void runLogic(CommandSender sender, Player player, String arg) {
5151
}
5252

5353
public void toggleGodmode(Player player) {
54-
player.setInvulnerable(!player.isInvulnerable());
55-
Util.flipPDCState(player, godModeStatus, false);
54+
boolean currentlyEnabled = Util.isPDCStateEnabled(player, godModeStatus, false);
55+
if (currentlyEnabled) {
56+
player.setInvulnerable(false);
57+
Util.setPdcState(player, godModeStatus, false);
58+
return;
59+
}
60+
player.setInvulnerable(true);
61+
Util.setPdcState(player, godModeStatus, true);
5662
}
5763

5864
public String getGodmodeStatus(Player player) {

src/main/java/simplexity/adminhax/util/Util.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public static void flipPDCState(Player player, NamespacedKey namespacedKey, bool
7676
}
7777
}
7878

79+
public static void setPdcState(Player player, NamespacedKey namespacedKey, boolean state){
80+
PersistentDataContainer playerPdc = player.getPersistentDataContainer();
81+
playerPdc.set(namespacedKey, PersistentDataType.BOOLEAN, state);
82+
}
83+
7984
public static boolean isPDCStateEnabled(Player player, NamespacedKey namespacedKey, boolean defaultState){
8085
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
8186
return playerPDC.getOrDefault(namespacedKey, PersistentDataType.BOOLEAN, defaultState);

0 commit comments

Comments
 (0)