From d10f738304da7dd8983763715893b89473a1f22c Mon Sep 17 00:00:00 2001 From: 9378062 Date: Thu, 7 Apr 2022 14:05:15 -0400 Subject: [PATCH] add command sign blocking todo: move all these blockings to blackout --- .../dev/plex/listener/impl/BlockListener.java | 27 +++++++++++++++++++ .../dev/plex/listener/impl/SpawnListener.java | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/plex/listener/impl/BlockListener.java b/src/main/java/dev/plex/listener/impl/BlockListener.java index f5b300f..8cb1ff7 100644 --- a/src/main/java/dev/plex/listener/impl/BlockListener.java +++ b/src/main/java/dev/plex/listener/impl/BlockListener.java @@ -2,19 +2,24 @@ package dev.plex.listener.impl; import dev.plex.listener.PlexListener; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import dev.plex.util.PlexUtils; import net.kyori.adventure.sound.Sound; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.block.Block; +import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.metadata.FixedMetadataValue; public class BlockListener extends PlexListener { @@ -24,6 +29,8 @@ public class BlockListener extends PlexListener private static List cachedBlockedBlocksConfig = null; + private static final List SIGNS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SIGN")).toList(); + @EventHandler(priority = EventPriority.LOW) public void onBlockPlace(BlockPlaceEvent event) { @@ -57,6 +64,26 @@ public class BlockListener extends PlexListener block.setType(Material.CAKE); PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5,0.5,0.5)); } + + if(SIGNS.contains(block.getType())) + { + Sign sign = (Sign) block.getState(false); + boolean anythingChanged = false; + for (int i = 0; i < sign.lines().size(); i++) + { + Component line = sign.line(i); + if(line.clickEvent() != null) + { + anythingChanged = true; + sign.line(i, line.clickEvent(null)); + } + } + if (anythingChanged) + { + sign.update(true); + PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5, 0.5, 0.5)); + } + } } @EventHandler(priority = EventPriority.LOW) diff --git a/src/main/java/dev/plex/listener/impl/SpawnListener.java b/src/main/java/dev/plex/listener/impl/SpawnListener.java index e3d2b25..11c6d12 100644 --- a/src/main/java/dev/plex/listener/impl/SpawnListener.java +++ b/src/main/java/dev/plex/listener/impl/SpawnListener.java @@ -12,7 +12,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockDispenseEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; @@ -23,7 +22,7 @@ import java.util.List; public class SpawnListener extends PlexListener { - public static final List SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList(); + private static final List SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList(); @EventHandler public void onEntitySpawn(EntitySpawnEvent event)