Skip to content

Commit

Permalink
Update Java compatibility to Java17
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Jan 31, 2024
1 parent 1074536 commit 279576e
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 61 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -44,7 +44,7 @@ dependencies {
api("net.kyori:adventure-text-serializer-legacy:$adventureVersion")
}

tasks.withType<JavaCompile>() {
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/surf/command/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
public List<String> 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<String> players = new ArrayList<>();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/surf/modules/antiillegal/CleanIllegal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/org/surf/modules/antilag/BlockPhysics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}
6 changes: 2 additions & 4 deletions src/main/java/org/surf/modules/patches/BookBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
55 changes: 25 additions & 30 deletions src/main/java/org/surf/modules/patches/ChunkBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}
4 changes: 1 addition & 3 deletions src/main/java/org/surf/modules/patches/GateWay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,19 +53,17 @@ 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);
}
}

@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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 279576e

Please sign in to comment.