From 4b1a03e5fb9d91b15297f1b3d940e2ad9ea0c4b9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 11 Dec 2020 12:47:32 +0100 Subject: [PATCH] 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); + } + } }