mob blocker

yay :D
This commit is contained in:
9378062 2022-04-07 10:59:04 -04:00
parent bb78816dec
commit e9e5db7c2b
5 changed files with 43 additions and 16 deletions

View File

@ -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));

View File

@ -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)

View File

@ -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<Material> 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)
{

View File

@ -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()));

View File

@ -160,6 +160,11 @@ blockedBlocks:
- "STRUCTURE_BLOCK"
- "JIGSAW"
# What entities should be blocked?
blockedEntities:
- "WITHER"
- "ENDER_DRAGON"
worlds:
flatlands:
name: "Flatlands"