diff --git a/src/main/java/de/epiceric/shopchest/listeners/CreativeModeListener.java b/src/main/java/de/epiceric/shopchest/listeners/CreativeModeListener.java index f2d4cff..47e95b4 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/CreativeModeListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/CreativeModeListener.java @@ -54,7 +54,6 @@ public class CreativeModeListener implements Listener { ClickType.removePlayerClickType(p); ((SelectClickType) clickType).setItem(e.getCursor()); p.closeInventory(); - p.setGameMode(((SelectClickType) clickType).getGameMode()); p.sendMessage(LanguageUtils.getMessage(Message.ITEM_SELECTED, new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(e.getCursor())))); @@ -75,7 +74,6 @@ public class CreativeModeListener implements Listener { return; ClickType.removePlayerClickType(p); - p.setGameMode(((SelectClickType) clickType).getGameMode()); p.sendMessage(LanguageUtils.getMessage(Message.CREATION_CANCELLED)); } @@ -84,9 +82,6 @@ public class CreativeModeListener implements Listener { // Reset game mode on quit if SelectClickType is set Player p = e.getPlayer(); ClickType ct = ClickType.getPlayerClickType(p); - if (ct instanceof SelectClickType) { - p.setGameMode(((SelectClickType) ct).getGameMode()); - } ClickType.removePlayerClickType(p); } diff --git a/src/main/java/de/epiceric/shopchest/utils/ClickType.java b/src/main/java/de/epiceric/shopchest/utils/ClickType.java index 45f1c62..cf80916 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ClickType.java +++ b/src/main/java/de/epiceric/shopchest/utils/ClickType.java @@ -58,6 +58,10 @@ public class ClickType { */ public static void removePlayerClickType(OfflinePlayer player) { UUID uuid = player.getUniqueId(); + if (playerClickType.get(uuid) instanceof SelectClickType && player instanceof Player) { + // Reset gamemode player has select click type + ((Player) player).setGameMode(((SelectClickType) playerClickType.get(uuid)).gameMode); + } playerClickType.remove(uuid); // If a timer is still running, cancel it @@ -73,6 +77,10 @@ public class ClickType { */ public static void setPlayerClickType(OfflinePlayer player, ClickType clickType) { UUID uuid = player.getUniqueId(); + if (playerClickType.get(uuid) instanceof SelectClickType && player instanceof Player) { + // Reset gamemode player has select click type + ((Player) player).setGameMode(((SelectClickType) playerClickType.get(uuid)).gameMode); + } playerClickType.put(uuid, clickType); // If a timer is already running, cancel it