diff --git a/README.md b/README.md index a42ad4a..5382f07 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A plugin to fix exploits and remove illegal/NBT items for anarchy servers. ## Compatibility - Support Java 17 and higher -- Support 1.8.x - Latest Minecraft version (1.20.3) +- Support Latest Minecraft version (1.20.4) - Compatible with Paper / Paper Forks - Folia Support @@ -39,8 +39,7 @@ ___ - 📫 Discord: `dreeam___` | QQ: `2682173972` ## TODOs -* Support lower version -* Support Spigot (maybe) + * Detect items in OffHand * Detect items in Equipment slot * Delete illegal enchantments or NBT tags rather than removing items. diff --git a/build.gradle.kts b/build.gradle.kts index 1f32267..9e04a7d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "org.surf" -version = "3.4.0" +version = "3.4.1" description = "Fix exploits and remove illegal/NBT items for anarchy servers" repositories { @@ -44,7 +44,7 @@ dependencies { api("net.kyori:adventure-text-serializer-legacy:$adventureVersion") } -tasks.withType() { +tasks.withType { options.encoding = "UTF-8" } diff --git a/src/main/java/org/surf/command/CommandHandler.java b/src/main/java/org/surf/command/CommandHandler.java index e2b6ef7..fe79139 100644 --- a/src/main/java/org/surf/command/CommandHandler.java +++ b/src/main/java/org/surf/command/CommandHandler.java @@ -52,8 +52,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String alias, String[] args) { for (BaseCommand command : commands) { if (command.getName().equalsIgnoreCase(cmd.getName())) { - if (command instanceof BaseTabCommand) { - BaseTabCommand tabCommand = (BaseTabCommand) command; + if (command instanceof BaseTabCommand tabCommand) { return tabCommand.onTab(args); } else { List players = new ArrayList<>(); diff --git a/src/main/java/org/surf/modules/antiillegal/CleanIllegal.java b/src/main/java/org/surf/modules/antiillegal/CleanIllegal.java index 7048bab..9c7fa4d 100644 --- a/src/main/java/org/surf/modules/antiillegal/CleanIllegal.java +++ b/src/main/java/org/surf/modules/antiillegal/CleanIllegal.java @@ -42,8 +42,7 @@ public void onLoad(ChunkLoadEvent event) { return; } for (BlockState state : event.getChunk().getTileEntities()) { - if (state instanceof Container) { - Container container = (Container) state; + if (state instanceof Container container) { ItemUtils.deleteIllegals(container.getInventory()); } } diff --git a/src/main/java/org/surf/modules/antilag/BlockPhysics.java b/src/main/java/org/surf/modules/antilag/BlockPhysics.java index 072f8a3..ea16048 100644 --- a/src/main/java/org/surf/modules/antilag/BlockPhysics.java +++ b/src/main/java/org/surf/modules/antilag/BlockPhysics.java @@ -19,12 +19,9 @@ public void onLiquidSpread(BlockFromToEvent event) { } private boolean isChecked(Material material) { - switch (material) { - case LAVA: - case WATER: - return true; - default: - return false; - } + return switch (material) { + case LAVA, WATER -> true; + default -> false; + }; } } \ No newline at end of file diff --git a/src/main/java/org/surf/modules/patches/BookBan.java b/src/main/java/org/surf/modules/patches/BookBan.java index e15f84d..179d5a8 100644 --- a/src/main/java/org/surf/modules/patches/BookBan.java +++ b/src/main/java/org/surf/modules/patches/BookBan.java @@ -24,12 +24,10 @@ public void onJoin(PlayerJoinEvent event) { for (ItemStack item : inv.getContents()) { // if item is null, skip if (item == null || item.getType() == Material.AIR) continue; - if (!(item.getItemMeta() instanceof BlockStateMeta)) continue; - BlockStateMeta meta = (BlockStateMeta) item.getItemMeta(); - if (!(meta.getBlockState() instanceof ShulkerBox)) { + if (!(item.getItemMeta() instanceof BlockStateMeta meta)) continue; + if (!(meta.getBlockState() instanceof ShulkerBox shulkerBox)) { continue; } - ShulkerBox shulkerBox = (ShulkerBox) meta.getBlockState(); for (ItemStack shulkerItem : shulkerBox.getInventory().getContents()) { if (shulkerItem == null || shulkerItem.getType() == Material.AIR) continue; if (shulkerItem.getType() == Material.WRITTEN_BOOK) { diff --git a/src/main/java/org/surf/modules/patches/ChunkBan.java b/src/main/java/org/surf/modules/patches/ChunkBan.java index b560269..7729833 100644 --- a/src/main/java/org/surf/modules/patches/ChunkBan.java +++ b/src/main/java/org/surf/modules/patches/ChunkBan.java @@ -65,38 +65,33 @@ public void onSpawn(PlayerInteractEvent event) { } private boolean isChecked(Block block) { - switch (block.getType()) { - case FURNACE: - //TODO - case TRAPPED_CHEST: -// case ENCHANTMENT_TABLE: -// case WALL_BANNER: - case ACACIA_SIGN: - case ACACIA_WALL_SIGN: - case HOPPER: - case DROPPER: - case DISPENSER: - case BREWING_STAND: - case BEACON: -// case SIGN_POST: - case ENDER_CHEST: - case FLOWER_POT: - case BLACK_BANNER: - case PLAYER_HEAD: - case PLAYER_WALL_HEAD: - return true; - default: - return false; - } + return switch (block.getType()) { + //TODO + //case ENCHANTMENT_TABLE: + //case WALL_BANNER: + //case SIGN_POST: + case FURNACE, + TRAPPED_CHEST, + ACACIA_SIGN, + ACACIA_WALL_SIGN, + HOPPER, + DROPPER, + DISPENSER, + BREWING_STAND, + BEACON, + ENDER_CHEST, + FLOWER_POT, + BLACK_BANNER, + PLAYER_HEAD, + PLAYER_WALL_HEAD-> true; + default -> false; + }; } private boolean isSkull(Material material) { - switch (material) { - case PLAYER_HEAD: - case PLAYER_WALL_HEAD: - return true; - default: - return false; - } + return switch (material) { + case PLAYER_HEAD, PLAYER_WALL_HEAD -> true; + default -> false; + }; } } diff --git a/src/main/java/org/surf/modules/patches/GateWay.java b/src/main/java/org/surf/modules/patches/GateWay.java index 5b8f2e9..9b663b3 100644 --- a/src/main/java/org/surf/modules/patches/GateWay.java +++ b/src/main/java/org/surf/modules/patches/GateWay.java @@ -20,7 +20,6 @@ import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.event.vehicle.VehicleMoveEvent; import org.bukkit.util.Vector; -import org.surf.Main; import org.surf.util.ConfigCache; import org.surf.util.Utils; @@ -82,10 +81,9 @@ public void EndGatewayTeleportProtection(VehicleMoveEvent event) { if (vehicle.getWorld().getEnvironment() != Environment.THE_END) { return; } - if (!(vehicle.getPassenger() instanceof Player)) { + if (!(vehicle.getPassenger() instanceof Player player)) { return; } - Player player = (Player) vehicle.getPassenger(); for (BlockFace face : BlockFace.values()) { Block next = vehicle.getLocation().getBlock().getRelative(face); if (next.getType() == Material.END_GATEWAY) { diff --git a/src/main/java/org/surf/modules/patches/IllegalDamageAndPotionCheck.java b/src/main/java/org/surf/modules/patches/IllegalDamageAndPotionCheck.java index b9ca456..c4a488b 100644 --- a/src/main/java/org/surf/modules/patches/IllegalDamageAndPotionCheck.java +++ b/src/main/java/org/surf/modules/patches/IllegalDamageAndPotionCheck.java @@ -24,14 +24,25 @@ public void onDamage(EntityDamageByEntityEvent event) { if (!ConfigCache.AntiIllegalCheckIllegalDamage) { return; } - if (!(event.getDamager() instanceof Player)) { + if (!(event.getDamager() instanceof Player damager)) { return; } - Player damager = (Player) event.getDamager(); if (event.getDamage() > 30) { event.setCancelled(true); Utils.sendMessage(damager, ConfigCache.IllegalDamageMessage); } + + /* + Entity damager = event.getDamager(); + if (event.getEntity().getEntityId() != damager.getEntityId() && event.getEntity() instanceof Player) { + // Cancel damage if an entity get damage >= 30 + if (event.getDamage() > 30) { + event.setCancelled(true); + // Send msg if damager is a player + if (damager instanceof Player) Utils.sendMessage(damager, ConfigCache.IllegalDamageMessage); + } + } + */ } @EventHandler(ignoreCancelled = true) @@ -42,8 +53,7 @@ public void onBow(EntityDamageByEntityEvent event) { if (!(event.getDamager() instanceof Arrow)) { return; } - if (((Arrow) event.getDamager()).getShooter() instanceof Player && event.getDamage() > 40) { - Player damager = (Player) ((Arrow) event.getDamager()).getShooter(); + if (((Arrow) event.getDamager()).getShooter() instanceof Player damager && event.getDamage() > 40) { event.setCancelled(true); Utils.sendMessage(damager, ConfigCache.IllegalDamageMessage); } @@ -51,10 +61,9 @@ public void onBow(EntityDamageByEntityEvent event) { @EventHandler(ignoreCancelled = true) public void onThrow(PotionSplashEvent event) { - if (!(event.getPotion().getShooter() instanceof Player)) { + if (!(event.getPotion().getShooter() instanceof Player player)) { return; } - Player player = (Player) event.getPotion().getShooter(); ItemStack pot = event.getPotion().getItem(); for (PotionEffect effects : event.getPotion().getEffects()) { if (effects.getAmplifier() > 5 @@ -110,11 +119,10 @@ public void onDispense(BlockDispenseEvent event) { @EventHandler(ignoreCancelled = true) public void onHit(ProjectileHitEvent event) { - if (!(event.getEntity() instanceof Arrow) || !(event.getEntity().getShooter() instanceof Player) + if (!(event.getEntity() instanceof Arrow arrow) || !(event.getEntity().getShooter() instanceof Player) || !(event.getHitEntity() instanceof Player)) { return; } - Arrow arrow = (Arrow) event.getEntity(); Player shooter = (Player) arrow.getShooter(); for (PotionEffect effects : arrow.getCustomEffects()) { if (effects.getAmplifier() > 4