From 75c7c8560c3bb8c1b69bed2cf5487639050e13bd Mon Sep 17 00:00:00 2001 From: YoyoSource Date: Thu, 10 Dec 2020 20:16:07 +0100 Subject: [PATCH] Add ScriptListener as its own class --- .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/world/RegionListener.java | 19 ------- .../bausystem/world/ScriptListener.java | 56 +++++++++++++++++++ 3 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 267533f..45641d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -133,6 +133,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); + Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new TraceListener(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 3b421e9..f2239dc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -106,23 +106,4 @@ public class RegionListener implements Listener { } } - @EventHandler - public void onLeftClick(PlayerInteractEvent event) { - if(event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK) - return; - - ItemStack item = event.getItem(); - if(item == null || (item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK) || item.getItemMeta() == null) - return; - - event.setCancelled(true); - Player player = event.getPlayer(); - BookMeta meta = (BookMeta) item.getItemMeta(); - for(String page : meta.getPages()){ - for(String command : page.split("\n")){ - Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); - Bukkit.getServer().dispatchCommand(player, command); - } - } - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java new file mode 100644 index 0000000..69d0b09 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -0,0 +1,56 @@ +/* + 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.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.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; + +import java.util.logging.Level; + +public class ScriptListener implements Listener { + + @EventHandler + public void onLeftClick(PlayerInteractEvent event) { + if(event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK) + return; + + ItemStack item = event.getItem(); + if(item == null || (item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK) || item.getItemMeta() == null) + return; + + event.setCancelled(true); + Player player = event.getPlayer(); + BookMeta meta = (BookMeta) item.getItemMeta(); + for(String page : meta.getPages()){ + for(String command : page.split("\n")){ + Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); + Bukkit.getServer().dispatchCommand(player, command); + } + } + } + +}