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 ff3986f..2be2361 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java
@@ -19,12 +19,13 @@
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;
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;
@@ -39,7 +40,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);
@@ -48,10 +49,26 @@ public class ScriptListener implements Listener {
for(String page : meta.getPages()){
for(String command : page.split("\n")){
if (command.startsWith("#")) continue;
+
+ 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);
}
}
}
+ private boolean isNoBook(ItemStack item){
+ switch(Core.getVersion()){
+ case 12:
+ return ScriptListener_12.isNoBook(item);
+ case 15:
+ default:
+ return ScriptListener_15.isNoBook(item);
+ }
+ }
+
}