Skip to content

Commit c5bbe27

Browse files
committed
Simplify /ps flag implementation
1 parent 7fb9a36 commit c5bbe27

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

  • src/main/java/dev/espi/protectionstones/commands

src/main/java/dev/espi/protectionstones/commands/ArgFlag.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private boolean openFlagGUI(Player p, PSRegion r, int page) {
118118
}
119119

120120
// add line based on flag type
121-
boolean isGroupValueAll = groupfValue.equalsIgnoreCase("all") || groupfValue.isEmpty();;
121+
boolean isGroupValueAll = groupfValue.equalsIgnoreCase("all") || groupfValue.isEmpty();
122122
if (f instanceof StateFlag) { // allow/deny
123123

124124
TextComponent allow = new TextComponent((fValue == StateFlag.State.ALLOW ? ChatColor.WHITE : ChatColor.DARK_GRAY) + "Allow"),
@@ -184,25 +184,15 @@ private boolean openFlagGUI(Player p, PSRegion r, int page) {
184184
}
185185

186186
// set hover and click task for flag group
187-
BaseComponent[] hover;
188-
// HACK: Prevent pvp flag value from being changed to none/null
189-
// Special handling for "pvp" flag with "all" group, disabling interaction.
190-
if (flag.equalsIgnoreCase("pvp") && isGroupValueAll) {
191-
hover = new ComponentBuilder(PSL.FLAG_PREVENT_EXPLOIT_HOVER.msg()).create();
192-
// Remove click action to fully disable changing this group.
193-
groupChange.setClickEvent(null);
194-
} else if (fValue == null) {
195-
hover = new ComponentBuilder(PSL.FLAG_GUI_HOVER_CHANGE_GROUP_NULL.msg()).create();
196-
} else {
197-
hover = new ComponentBuilder(PSL.FLAG_GUI_HOVER_CHANGE_GROUP.msg().replace("%group%", nextGroup)).create();
198-
}
199-
200-
// Always set hover if the flag is pvp and group is "all"
201-
if (flag.equalsIgnoreCase("pvp") && groupfValue.equalsIgnoreCase("all")) {
202-
hover = new ComponentBuilder(PSL.FLAG_PREVENT_EXPLOIT_HOVER.msg()).create();
187+
// HACK: Prevent pvp flag group from being changed when set to "all" to prevent exploit
188+
boolean isPvpExploitCase = flag.equalsIgnoreCase("pvp") && isGroupValueAll;
189+
if (isPvpExploitCase) {
190+
BaseComponent[] hover = new ComponentBuilder(PSL.FLAG_PREVENT_EXPLOIT_HOVER.msg()).create();
203191
groupChange.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover));
204-
groupChange.setClickEvent(null); // Disable click event explicitly
205192
} else if (!nextGroup.equals(groupfValue)) {
193+
BaseComponent[] hover = fValue == null
194+
? new ComponentBuilder(PSL.FLAG_GUI_HOVER_CHANGE_GROUP_NULL.msg()).create()
195+
: new ComponentBuilder(PSL.FLAG_GUI_HOVER_CHANGE_GROUP.msg().replace("%group%", nextGroup)).create();
206196
groupChange.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover));
207197
groupChange.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, suggestedCommand + "-g " + nextGroup + " " + page + ":" + flag + " " + fValue));
208198
}

0 commit comments

Comments
 (0)