From 4b1a03e5fb9d91b15297f1b3d940e2ad9ea0c4b9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 11 Dec 2020 12:47:32 +0100 Subject: [PATCH 1/3] Fix script book in 1.12 --- .../bausystem/world/ScriptListener_12.java | 31 +++++++++++++++++++ .../bausystem/world/ScriptListener_15.java | 31 +++++++++++++++++++ .../bausystem/world/ScriptListener.java | 13 ++++++-- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/world/ScriptListener_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/world/ScriptListener_15.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/ScriptListener_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/ScriptListener_12.java new file mode 100644 index 0000000..061befa --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/world/ScriptListener_12.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.world; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +class ScriptListener_12 { + private ScriptListener_12(){} + + static boolean isNoBook(ItemStack item){ + return item.getType() != Material.BOOK_AND_QUILL && item.getType() != Material.WRITTEN_BOOK; + } +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/ScriptListener_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/ScriptListener_15.java new file mode 100644 index 0000000..3964be0 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/world/ScriptListener_15.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.world; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +class ScriptListener_15 { + private ScriptListener_15(){} + + static boolean isNoBook(ItemStack item){ + return item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 69d0b09..2dd51a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -19,8 +19,8 @@ package de.steamwar.bausystem.world; +import de.steamwar.core.Core; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -39,7 +39,7 @@ public class ScriptListener implements Listener { return; ItemStack item = event.getItem(); - if(item == null || (item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK) || item.getItemMeta() == null) + if(item == null || isNoBook(item) || item.getItemMeta() == null) return; event.setCancelled(true); @@ -53,4 +53,13 @@ public class ScriptListener implements Listener { } } + private boolean isNoBook(ItemStack item){ + switch(Core.getVersion()){ + case 12: + return ScriptListener_12.isNoBook(item); + case 15: + default: + return ScriptListener_15.isNoBook(item); + } + } } From 0f03e2b0a916baad59187b619b11a42622a08e70 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 11 Dec 2020 14:55:09 +0100 Subject: [PATCH 2/3] Hotfix WE security issue --- .../src/de/steamwar/bausystem/world/ScriptListener.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 2dd51a0..14dd914 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; @@ -47,6 +48,11 @@ public class ScriptListener implements Listener { BookMeta meta = (BookMeta) item.getItemMeta(); for(String page : meta.getPages()){ for(String command : page.split("\n")){ + PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, command); + Bukkit.getServer().getPluginManager().callEvent(preprocessEvent); + if(preprocessEvent.isCancelled()) + continue; + Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); Bukkit.getServer().dispatchCommand(player, command); } From e901568a07893a2a5cef3be499122b203ab67d70 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 11 Dec 2020 15:19:15 +0100 Subject: [PATCH 3/3] Hotfix WE security issue --- .../src/de/steamwar/bausystem/world/ScriptListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 14dd914..0d2eddb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -48,7 +48,7 @@ public class ScriptListener implements Listener { BookMeta meta = (BookMeta) item.getItemMeta(); for(String page : meta.getPages()){ for(String command : page.split("\n")){ - PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, command); + PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command); Bukkit.getServer().getPluginManager().callEvent(preprocessEvent); if(preprocessEvent.isCancelled()) continue;