diff --git a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java index 653bd81..fbc2812 100644 --- a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java +++ b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java @@ -35,7 +35,7 @@ public class EntityWipeCMD extends PlexCommand EntityType[] entityTypes = EntityType.values(); entityWhitelist.removeIf(name -> { - boolean res = Arrays.stream(entityTypes).noneMatch(entityType -> entityType.name().equalsIgnoreCase(name)); + boolean res = Arrays.stream(entityTypes).noneMatch(entityType -> name.equalsIgnoreCase(entityType.name())); if (res) { sender.sendMessage(messageComponent("invalidEntityType", name)); diff --git a/src/main/java/dev/plex/listener/impl/BlockListener.java b/src/main/java/dev/plex/listener/impl/BlockListener.java index c8993ed..f5b300f 100644 --- a/src/main/java/dev/plex/listener/impl/BlockListener.java +++ b/src/main/java/dev/plex/listener/impl/BlockListener.java @@ -4,9 +4,13 @@ import dev.plex.listener.PlexListener; import java.util.ArrayList; import java.util.List; +import dev.plex.util.PlexUtils; import net.kyori.adventure.sound.Sound; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; @@ -41,24 +45,18 @@ public class BlockListener extends PlexListener } } - if (blockedBlocks.contains(event.getBlock().getType())) - { - event.getBlock().setType(Material.CAKE); - Particle.CLOUD.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(5).spawn(); - Particle.FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).extra(0).offset(0.5,0.5,0.5).count(3).spawn(); - Particle.SOUL_FIRE_FLAME.builder().location(event.getBlock().getLocation().add(0.5,0.5,0.5)).receivers(event.getPlayer()).offset(0.5,0.5,0.5).extra(0).count(2).spawn(); - event.getPlayer().playSound(Sound.sound(org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH.key(), Sound.Source.BLOCK, 0.5f, 0.5f)); - } - - if (blockedPlayers.size() == 0) - { - return; - } + Block block = event.getBlock(); if (blockedPlayers.contains(event.getPlayer().getName())) { event.setCancelled(true); } + + if (blockedBlocks.contains(block.getType())) + { + block.setType(Material.CAKE); + 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 766ab1e..a6356b0 100644 --- a/src/main/java/dev/plex/listener/impl/SpawnListener.java +++ b/src/main/java/dev/plex/listener/impl/SpawnListener.java @@ -1,15 +1,19 @@ package dev.plex.listener.impl; import dev.plex.listener.PlexListener; +import dev.plex.util.PlexUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.Directional; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; 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; @@ -18,10 +22,22 @@ import java.util.List; public class SpawnListener extends PlexListener { - // TODO: CONFIGURABILITY!!! - public static final List SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList(); + @EventHandler + public void onEntitySpawn(EntitySpawnEvent event) + { + if(plugin.config.getStringList("blockedEntities").stream().anyMatch(type -> type.equalsIgnoreCase(event.getEntityType().name()))) + { + event.setCancelled(true); + Location location = event.getLocation(); + for (Player player : location.getNearbyEntitiesByType(Player.class, 10)) + { + PlexUtils.disabledEffect(player, location); + } + } + } + @EventHandler public void onDispense(BlockDispenseEvent event) { diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index ac04361..45c7b0f 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -66,6 +66,14 @@ public class PlexUtils extends PlexBase } } + public static void disabledEffect(Player player, Location location) + { + Particle.CLOUD.builder().location(location).receivers(player).extra(0).offset(0.5,0.5,0.5).count(5).spawn(); + Particle.FLAME.builder().location(location).receivers(player).extra(0).offset(0.5,0.5,0.5).count(3).spawn(); + Particle.SOUL_FIRE_FLAME.builder().location(location).receivers(player).offset(0.5,0.5,0.5).extra(0).count(2).spawn(); + player.playSound(net.kyori.adventure.sound.Sound.sound(org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH.key(), net.kyori.adventure.sound.Sound.Source.BLOCK, 0.5f, 0.5f)); + } + public static ChatColor randomChatColor() { return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size())); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9324c18..49f88e2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -160,6 +160,11 @@ blockedBlocks: - "STRUCTURE_BLOCK" - "JIGSAW" +# What entities should be blocked? +blockedEntities: + - "WITHER" + - "ENDER_DRAGON" + worlds: flatlands: name: "Flatlands"