From 52c198a80253d83a0d1e741430e2de9275996e5d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 10 Dec 2020 18:49:21 +0100 Subject: [PATCH] Add script item --- .../bausystem/world/RegionListener.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 70718f1..3b421e9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -23,15 +23,23 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.core.Core; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; + +import java.util.logging.Level; public class RegionListener implements Listener { @@ -97,4 +105,24 @@ public class RegionListener implements Listener { event.setLine(i, line); } } + + @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); + } + } + } } -- 2.39.5