Fix exploit that allows staying in creative mode

This commit is contained in:
Eric 2019-06-13 13:11:55 +02:00
parent 060c8a7295
commit 00bdbaee53
2 changed files with 8 additions and 5 deletions

View File

@ -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);
}

View File

@ -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