Skip to content

Commit

Permalink
improve code for legacy sign command module
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 1, 2024
1 parent beffa3e commit 61a5357
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class CommandSign extends AEFModule {
public class CommandSign extends AEFModule implements Listener {

private final Listener signCommandListener;

Expand All @@ -21,16 +21,7 @@ public CommandSign() {
"Patch signs that have run_command NBT tags attached, allowing the \n" +
"to run a command with operator permissions on click. \n" +
"Recommended to enable if you had a rogue admin or backdoor incident.");
this.signCommandListener = SignCommandListener.isSupported() ? new SignCommandListener() : new Listener() {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (!MaterialUtil.SIGNS.contains(event.getClickedBlock().getType())) return;
if (!CachingPermTool.hasPermission(AEFPermission.BYPASS_PREVENTION_COMMANDSIGN, event.getPlayer())) {
event.setCancelled(true);
}
}
};
this.signCommandListener = SignCommandListener.isSupported() ? new SignCommandListener() : this;
}

@Override
Expand All @@ -47,4 +38,15 @@ public boolean shouldEnable() {
public void disable() {
HandlerList.unregisterAll(signCommandListener);
}

// Fallback listener, just cancels any right-clicking on signs
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (!MaterialUtil.SIGNS.contains(event.getClickedBlock().getType())) return;

if (!CachingPermTool.hasPermission(AEFPermission.BYPASS_PREVENTION_COMMANDSIGN, event.getPlayer())) {
event.setCancelled(true);
}
}
}

0 comments on commit 61a5357

Please sign in to comment.