diff --git a/build.gradle b/build.gradle index 84b51e4..6edcfd6 100644 --- a/build.gradle +++ b/build.gradle @@ -3,20 +3,19 @@ plugins { } group = "dev.plex" -version = "1.0" +version = "1.4-SNAPSHOT" description = "Module-FalseOp" repositories { mavenCentral() maven { url "https://repo.papermc.io/repository/maven-public/" } - // maven { url "https://nexus.telesphoreo.me/repository/plex/" } + maven { url "https://nexus.telesphoreo.me/repository/plex/" } maven { url "https://repo.dmulloy2.net/repository/public/" } } dependencies { compileOnly "io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT" - // compileOnly "dev.plex:server:1.3" - compileOnly files("libs/Plex-1.4-SNAPSHOT.jar") + compileOnly "dev.plex:server:1.4-SNAPSHOT" implementation "com.comphenix.protocol:ProtocolLib:5.1.0" } diff --git a/src/main/java/dev/plex/FalseOp.java b/src/main/java/dev/plex/FalseOp.java index e25f6d8..9f463e0 100644 --- a/src/main/java/dev/plex/FalseOp.java +++ b/src/main/java/dev/plex/FalseOp.java @@ -5,11 +5,13 @@ import dev.plex.module.PlexModule; import dev.plex.util.PlexLog; import org.bukkit.Bukkit; -public class FalseOp extends PlexModule { - +public class FalseOp extends PlexModule +{ @Override - public void enable() { - if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) { + public void enable() + { + if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) + { PlexLog.error("The Plex-FalseOp module requires the ProtocolLib plugin to work."); return; } @@ -17,7 +19,7 @@ public class FalseOp extends PlexModule { } @Override - public void disable() { - // + public void disable() + { } } \ No newline at end of file diff --git a/src/main/java/dev/plex/listener/PlayerListener.java b/src/main/java/dev/plex/listener/PlayerListener.java index 0d2dc8a..287fdcb 100644 --- a/src/main/java/dev/plex/listener/PlayerListener.java +++ b/src/main/java/dev/plex/listener/PlayerListener.java @@ -24,14 +24,18 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; -public class PlayerListener extends PlexListener { +public class PlayerListener extends PlexListener +{ private final ProtocolManager protocolManager; - public PlayerListener() { + + public PlayerListener() + { protocolManager = ProtocolLibrary.getProtocolManager(); } @EventHandler - public void onJoin(PlayerJoinEvent event) { + public void onJoin(PlayerJoinEvent event) + { PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS); packet.getIntegers().write(0, event.getPlayer().getEntityId()); packet.getBytes().write(0, (byte) 28); @@ -39,84 +43,136 @@ public class PlayerListener extends PlexListener { } @EventHandler - private void onBlock(PlayerInteractEvent event) { - if (event.useInteractedBlock() == Event.Result.DENY) return; + private void onBlock(PlayerInteractEvent event) + { + if (event.useInteractedBlock() == Event.Result.DENY) + { + return; + } var type = event.getMaterial(); var player = event.getPlayer(); Block clicked = event.getClickedBlock(); - if (clicked == null) return; + if (clicked == null) + { + return; + } boolean canPlace = player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SURVIVAL; boolean canBreak = player.getGameMode() == GameMode.CREATIVE; - if (player.getGameMode() == GameMode.ADVENTURE) { + if (player.getGameMode() == GameMode.ADVENTURE) + { ItemStack item = event.getItem(); - if (item != null) { + if (item != null) + { ItemMeta meta = item.getItemMeta(); - if (meta != null) { + if (meta != null) + { canPlace = meta.getPlaceableKeys().contains(clicked.getType().getKey()); canBreak = meta.getDestroyableKeys().contains(clicked.getType().getKey()); } } } boolean clickedTargetBlock = clicked.getType() == Material.COMMAND_BLOCK || clicked.getType() == Material.CHAIN_COMMAND_BLOCK || clicked.getType() == Material.REPEATING_COMMAND_BLOCK || clicked.getType() == Material.STRUCTURE_BLOCK || clicked.getType() == Material.JIGSAW; - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && (type == Material.COMMAND_BLOCK || type == Material.CHAIN_COMMAND_BLOCK || type == Material.REPEATING_COMMAND_BLOCK || type == Material.STRUCTURE_BLOCK || type == Material.JIGSAW) && (!clickedTargetBlock || player.isSneaking())) { - if (!canPlace) return; - if (isInteractable(clicked.getType()) && !player.isSneaking()) return; + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && (type == Material.COMMAND_BLOCK || type == Material.CHAIN_COMMAND_BLOCK || type == Material.REPEATING_COMMAND_BLOCK || type == Material.STRUCTURE_BLOCK || type == Material.JIGSAW) && (!clickedTargetBlock || player.isSneaking())) + { + if (!canPlace) + { + return; + } + if (isInteractable(clicked.getType()) && !player.isSneaking()) + { + return; + } Location loc = clicked.isReplaceable() ? clicked.getLocation() : clicked.getLocation().add(event.getBlockFace().getDirection()); Block block = loc.getBlock(); - if (!block.isReplaceable()) return; - if (!block.getWorld().getNearbyEntities(block.getLocation().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5).isEmpty()) return; + if (!block.isReplaceable()) + { + return; + } + if (!block.getWorld().getNearbyEntities(block.getLocation().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5).isEmpty()) + { + return; + } Material oldType = block.getType(); BlockData oldData = block.getBlockData(); block.setType(type); BlockFace face = calcVecBlockFace(player.getLocation().getDirection()); - if (block.getBlockData() instanceof Directional directional) { + if (block.getBlockData() instanceof Directional directional) + { directional.setFacing(face.getOppositeFace()); block.setBlockData(directional); } BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), clicked, event.getItem(), player, true, player.getHandRaised()); plugin.getServer().getPluginManager().callEvent(placeEvent); - if (placeEvent.isCancelled()) { + if (placeEvent.isCancelled()) + { block.setType(oldType); block.setBlockData(oldData); return; } - if (player.getGameMode() != GameMode.CREATIVE && event.getItem() != null) event.getItem().setAmount(event.getItem().getAmount() - 1); + if (player.getGameMode() != GameMode.CREATIVE && event.getItem() != null) + { + event.getItem().setAmount(event.getItem().getAmount() - 1); + } player.closeInventory(); - } else if (event.getAction() == Action.LEFT_CLICK_BLOCK && clickedTargetBlock) { - if (!canBreak) return; - if (event.getItem() != null && (EnchantmentTarget.WEAPON.includes(event.getItem().getType()) || event.getItem().getType() == Material.DEBUG_STICK || event.getItem().getType() == Material.TRIDENT)) return; + } + else if (event.getAction() == Action.LEFT_CLICK_BLOCK && clickedTargetBlock) + { + if (!canBreak) + { + return; + } + if (event.getItem() != null && (EnchantmentTarget.WEAPON.includes(event.getItem().getType()) || event.getItem().getType() == Material.DEBUG_STICK || event.getItem().getType() == Material.TRIDENT)) + { + return; + } BlockBreakEvent breakEvent = new BlockBreakEvent(clicked, player); plugin.getServer().getPluginManager().callEvent(breakEvent); - if (breakEvent.isCancelled()) return; + if (breakEvent.isCancelled()) + { + return; + } clicked.breakNaturally(event.getItem()); } } - private static BlockFace calcVecBlockFace(Vector vector) { + private static BlockFace calcVecBlockFace(Vector vector) + { double x = Math.abs(vector.getX()); double y = Math.abs(vector.getY()); double z = Math.abs(vector.getZ()); - if (x > z) { - if (x > y) { + if (x > z) + { + if (x > y) + { return calcFacing(vector.getX(), BlockFace.EAST, BlockFace.WEST); - } else { + } + else + { return calcFacing(vector.getY(), BlockFace.UP, BlockFace.DOWN); } - } else { - if (z > y) { + } + else + { + if (z > y) + { return calcFacing(vector.getZ(), BlockFace.SOUTH, BlockFace.NORTH); - } else { + } + else + { return calcFacing(vector.getY(), BlockFace.UP, BlockFace.DOWN); } } } - private static BlockFace calcFacing(double value, BlockFace positive, BlockFace negative) { + private static BlockFace calcFacing(double value, BlockFace positive, BlockFace negative) + { return value > 0 ? positive : negative; } - private boolean isInteractable(Material material) { - return switch (material) { + private boolean isInteractable(Material material) + { + return switch (material) + { case BREWING_STAND, CAKE, CHEST, HOPPER, TRAPPED_CHEST, ENDER_CHEST, CAULDRON, COMMAND_BLOCK, REPEATING_COMMAND_BLOCK, CHAIN_COMMAND_BLOCK, BEACON, REPEATER, COMPARATOR, BARREL, DISPENSER, DROPPER, LEVER, CRAFTING_TABLE, CARTOGRAPHY_TABLE, SMITHING_TABLE, ENCHANTING_TABLE, FLETCHING_TABLE, BLAST_FURNACE, LOOM, GRINDSTONE, FURNACE, STONECUTTER, BELL, DAYLIGHT_DETECTOR, JIGSAW, STRUCTURE_BLOCK -> true; default -> diff --git a/src/main/resources/module.yml b/src/main/resources/module.yml index bc4eb57..2c10717 100644 --- a/src/main/resources/module.yml +++ b/src/main/resources/module.yml @@ -1,4 +1,4 @@ name: Module-FalseOp main: dev.plex.FalseOp description: Make clients think they have OP! -version: 1.0 \ No newline at end of file +version: 1.4-SNAPSHOT \ No newline at end of file