From 041741bc756d43551056019096d870d02fe20cb4 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 16:39:21 +0100 Subject: [PATCH] Fix CommandTNT Fix RegionToggleCommand --- .../bausystem/commands/CommandTNT.java | 51 ++++++++++--------- .../commands/RegionToggleCommand.java | 17 ++++--- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index c5ccad2..4230f93 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -116,31 +116,32 @@ public class CommandTNT implements CommandExecutor, Listener { } } - TNTMode finalRequestedMode = requestedMode; - String finalRequestedMessage = requestedMessage; - Region.getRegion(player.getLocation(), region -> { - if (finalRequestedMode != null) { - region.setTntMode(finalRequestedMode); - RegionToggleCommand.actionBar(region, finalRequestedMessage); - return; - } - switch (region.getTntMode()) { - case ON: - case ONLY_TB: - region.setTntMode(TNTMode.OFF); - RegionToggleCommand.actionBar(region, getDisableMessage()); - break; - case OFF: - if (Region.buildAreaEnabled()) { - region.setTntMode(TNTMode.ONLY_TB); - RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); - } else { - region.setTntMode(TNTMode.ON); - RegionToggleCommand.actionBar(region, getEnableMessage()); - } - break; - } - }, () -> RegionToggleCommand.actionBar(player, getNoRegionMessage())); + Region region = Region.getRegion(player.getLocation()); + if (region == null) { + RegionToggleCommand.actionBar(player, getNoRegionMessage()); + return false; + } + if (requestedMode != null) { + region.setTntMode(requestedMode); + RegionToggleCommand.actionBar(region, requestedMessage); + return false; + } + switch (region.getTntMode()) { + case ON: + case ONLY_TB: + region.setTntMode(TNTMode.OFF); + RegionToggleCommand.actionBar(region, getDisableMessage()); + break; + case OFF: + if (Region.buildAreaEnabled()) { + region.setTntMode(TNTMode.ONLY_TB); + RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); + } else { + region.setTntMode(TNTMode.ON); + RegionToggleCommand.actionBar(region, getEnableMessage()); + } + break; + } return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 7aaff41..6b01ea4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -52,13 +52,16 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { return false; } - Region.getRegion(player.getLocation(), region -> { - if (toggle(region)) { - actionBar(region, getEnableMessage()); - } else { - actionBar(region, getDisableMessage()); - } - }, () -> actionBar(player, getNoRegionMessage())); + Region region = Region.getRegion(player); + if (region == null) { + actionBar(player, getNoRegionMessage()); + return false; + } + if (toggle(region)) { + actionBar(region, getEnableMessage()); + } else { + actionBar(region, getDisableMessage()); + } return false; }