use of org.bukkit.entity.Silverfish in project RedLib by Redempt.
the class ProtectionRegistrations method registerProtections.
public static void registerProtections() {
ProtectionListener.protect(BlockBreakEvent.class, ProtectionType.BREAK_BLOCK, e -> e.getPlayer(), e -> e.getBlock());
ProtectionListener.protect(BlockPlaceEvent.class, ProtectionType.PLACE_BLOCK, e -> e.getPlayer(), e -> e.getBlock());
ProtectionListener.protect(PlayerInteractEvent.class, ProtectionType.INTERACT, e -> e.getPlayer(), e -> {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getClickedBlock() == null || (RedLib.MID_VERSION >= 13 && !e.getClickedBlock().getType().isInteractable())) {
return null;
}
if (e.getClickedBlock().getState() instanceof InventoryHolder && !e.getPlayer().isSneaking()) {
return null;
}
return e.getClickedBlock();
});
Set<String> farmlandNames = new HashSet<>();
Collections.addAll(farmlandNames, "FARMLAND", "SOIL");
ProtectionListener.protect(PlayerInteractEvent.class, ProtectionType.TRAMPLE, e -> e.getPlayer(), e -> {
if (e.getAction() == Action.PHYSICAL && e.getClickedBlock() != null && farmlandNames.contains(e.getClickedBlock().getType().toString())) {
return e.getClickedBlock();
}
return null;
});
ProtectionListener.protect(InventoryOpenEvent.class, ProtectionType.CONTAINER_ACCESS, e -> (Player) e.getPlayer(), e -> getBlock(e.getInventory()));
ProtectionListener.protectMultiBlock(EntityExplodeEvent.class, ProtectionType.ENTITY_EXPLOSION, e -> null, (e, b) -> e.blockList().remove(b), e -> e.blockList());
ProtectionListener.protectMultiBlock(BlockExplodeEvent.class, ProtectionType.BLOCK_EXPLOSION, e -> null, (e, b) -> e.blockList().remove(b), e -> e.blockList());
ProtectionListener.protect(PlayerBucketFillEvent.class, ProtectionType.USE_BUCKETS, e -> e.getPlayer(), e -> e.getBlockClicked());
ProtectionListener.protect(PlayerBucketEmptyEvent.class, ProtectionType.USE_BUCKETS, e -> e.getPlayer(), e -> e.getBlockClicked());
ProtectionListener.protectMultiBlock(BlockPistonExtendEvent.class, ProtectionType.PISTONS, e -> null, (e, b) -> e.setCancelled(true), e -> {
List<Block> blocks = new ArrayList<>(e.getBlocks());
blocks.add(e.getBlock());
return blocks;
});
ProtectionListener.protectMultiBlock(BlockPistonRetractEvent.class, ProtectionType.PISTONS, e -> null, (e, b) -> e.setCancelled(true), e -> {
List<Block> blocks = new ArrayList<>(e.getBlocks());
blocks.add(e.getBlock());
return blocks;
});
ProtectionListener.protectNonCancellable(BlockRedstoneEvent.class, ProtectionType.REDSTONE, e -> null, e -> e.setNewCurrent(e.getOldCurrent()), e -> e.getBlock());
ProtectionListener.protect(EntityChangeBlockEvent.class, ProtectionType.FALLING_BLOCK, e -> null, e -> {
if (!(e.getEntity() instanceof FallingBlock)) {
return null;
}
return e.getBlock();
});
ProtectionListener.protect(EntityChangeBlockEvent.class, ProtectionType.SILVERFISH, e -> null, e -> {
if (!(e.getEntity() instanceof Silverfish)) {
return null;
}
return e.getBlock();
});
ProtectionListener.protect(EntityChangeBlockEvent.class, ProtectionType.WITHER, e -> null, e -> {
if (!(e.getEntity() instanceof Wither)) {
return null;
}
return e.getBlock();
});
ProtectionListener.protect(BlockGrowEvent.class, ProtectionType.GROWTH, e -> null, e -> e.getBlock());
ProtectionListener.protect(BlockSpreadEvent.class, ProtectionType.GROWTH, e -> null, e -> e.getNewState().getType() == Material.FIRE ? null : e.getBlock());
ProtectionListener.protect(BlockFormEvent.class, ProtectionType.GROWTH, e -> null, e -> e.getBlock());
ProtectionListener.protect(BlockFadeEvent.class, ProtectionType.FADE, e -> null, e -> e.getBlock());
ProtectionListener.protect(BlockFromToEvent.class, ProtectionType.FLOW, e -> null, e -> e.getBlock(), e -> e.getToBlock());
ProtectionListener.protect(BlockBurnEvent.class, ProtectionType.FIRE, e -> null, e -> e.getBlock());
ProtectionListener.protect(BlockSpreadEvent.class, ProtectionType.FIRE, e -> null, e -> e.getNewState().getType() == Material.FIRE ? e.getBlock() : null);
ProtectionListener.protect(CreatureSpawnEvent.class, ProtectionType.MOB_SPAWN, e -> null, e -> {
if (e.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM) {
return null;
}
return e.getEntity().getLocation().getBlock();
});
ProtectionListener.protectMultiBlock(PortalCreateEvent.class, ProtectionType.PORTAL_PAIRING, e -> null, (e, b) -> e.setCancelled(true), e -> {
if (e.getReason() != PortalCreateEvent.CreateReason.NETHER_PAIR) {
return null;
}
return e.getBlocks().stream().map(BlockState::getBlock).collect(Collectors.toList());
});
ProtectionListener.protectDirectional(BlockFromToEvent.class, ProtectionType.FLOW_IN, e -> null, e -> e.getBlock(), e -> Collections.singletonList(e.getToBlock()));
ProtectionListener.protectDirectional(BlockPistonExtendEvent.class, ProtectionType.PISTONS_IN, e -> null, e -> e.getBlock(), e -> e.getBlocks().stream().map(b -> b.getRelative(e.getDirection())).collect(Collectors.toList()));
ProtectionListener.protectDirectional(BlockPistonRetractEvent.class, ProtectionType.PISTONS_IN, e -> null, e -> e.getBlock(), e -> e.getBlocks());
ProtectionListener.protectMultiBlock(StructureGrowEvent.class, ProtectionType.STRUCTURE_GROWTH, e -> null, (e, b) -> e.setCancelled(true), e -> e.getBlocks().stream().map(BlockState::getBlock).collect(Collectors.toList()));
ProtectionListener.protectDirectional(StructureGrowEvent.class, ProtectionType.STRUCTURE_GROWTH_IN, e -> null, e -> e.getLocation().getBlock(), e -> e.getBlocks().stream().map(BlockState::getBlock).collect(Collectors.toList()));
ProtectionListener.protect(EntityBlockFormEvent.class, ProtectionType.ENTITY_FORM_BLOCK, e -> e.getEntity() instanceof Player ? (Player) e.getEntity() : null, e -> e.getBlock());
ProtectionListener.protectDirectional(InventoryMoveItemEvent.class, ProtectionType.CONTAINER_ACCESS, e -> null, e -> getBlock(e.getSource()), e -> Collections.singletonList(getBlock(e.getDestination())));
ProtectionListener.protect(PlayerInteractEntityEvent.class, ProtectionType.INTERACT_ENTITY, PlayerEvent::getPlayer, e -> e.getRightClicked() instanceof StorageMinecart ? null : e.getRightClicked().getLocation().getBlock());
ProtectionListener.protect(PlayerInteractEntityEvent.class, ProtectionType.CONTAINER_ACCESS, PlayerEvent::getPlayer, e -> e.getRightClicked() instanceof StorageMinecart ? e.getRightClicked().getLocation().getBlock() : null);
ProtectionListener.protect(PlayerArmorStandManipulateEvent.class, ProtectionType.INTERACT_ENTITY, PlayerEvent::getPlayer, e -> e.getRightClicked().getLocation().getBlock());
ProtectionListener.protect(HangingPlaceEvent.class, ProtectionType.PLACE_ENTITY, HangingPlaceEvent::getPlayer, HangingPlaceEvent::getBlock);
ProtectionListener.protect(PlayerInteractEvent.class, ProtectionType.PLACE_ENTITY, e -> e.getPlayer(), e -> {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() == null) {
return null;
}
Material type = e.getItem().getType();
if (type.toString().endsWith("BOAT") || type.toString().endsWith("MINECART") || type == Material.ARMOR_STAND) {
return e.getClickedBlock();
}
return null;
});
ProtectionListener.protect(HangingBreakByEntityEvent.class, ProtectionType.INTERACT_ENTITY, e -> e.getRemover() instanceof Player ? (Player) e.getRemover() : null, e -> e.getCause() == HangingBreakEvent.RemoveCause.ENTITY ? getBlock(e.getEntity()) : null);
ProtectionListener.protect(HangingBreakByEntityEvent.class, ProtectionType.ENTITY_EXPLOSION, e -> null, e -> e.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION ? getBlock(e.getEntity()) : null);
Set<Material> bannedDispenserItems = EnumSet.of(Material.FLINT_AND_STEEL, Material.WATER_BUCKET, Material.LAVA_BUCKET, Material.JACK_O_LANTERN, Material.PUMPKIN, Material.ARMOR_STAND);
Arrays.stream(Material.values()).filter(m -> m.toString().endsWith("MINECART") || m.toString().endsWith("BOAT") || m.toString().endsWith("_BUCKET")).forEach(bannedDispenserItems::add);
ProtectionListener.protect(BlockDispenseEvent.class, ProtectionType.DISPENSER_PLACE, e -> null, e -> bannedDispenserItems.contains(e.getItem().getType()) ? e.getBlock() : null);
ProtectionListener.protectDirectional(BlockDispenseEvent.class, ProtectionType.DISPENSER_PLACE_IN, e -> null, e -> e.getBlock(), e -> {
if (!bannedDispenserItems.contains(e.getItem().getType())) {
return null;
}
Block rel = e.getBlock().getRelative(getFace(e.getBlock()));
return Collections.singletonList(rel);
});
ProtectionListener.protectMultiBlock(BlockMultiPlaceEvent.class, ProtectionType.PLACE_BLOCK, e -> e.getPlayer(), (e, b) -> e.setCancelled(true), e -> e.getReplacedBlockStates().stream().map(BlockState::getBlock).collect(Collectors.toList()));
}
use of org.bukkit.entity.Silverfish in project CoreProtect by PlayPro.
the class EntityChangeBlockListener method onEntityChangeBlock.
@EventHandler(priority = EventPriority.MONITOR)
protected void onEntityChangeBlock(EntityChangeBlockEvent event) {
World world = event.getBlock().getWorld();
if (!event.isCancelled() && Config.getConfig(world).ENTITY_CHANGE) {
// Can be sand/gravel
Entity entity = event.getEntity();
Block block = event.getBlock();
Material newtype = event.getTo();
Material type = event.getBlock().getType();
String e = "";
if (entity instanceof Enderman) {
e = "#enderman";
} else if (entity instanceof EnderDragon) {
e = "#enderdragon";
} else if (entity instanceof Fox) {
e = "#fox";
} else if (entity instanceof Wither) {
e = "#wither";
} else if (entity instanceof Turtle) {
e = "#turtle";
} else if (entity instanceof Ravager) {
e = "#ravager";
} else if (entity instanceof Silverfish) {
if (newtype.equals(Material.AIR) || newtype.equals(Material.CAVE_AIR)) {
e = "#silverfish";
}
}
if (e.length() > 0) {
if (newtype.equals(Material.AIR) || newtype.equals(Material.CAVE_AIR)) {
Queue.queueBlockBreak(e, block.getState(), type, block.getBlockData().getAsString(), 0);
} else {
queueBlockPlace(e, block.getState(), type, block.getState(), newtype, -1, 0, event.getBlockData().getAsString());
}
}
}
}
Aggregations