From 33a18c1596f51bc9e826f52e89256c56f6917c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Mon, 23 May 2022 17:54:40 +0200 Subject: [PATCH 1/2] plot protection fixes --- pom.xml | 6 +- .../modnmetl/virtualrealty/VirtualRealty.java | 3 +- .../configs/PermissionsConfiguration.java | 1 + .../configs/PluginConfiguration.java | 6 + .../enums/materials/DoorMaterial.java | 17 ++ .../enums/materials/InteractMaterial.java | 51 ++-- .../enums/materials/StorageMaterial.java | 34 +++ .../enums/materials/SwitchMaterial.java | 2 + .../enums/permissions/RegionPermission.java | 18 +- .../listeners/PlotEntranceListener.java | 49 ++-- .../protection/PlotProtectionListener.java | 249 ++++++++++++++++-- .../protection/WorldProtectionListener.java | 8 +- .../modnmetl/virtualrealty/objects/Plot.java | 41 ++- .../objects/region/GridStructure.java | 2 - .../modnmetl/virtualrealty/utils/Loader.java | 71 ++--- .../virtualrealty/utils/VectorUtils.java | 2 +- .../utils/data/SchematicUtil.java | 1 - 17 files changed, 415 insertions(+), 146 deletions(-) create mode 100644 src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java create mode 100644 src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java diff --git a/pom.xml b/pom.xml index 3e1c1ef..e435ac1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.modnmetl virtualrealty - 2.1.0 + 2.2.0 jar A plot creation and management plugin for Minecraft @@ -103,7 +103,7 @@ org.jetbrains annotations - 22.0.0 + 23.0.0 provided @@ -169,7 +169,7 @@ org.projectlombok lombok - 1.18.22 + 1.18.24 provided diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index 19f62ee..44c8093 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -136,8 +136,9 @@ public void onEnable() { } if (!pluginConfiguration.license.key.isEmpty() && !pluginConfiguration.license.email.isEmpty()) { try { - new Loader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion(), getLoader(), false); + new Loader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion(), getLoader(), VirtualRealty.getPluginConfiguration().loaderDebugMode); } catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); getLogger().log(Level.WARNING, "Load of premium features failed."); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java index 1c432d5..7fa7d37 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java @@ -26,6 +26,7 @@ public class PermissionsConfiguration extends OkaeriConfig { @Comment(" - ENTITY_DAMAGE") @Comment(" - SWITCH") @Comment(" - ITEM_USE") + @Comment(" - DOORS") @Comment(" ") @Comment("Set permissions for players who are not members of the plot.") private final List defaultNonMembers = new LinkedList<>(); diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java index 1f93abc..8fa7b0f 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java @@ -23,6 +23,9 @@ public class PluginConfiguration extends OkaeriConfig { @Comment("Debug mode") public boolean debugMode = false; + @Comment("Loader debug mode (only for devs)") + public boolean loaderDebugMode = false; + @Comment("Here you put your license details") public License license = new License(); @@ -44,6 +47,9 @@ public static class License extends OkaeriConfig { @CustomKey("default-plot-gamemode") public String plotGamemode = "SURVIVAL"; + @Comment("Disable natural spawning of hostile mobs in plots/areas") + public boolean plotMobsSpawn = true; + @Comment("Lock gamemode to plot default when player enters their plot (disables '/plot gm' command)") public boolean lockPlotGamemode = false; diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java b/src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java new file mode 100644 index 0000000..1c9e466 --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java @@ -0,0 +1,17 @@ +package com.modnmetl.virtualrealty.enums.materials; + +public enum DoorMaterial { + + WOODEN_DOOR, + IRON_DOOR_BLOCK, + ACACIA_DOOR, + WARPED_DOOR, + CRIMSON_DOOR, + BIRCH_DOOR, + DARK_OAK_DOOR, + IRON_DOOR, + JUNGLE_DOOR, + OAK_DOOR, + SPRUCE_DOOR + +} diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java b/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java index b0a9157..9850029 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java +++ b/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java @@ -2,17 +2,28 @@ public enum InteractMaterial { - WOODEN_DOOR, - IRON_DOOR_BLOCK, + SMITHING_TABLE, + LOOM, + GRINDSTONE, + CARTOGRAPY_TABLE, + WARPED_FENCE_GATE, CRIMSON_FENCE_GATE, - WARPED_DOOR, - CRIMSON_DOOR, - ACACIA_DOOR, + BIRCH_TRAPDOOR, + ACACIA_TRAPDOOR, + DARK_OAK_TRAPDOOR, + IRON_TRAPDOOR, + TRAP_DOOR, + CRIMSON_TRAPDOOR, + WARPED_TRAPDOOR, + OAK_TRAPDOOR, + SPRUCE_TRAPDOOR, + JUNGLE_TRAPDOOR, + ACACIA_FENCE_GATE, ACACIA_BUTTON, - ACACIA_TRAPDOOR, + ANVIL, ARMOR_STAND, BARREL, @@ -21,17 +32,13 @@ public enum InteractMaterial { BELL, BIRCH_BOAT, BIRCH_BUTTON, - BIRCH_DOOR, BIRCH_FENCE_GATE, - BIRCH_TRAPDOOR, + BLACK_BED, - BLACK_SHULKER_BOX, BLAST_FURNACE, BLUE_BED, - BLUE_SHULKER_BOX, BREWING_STAND, BROWN_BED, - BROWN_SHULKER_BOX, CAMPFIRE, CAULDRON, CHEST, @@ -44,13 +51,11 @@ public enum InteractMaterial { COMPOSTER, CRAFTING_TABLE, CYAN_BED, - CYAN_SHULKER_BOX, DAMAGED_ANVIL, DARK_OAK_BOAT, DARK_OAK_BUTTON, DARK_OAK_FENCE_GATE, - DARK_OAK_TRAPDOOR, - DARK_OAK_DOOR, + DAYLIGHT_DETECTOR, DAYLIGHT_DETECTOR_INVERTED, DIODE, @@ -69,45 +74,34 @@ public enum InteractMaterial { EXPLOSIVE_MINECART, FARMLAND, FLETCHING_TABLE, - FLOWER_POT, FURNACE, FURNACE_MINECART, GRAY_BED, - GRAY_SHULKER_BOX, GREEN_BED, - GREEN_SHULKER_BOX, HOPPER, HOPPER_MINECART, - IRON_DOOR, - IRON_TRAPDOOR, + ITEM_FRAME, JUKEBOX, JUNGLE_BUTTON, JUNGLE_BOAT, - JUNGLE_DOOR, JUNGLE_FENCE_GATE, LEVER, LIGHT_BLUE_BED, - LIGHT_BLUE_SHULKER_BOX, LIGHT_GRAY_BED, - LIGHT_GRAY_SHULKER_BOX, LIME_BED, LIME_SHULKER_BOX, MAGENTA_BED, - MAGENTA_SHULKER_BOX, MINECART, NOTE_BLOCK, OAK_BOAT, OAK_BUTTON, - OAK_DOOR, OAK_FENCE_GATE, ORANGE_BED, - ORANGE_SHULKER_BOX, PINK_BED, PINK_SHULKER_BOX, POWERED_MINECART, PURPLE_BED, - PURPLE_SHULKER_BOX, RED_BED, RED_SHULKER_BOX, REDSTONE_ORE, @@ -122,23 +116,18 @@ public enum InteractMaterial { SHULKER_BOX, SIGN, SIGN_POST, - SMITHING_TABLE, SMOKER, SPRUCE_BOAT, SPRUCE_BUTTON, - SPRUCE_DOOR, SPRUCE_FENCE_GATE, STONECUTTER, STONE_BUTTON, STORAGE_MINECART, TNT_MINECART, TNT, - TRAP_DOOR, TRAPPED_CHEST, WHITE_BED, - WHITE_SHULKER_BOX, WOOD_BUTTON, YELLOW_BED, - YELOW_SHULKER_BOX; } diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java b/src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java new file mode 100644 index 0000000..882855a --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java @@ -0,0 +1,34 @@ +package com.modnmetl.virtualrealty.enums.materials; + +public enum StorageMaterial { + + CHEST, + TRAPPED_CHEST, + CHEST_MINECART, + ENDER_CHEST, + + DISPENSER, + DROPPER, + HOPPER, + SMOKER, + BARREL, + + SHULKER_BOX, + CYAN_SHULKER_BOX, + YELLOW_SHULKER_BOX, + LIGHT_BLUE_SHULKER_BOX, + GRAY_SHULKER_BOX, + GREEN_SHULKER_BOX, + RED_SHULKER_BOX, + ORANGE_SHULKER_BOX, + MAGENTA_SHULKER_BOX, + LIME_SHULKER_BOX, + PINK_SHULKER_BOX, + LIGHT_GRAY_SHULKER_BOX, + PURPLE_SHULKER_BOX, + BLUE_SHULKER_BOX, + BLACK_SHULKER_BOX, + WHITE_SHULKER_BOX, + BROWN_SHULKER_BOX, + +} diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java b/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java index 2e15752..c0bd071 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java +++ b/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java @@ -13,6 +13,8 @@ public enum SwitchMaterial { ACACIA_BUTTON, DARK_OAK_BUTTON, WARPED_BUTTON, + CRIMSON_BUTTON, + POLISHED_BLACKSTONE_BUTTON, TRIPWIRE, COMPARATOR, diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java b/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java index 6742998..581364b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java +++ b/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java @@ -15,21 +15,29 @@ public enum RegionPermission { ARMOR_STAND(3, "Armor Stand", new ItemBuilder(Material.ARMOR_STAND)), ENTITY_DAMAGE(4, "Entity Damage", new ItemBuilder(Material.IRON_SWORD).addItemFlag(ItemFlag.HIDE_ATTRIBUTES)), SWITCH(5, "Switch", new ItemBuilder(Material.LEVER)), - ITEM_USE(6, "Item Use", new ItemBuilder(Material.FLINT_AND_STEEL)); + ITEM_USE(6, "Item Use", new ItemBuilder(Material.FLINT_AND_STEEL)), + DOORS(7, "Doors", new ItemBuilder(Material.OAK_DOOR)); - private final int slot; + private final int index; private final String name; private final ItemBuilder item; - RegionPermission(int slot, String name, ItemBuilder item) { - this.slot = slot; + RegionPermission(int index, String name, ItemBuilder item) { + this.index = index; this.name = name; this.item = item; } public static RegionPermission getPermission(int i) { + int currentSlot = 0; + int endings = 0; for (RegionPermission value : values()) { - if (value.getSlot() == i) return value; + if ((currentSlot-endings)%7==0 && currentSlot!=0) { + currentSlot+=2; + endings+=2; + } + if (currentSlot == i) return value; + currentSlot++; } return null; } diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java index 3f306a8..e9a129d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java @@ -18,6 +18,7 @@ import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; +import java.util.Objects; public class PlotEntranceListener extends VirtualListener { @@ -32,13 +33,14 @@ public void onPlotMove(PlayerMoveEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); Location to = e.getTo(); + if (to == null) return; Plot plot = PlotManager.getPlot(to); if (plot != null) { OfflinePlayer offlinePlayer; String enterPlotString = VirtualRealty.getMessages().enteredAvailablePlot; if (plot.getOwnedBy() != null) { offlinePlayer = Bukkit.getOfflinePlayer(plot.getOwnedBy()); - enterPlotString = VirtualRealty.getMessages().enteredOwnedPlot.replaceAll("%owner%", offlinePlayer.getName()).replaceAll("%plot_id%", plot.getID() + ""); + enterPlotString = VirtualRealty.getMessages().enteredOwnedPlot.replaceAll("%owner%", Objects.requireNonNull(offlinePlayer.getName())).replaceAll("%plot_id%", plot.getID() + ""); } if (!enteredPlot.containsKey(player)) { enteredPlot.put(player, new AbstractMap.SimpleEntry<>(plot, true)); @@ -72,34 +74,33 @@ public void onPlotMove(PlayerMoveEvent e) { } } } else { - if (enteredPlot.containsKey(player)) { - if (enteredPlot.get(player).getValue()) { - OfflinePlayer offlinePlayer; - String leavePlotString = VirtualRealty.getMessages().leftAvailablePlot; - if (enteredPlot.get(player).getKey().getOwnedBy() != null) { - offlinePlayer = Bukkit.getOfflinePlayer(enteredPlot.get(player).getKey().getOwnedBy()); - leavePlotString = VirtualRealty.getMessages().leftOwnedPlot.replaceAll("%owner%", offlinePlayer.getName()).replaceAll("%plot_id%", enteredPlot.get(player).getKey().getID() + ""); - if (VirtualRealty.getPluginConfiguration().enablePlotGamemode) { - if (enteredPlot.get(player).getKey().hasMembershipAccess(player.getUniqueId())) { - player.setGameMode(Bukkit.getServer().getDefaultGameMode()); - } + if (!enteredPlot.containsKey(player)) return; + if (enteredPlot.get(player).getValue()) { + OfflinePlayer offlinePlayer; + String leavePlotString = VirtualRealty.getMessages().leftAvailablePlot; + if (enteredPlot.get(player).getKey().getOwnedBy() != null) { + offlinePlayer = Bukkit.getOfflinePlayer(enteredPlot.get(player).getKey().getOwnedBy()); + leavePlotString = VirtualRealty.getMessages().leftOwnedPlot.replaceAll("%owner%", Objects.requireNonNull(offlinePlayer.getName())).replaceAll("%plot_id%", enteredPlot.get(player).getKey().getID() + ""); + if (VirtualRealty.getPluginConfiguration().enablePlotGamemode) { + if (enteredPlot.get(player).getKey().hasMembershipAccess(player.getUniqueId())) { + player.setGameMode(Bukkit.getServer().getDefaultGameMode()); } } - if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) { - if (VirtualRealty.getPluginConfiguration().plotSound) { - player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, 0.3f, 1f); - } - if (enteredPlot.get(player).getKey().getPlotSize() == PlotSize.AREA) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(VirtualRealty.getMessages().leftProtectedArea)); - } else { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(leavePlotString)); - } + } + if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) { + if (VirtualRealty.getPluginConfiguration().plotSound) { + player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, 0.3f, 1f); + } + if (enteredPlot.get(player).getKey().getPlotSize() == PlotSize.AREA) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(VirtualRealty.getMessages().leftProtectedArea)); + } else { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(leavePlotString)); } - enteredPlot.remove(player); - return; } - enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(enteredPlot.get(player).getKey(), false)); + enteredPlot.remove(player); + return; } + enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(enteredPlot.get(player).getKey(), false)); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java index 1d61616..9fef9b6 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java @@ -1,7 +1,9 @@ package com.modnmetl.virtualrealty.listeners.protection; import com.modnmetl.virtualrealty.VirtualRealty; +import com.modnmetl.virtualrealty.enums.materials.DoorMaterial; import com.modnmetl.virtualrealty.enums.materials.InteractMaterial; +import com.modnmetl.virtualrealty.enums.materials.StorageMaterial; import com.modnmetl.virtualrealty.enums.permissions.RegionPermission; import com.modnmetl.virtualrealty.enums.materials.SwitchMaterial; import com.modnmetl.virtualrealty.listeners.VirtualListener; @@ -20,6 +22,7 @@ import org.bukkit.event.block.*; import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.*; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.world.StructureGrowEvent; @@ -34,20 +37,34 @@ public class PlotProtectionListener extends VirtualListener { public static final Permission PLOT_BUILD = new Permission("virtualrealty.build.plot"); - public static final LinkedList INTERACTABLE = new LinkedList<>(); - public static final LinkedList SWITCHABLE = new LinkedList<>(); + public static final LinkedList INTERACT = new LinkedList<>(); + public static final LinkedList SWITCHES = new LinkedList<>(); + public static final LinkedList STORAGES = new LinkedList<>(); + public static final LinkedList DOORS = new LinkedList<>(); static { for (InteractMaterial value : InteractMaterial.values()) { Material material = Material.getMaterial(value.toString()); if (Objects.nonNull(material)) { - INTERACTABLE.add(material); + INTERACT.add(material); } } for (SwitchMaterial value : SwitchMaterial.values()) { Material material = Material.getMaterial(value.toString()); if (Objects.nonNull(material)) { - SWITCHABLE.add(material); + SWITCHES.add(material); + } + } + for (StorageMaterial value : StorageMaterial.values()) { + Material material = Material.getMaterial(value.toString()); + if (Objects.nonNull(material)) { + STORAGES.add(material); + } + } + for (DoorMaterial value : DoorMaterial.values()) { + Material material = Material.getMaterial(value.toString()); + if (Objects.nonNull(material)) { + DOORS.add(material); } } } @@ -56,22 +73,69 @@ public PlotProtectionListener(VirtualRealty plugin) { super(plugin); } + @EventHandler + public void onMobSpawn(CreatureSpawnEvent e) { + if (e.isCancelled()) return; + if (e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) return; + Location location = e.getLocation(); + Plot plot = PlotManager.getPlot(location); + if (plot != null) { + if (!VirtualRealty.getPluginConfiguration().plotMobsSpawn) { + if (e.getEntity() instanceof Monster) { + e.setCancelled(true); + } + } + } + } + + @EventHandler + public void onCropInteract(PlayerInteractEvent e) { + if (e.isCancelled()) return; + Player player = e.getPlayer(); + if (e.getAction() != Action.PHYSICAL) return; + if (e.getClickedBlock() == null) return; + if (e.getClickedBlock().getType() != Material.FARMLAND) return; + Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + if (plot == null) return; + if (hasPermission(player, PLOT_BUILD)) return; + if (plot.hasMembershipAccess(player.getUniqueId())) { + PlotMember plotMember = plot.getMember(player.getUniqueId()); + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + return; + } + if (plotMember == null) return; + if (!plotMember.hasPermission(RegionPermission.BREAK)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG); + } + } else { + if (!plot.hasPermission(RegionPermission.BREAK)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG); + } + } + } + @EventHandler(priority = EventPriority.LOW) public void onBlockInteract(PlayerInteractEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); if (e.getClickedBlock() == null) return; - if (e.getClickedBlock().getType() == Material.CHEST) return; + if (STORAGES.contains(e.getClickedBlock().getType())) return; if (!(e.getAction() == Action.PHYSICAL || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if (player.isSneaking() && e.isBlockInHand()) return; - if (!(INTERACTABLE.contains(e.getClickedBlock().getType()) || SWITCHABLE.contains(e.getClickedBlock().getType()))) return; + if (!(INTERACT.contains(e.getClickedBlock().getType()) || SWITCHES.contains(e.getClickedBlock().getType()) || DOORS.contains(e.getClickedBlock().getType()) || e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE"))) return; if (!VirtualRealty.legacyVersion) { if (e.getHand() == EquipmentSlot.OFF_HAND) return; - if (!e.getClickedBlock().getType().isInteractable()) return; + if (!e.getClickedBlock().getType().isInteractable() && !(e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE"))) return; } Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; + boolean isModernSwitch = !VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch; + boolean isLegacySwitch = SWITCHES.contains(e.getClickedBlock().getType()); if (plot.hasMembershipAccess(player.getUniqueId())) { PlotMember plotMember = plot.getMember(player.getUniqueId()); if (plot.isOwnershipExpired()) { @@ -80,31 +144,49 @@ public void onBlockInteract(PlayerInteractEvent e) { return; } if (plotMember == null) return; - if ((!VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch) || SWITCHABLE.contains(e.getClickedBlock().getType())) { + if (isModernSwitch || isLegacySwitch || e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE")) { if (!plotMember.hasPermission(RegionPermission.SWITCH)) { e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + if (!e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE")) + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); } return; } - if (INTERACTABLE.contains(e.getClickedBlock().getType())) { + if (INTERACT.contains(e.getClickedBlock().getType())) { if (!plotMember.hasPermission(RegionPermission.ITEM_USE)) { e.setCancelled(true); player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + return; + } + } + if (DOORS.contains(e.getClickedBlock().getType())) { + if (!plotMember.hasPermission(RegionPermission.DOORS)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + return; } } } else { - if ((!VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch) || SWITCHABLE.contains(e.getClickedBlock().getType())) { + if (isModernSwitch || isLegacySwitch || e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE")) { if (!plot.hasPermission(RegionPermission.SWITCH)) { e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + if (!e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE")) + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); } return; } - if (INTERACTABLE.contains(e.getClickedBlock().getType())) { + if (INTERACT.contains(e.getClickedBlock().getType())) { if (!plot.hasPermission(RegionPermission.ITEM_USE)) { e.setCancelled(true); player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + return; + } + } + if (DOORS.contains(e.getClickedBlock().getType())) { + if (!plot.hasPermission(RegionPermission.DOORS)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + return; } } } @@ -115,7 +197,7 @@ public void onChestEvent(PlayerInteractEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); if (e.getClickedBlock() == null) return; - if (e.getClickedBlock().getType() != Material.CHEST) return; + if (!STORAGES.contains(e.getClickedBlock().getType())) return; if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (player.isSneaking() && e.isBlockInHand()) return; Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); @@ -141,6 +223,51 @@ public void onChestEvent(PlayerInteractEvent e) { } } + @EventHandler(priority = EventPriority.LOWEST) + public void onPotInteract(PlayerInteractEvent e) { + if (e.isCancelled()) return; + Player player = e.getPlayer(); + if (e.getClickedBlock() == null) return; + if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; + Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + if (plot == null) return; + if (hasPermission(player, PLOT_BUILD)) return; + if (plot.hasMembershipAccess(player.getUniqueId())) { + PlotMember plotMember = plot.getMember(player.getUniqueId()); + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + return; + } + if (plotMember == null) return; + if (e.getClickedBlock().getType().name().startsWith("POTTED_")) { + if (!plotMember.hasPermission(RegionPermission.BREAK)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + if (e.getClickedBlock().getType().name().startsWith("FLOWER_POT")) { + if (!plotMember.hasPermission(RegionPermission.PLACE)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } else { + if (e.getClickedBlock().getType().name().startsWith("POTTED_")) { + if (!plot.hasPermission(RegionPermission.BREAK)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + if (e.getClickedBlock().getType().name().startsWith("FLOWER_POT")) { + if (!plot.hasPermission(RegionPermission.PLACE)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + } + @EventHandler(priority = EventPriority.LOW) public void onLiquidPlace(PlayerBucketEmptyEvent e) { if (e.isCancelled()) return; @@ -467,14 +594,14 @@ public void onItemFrameDamage(HangingBreakByEntityEvent e) { return; } if (plotMember == null) return; - if (!plotMember.hasPermission(RegionPermission.ENTITY_DAMAGE)) { + if (!plotMember.hasPermission(RegionPermission.BREAK)) { e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); } } else { - if (!plot.hasPermission(RegionPermission.ENTITY_DAMAGE)) { + if (!plot.hasPermission(RegionPermission.BREAK)) { e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); } } } @@ -506,11 +633,69 @@ public void onItemFrameRotate(PlayerInteractEntityEvent e) { } } + @EventHandler(priority = EventPriority.LOWEST) + private void onInteract(PlayerInteractEvent e) { + if (e.isCancelled()) return; + Player player = e.getPlayer(); + if (e.getItem() == null) return; + if (e.getItem().getType() != Material.ARMOR_STAND) return; + if (e.getClickedBlock() == null) return; + Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + if (plot == null) return; + if (hasPermission(player, PLOT_BUILD)) return; + if (plot.hasMembershipAccess(player.getUniqueId())) { + PlotMember plotMember = plot.getMember(player.getUniqueId()); + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + return; + } + if (plotMember == null) return; + if (!plotMember.hasPermission(RegionPermission.PLACE)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } else { + if (!plot.hasPermission(RegionPermission.PLACE)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + + @EventHandler(priority = EventPriority.LOW) + public void onHangingPlace(HangingPlaceEvent e) { + if (e.isCancelled()) return; + Player player = e.getPlayer(); + if (player == null) return; + Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + if (plot == null) return; + if (hasPermission(player, PLOT_BUILD)) return; + if (plot.hasMembershipAccess(player.getUniqueId())) { + PlotMember plotMember = plot.getMember(player.getUniqueId()); + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + return; + } + if (plotMember == null) return; + if (!plotMember.hasPermission(RegionPermission.PLACE)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } else { + if (!plot.hasPermission(RegionPermission.PLACE)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } @EventHandler(priority = EventPriority.LOW) public void onEntityDamage(EntityDamageByEntityEvent e) { if (e.isCancelled()) return; if (!(e.getDamager() instanceof Player)) return; + if (!(e.getEntity() instanceof Creature) && !(e.getEntity() instanceof Player)) return; Player player = (Player) e.getDamager(); Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); if (plot == null) return; @@ -535,6 +720,34 @@ public void onEntityDamage(EntityDamageByEntityEvent e) { } } + @EventHandler(priority = EventPriority.LOWEST) + public void onStaticEntityDamage(EntityDamageByEntityEvent e) { + if (e.isCancelled()) return; + if (e.getEntity() instanceof Creature || e.getEntity() instanceof Player) return; + Player player = (Player) e.getDamager(); + Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + if (plot == null) return; + if (hasPermission(player, PLOT_BUILD)) return; + if (plot.hasMembershipAccess(player.getUniqueId())) { + PlotMember plotMember = plot.getMember(player.getUniqueId()); + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + return; + } + if (plotMember == null) return; + if (!plotMember.hasPermission(RegionPermission.BREAK)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } else { + if (!plot.hasPermission(RegionPermission.BREAK)) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + @EventHandler(priority = EventPriority.LOW) public void onEntityExplode(EntityExplodeEvent e) { for (Block block : new ArrayList<>(e.blockList())) { diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java index dfe2480..51ae109 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java @@ -7,7 +7,6 @@ import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.WorldUtil; import org.bukkit.Material; -import org.bukkit.block.BlockFace; import org.bukkit.block.data.type.Switch; import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; @@ -23,7 +22,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.permissions.Permission; -import org.bukkit.util.Vector; public class WorldProtectionListener extends VirtualListener { @@ -41,7 +39,7 @@ public void onBlockInteract(PlayerInteractEvent e) { if (e.getClickedBlock().getType() == Material.CHEST) return; if (!(e.getAction() == Action.PHYSICAL || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if (player.isSneaking() && e.isBlockInHand()) return; - if (!(PlotProtectionListener.INTERACTABLE.contains(e.getClickedBlock().getType()) || PlotProtectionListener.SWITCHABLE.contains(e.getClickedBlock().getType()))) + if (!(PlotProtectionListener.INTERACT.contains(e.getClickedBlock().getType()) || PlotProtectionListener.SWITCHES.contains(e.getClickedBlock().getType()))) return; if (!VirtualRealty.legacyVersion) { if (e.getHand() == EquipmentSlot.OFF_HAND) return; @@ -51,7 +49,7 @@ public void onBlockInteract(PlayerInteractEvent e) { if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; try { - if ((!VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch) || PlotProtectionListener.SWITCHABLE.contains(e.getClickedBlock().getType())) { + if ((!VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch) || PlotProtectionListener.SWITCHES.contains(e.getClickedBlock().getType())) { Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", false, VirtualRealty.getLoader()); if (!WorldUtil.hasPermission(RegionPermission.SWITCH)) { e.setCancelled(true); @@ -59,7 +57,7 @@ public void onBlockInteract(PlayerInteractEvent e) { } return; } - if (PlotProtectionListener.INTERACTABLE.contains(e.getClickedBlock().getType())) { + if (PlotProtectionListener.INTERACT.contains(e.getClickedBlock().getType())) { Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", false, VirtualRealty.getLoader()); if (!WorldUtil.hasPermission(RegionPermission.ITEM_USE)) { e.setCancelled(true); diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java index 6467ad5..5bc294c 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java @@ -51,7 +51,7 @@ public class Plot { private Material floorMaterial, borderMaterial; private byte floorData, borderData; private final Location createdLocation; - private final Direction createdDirection; + private Direction createdDirection; private BlockVector3 bottomLeftCorner, topRightCorner, borderBottomLeftCorner, borderTopRightCorner; private GameMode selectedGameMode; private final String createdWorld; @@ -67,19 +67,17 @@ public Plot(Location location, Material floorMaterial, Material borderMaterial, this.ownedUntilDate = MAX_DATE; if (natural) { this.floorMaterial = Material.AIR; - this.floorData = 0; this.borderMaterial = Material.AIR; - this.borderData = 0; } else { this.floorMaterial = floorMaterial; - this.floorData = 0; this.borderMaterial = borderMaterial; - this.borderData = 0; } + this.floorData = 0; + this.borderData = 0; this.createdLocation = location; this.createdDirection = Direction.byYaw(location.getYaw()); this.selectedGameMode = VirtualRealty.getPluginConfiguration().getDefaultPlotGamemode(); - this.createdWorld = location.getWorld().getName(); + this.createdWorld = Objects.requireNonNull(location.getWorld()).getName(); this.modified = Instant.now(); this.createdAt = LocalDateTime.now(); this.plotSize = plotSize; @@ -128,7 +126,9 @@ public Plot(ResultSet rs) { ArrayList location = new ArrayList<>(Arrays.asList(rs.getString("createdLocation").subSequence(0, rs.getString("createdLocation").length() - 1).toString().split(";"))); Location createLocation = new Location(Bukkit.getWorld(location.get(0)), Double.parseDouble(location.get(1)), Double.parseDouble(location.get(2)), Double.parseDouble(location.get(3)), Float.parseFloat(location.get(4)), Float.parseFloat(location.get(5))); this.createdLocation = rs.getString("createdLocation").isEmpty() ? null : createLocation; - this.createdDirection = Direction.byYaw(createdLocation.getYaw()); + if (this.createdLocation != null) { + this.createdDirection = Direction.byYaw(createdLocation.getYaw()); + } if (!rs.getString("selectedGameMode").isEmpty() && EnumUtils.isValidEnum(GameMode.class, rs.getString("selectedGameMode"))) { this.selectedGameMode = GameMode.valueOf(rs.getString("selectedGameMode")); } else { @@ -157,17 +157,16 @@ public String getBorderMaterialName() { } public void teleportPlayer(Player player) { - Location loc = new Location(createdLocation.getWorld(), getCenter().getBlockX(), getCenter().getBlockY() + 1, getCenter().getBlockZ()); - if (!createdLocation.getWorld().getName().endsWith("_nether")) { - loc.setY(Objects.requireNonNull(loc.getWorld()).getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY() + 1); + Location location = new Location(createdLocation.getWorld(), getCenter().getBlockX(), getCenter().getBlockY() + 1, getCenter().getBlockZ()); + if (!Objects.requireNonNull(createdLocation.getWorld()).getName().endsWith("_nether")) { + location.setY(Objects.requireNonNull(location.getWorld()).getHighestBlockAt(location.getBlockX(), location.getBlockZ()).getY() + 1); } - player.teleport(loc); + player.teleport(location); } public boolean hasMembershipAccess(UUID uuid) { PlotMember member = getMember(uuid); - if (member != null || (ownedBy != null && getPlotOwner().getUniqueId() == uuid)) return true; - return false; + return member != null || (ownedBy != null && getPlotOwner().getUniqueId() == uuid); } public void togglePermission(RegionPermission plotPermission) { @@ -193,9 +192,7 @@ public void removePermission(RegionPermission plotPermission) { public PlotMember getMember(UUID uuid) { for (PlotMember member : members) { - if (member.getUuid().equals(uuid)) { - return member; - } + if (member.getUuid().equals(uuid)) return member; } return null; } @@ -289,10 +286,6 @@ public void setBorderMaterial(Material borderMaterial, byte data) { } } - public BlockVector3 getBorderedCenter() { - return new Cuboid(borderBottomLeftCorner, borderTopRightCorner, createdLocation.getWorld()).getCenterVector(); - } - public BlockVector3 getCenter() { return new Cuboid(bottomLeftCorner, topRightCorner, createdLocation.getWorld()).getCenterVector(); } @@ -417,7 +410,7 @@ public Set getBorderBlocks() { for (int x = minX - 1; x < maxX; x++) { for (int z = minZ; z < maxZ; z++) { if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - blocks.add(location.getWorld().getBlockAt(x, location.getBlockY() + 1, z)); + blocks.add(Objects.requireNonNull(location.getWorld()).getBlockAt(x, location.getBlockY() + 1, z)); } } } @@ -505,7 +498,7 @@ public void prepareBlocks(Location location, boolean natural) { if (natural) return; for (Block floorBlock : getFloorBlocks()) { for (int y = location.getBlockY() + height; y > location.getBlockY() - 1; y--) { - Block airBlock = location.getWorld().getBlockAt(floorBlock.getX(), y, floorBlock.getZ()); + Block airBlock = Objects.requireNonNull(location.getWorld()).getBlockAt(floorBlock.getX(), y, floorBlock.getZ()); airBlock.setType(Material.AIR, false); } floorBlock.setType(floorMaterial); @@ -556,7 +549,7 @@ public void prepareBlocks(Location location, boolean natural) { for (int x = minX - 1; x < maxX; x++) { for (int z = minZ; z < maxZ; z++) { if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); + Block borderBlock = Objects.requireNonNull(location.getWorld()).getBlockAt(x, location.getBlockY() + 1, z); if (VirtualRealty.legacyVersion) { borderBlock.setType(plotSize.getBorderMaterial()); try { @@ -612,7 +605,7 @@ private void modified() { @SneakyThrows public void insert() { String serializedLocation = - this.createdLocation.getWorld().getName() + ";" + + Objects.requireNonNull(this.createdLocation.getWorld()).getName() + ";" + this.createdLocation.getX() + ";" + this.createdLocation.getY() + ";" + this.createdLocation.getZ() + ";" + diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java b/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java index e5c55ff..ac29980 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java @@ -16,8 +16,6 @@ import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.util.NumberConversions; -import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java b/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java index 35fdf50..e4c0bbb 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java @@ -6,15 +6,10 @@ import com.modnmetl.virtualrealty.utils.loader.CustomClassLoader; import lombok.SneakyThrows; import org.apache.commons.io.FileUtils; +import sun.net.www.protocol.ftp.FtpURLConnection; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.URL; +import java.io.*; +import java.net.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; @@ -32,14 +27,27 @@ public Loader(String licenseKey, String licenseEmail, String pluginVersion, Clas private void runLoader(String licenseKey, String licenseEmail, String pluginVersion, ClassLoader classLoader, boolean debug) throws IOException { VirtualRealty.debug("Injecting premium.."); URL url; - HttpURLConnection httpConn; + URLConnection httpConn; if (debug) { - url = new URL("http://localhost/virtualrealty/premium" + "?license=" + licenseKey + "&email=" + licenseEmail + "&version=" + pluginVersion); - httpConn = (HttpURLConnection) url.openConnection(); + String premiumPath = VirtualRealty.getInstance().getDataFolder().getAbsolutePath() + File.separator + "data" + File.separator + "virtualrealty-premium-" + VirtualRealty.getInstance().getDescription().getVersion() + ".jar"; + url = new URL("file:/" + premiumPath); + System.out.println(url); + File originFile = new File(premiumPath); + InputStream targetStream = new FileInputStream(originFile); + File loaderFile = File.createTempFile(String.valueOf(Arrays.asList(new Random().nextInt(9), new Random().nextInt(9), new Random().nextInt(9))), ".tmp"); + VirtualRealty.setLoaderFile(loaderFile); + FileUtils.deleteQuietly(loaderFile); + Files.copy(targetStream, Paths.get(loaderFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); + targetStream.close(); + VirtualRealty.getInstance().jarFiles.add(new JarFile(loaderFile)); + URL jarUrl = loaderFile.toURI().toURL(); + VirtualRealty.getInstance().setClassLoader(new CustomClassLoader( + new URL[]{jarUrl}, classLoader) + ); } else { url = new URL("https://api.modnmetl.com/auth/key"); - httpConn = (HttpURLConnection) url.openConnection(); - httpConn.setRequestMethod("POST"); + httpConn = url.openConnection(); + ((HttpURLConnection)httpConn).setRequestMethod("POST"); httpConn.setDoOutput(true); httpConn.setRequestProperty("Content-Type", "application/json"); @@ -54,26 +62,27 @@ private void runLoader(String licenseKey, String licenseEmail, String pluginVers byte[] out = data.getBytes(StandardCharsets.UTF_8); OutputStream stream = httpConn.getOutputStream(); stream.write(out); - } + int responseCode = ((HttpURLConnection) httpConn).getResponseCode(); + if (responseCode != HttpURLConnection.HTTP_OK) { + VirtualRealty.debug("Authentication error | " + ((HttpURLConnection) httpConn).getResponseCode() + " " + ((HttpURLConnection) httpConn).getResponseMessage()); + return; + } - int responseCode = httpConn.getResponseCode(); - if (responseCode != HttpURLConnection.HTTP_OK) { - VirtualRealty.debug("Authentication error | " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); - return; - } - File loaderFile; - try (InputStream in = httpConn.getInputStream()) { - loaderFile = File.createTempFile(String.valueOf(Arrays.asList(new Random().nextInt(9), new Random().nextInt(9), new Random().nextInt(9))), ".tmp"); - VirtualRealty.setLoaderFile(loaderFile); - FileUtils.deleteQuietly(loaderFile); - Files.copy(in, Paths.get(loaderFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); - VirtualRealty.getInstance().jarFiles.add(new JarFile(loaderFile)); + File loaderFile; + try (InputStream in = httpConn.getInputStream()) { + loaderFile = File.createTempFile(String.valueOf(Arrays.asList(new Random().nextInt(9), new Random().nextInt(9), new Random().nextInt(9))), ".tmp"); + VirtualRealty.setLoaderFile(loaderFile); + FileUtils.deleteQuietly(loaderFile); + Files.copy(in, Paths.get(loaderFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); + VirtualRealty.getInstance().jarFiles.add(new JarFile(loaderFile)); + } + ((HttpURLConnection) httpConn).disconnect(); + URL jarUrl = loaderFile.toURI().toURL(); + System.out.println(jarUrl); + VirtualRealty.getInstance().setClassLoader(new CustomClassLoader( + new URL[]{jarUrl}, classLoader) + ); } - httpConn.disconnect(); - URL jarUrl = loaderFile.toURI().toURL(); - VirtualRealty.getInstance().setClassLoader(new CustomClassLoader( - new URL[]{ jarUrl }, classLoader) - ); try { Class clazz = Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getLoader()); VirtualRealty.setPremium(clazz.newInstance()); diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java b/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java index 9bfbe20..bf5643a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java @@ -14,4 +14,4 @@ public static double distanceSquared(BlockVector2 vector, BlockVector2 vector2) NumberConversions.square(vector.getBlockZ() - vector2.getBlockZ()); } -} +} \ No newline at end of file diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java index 8bd4868..df452d1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java @@ -5,7 +5,6 @@ import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; import lombok.SneakyThrows; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang.SerializationUtils; import org.bukkit.Bukkit; import org.bukkit.Location; From 41c021dd239d86182929ef2cec947c2de5101489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Mon, 23 May 2022 17:59:05 +0200 Subject: [PATCH 2/2] plot protection fixes --- .../com/modnmetl/virtualrealty/configs/PluginConfiguration.java | 2 +- .../listeners/protection/PlotProtectionListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java index 8fa7b0f..955b7e9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java @@ -48,7 +48,7 @@ public static class License extends OkaeriConfig { public String plotGamemode = "SURVIVAL"; @Comment("Disable natural spawning of hostile mobs in plots/areas") - public boolean plotMobsSpawn = true; + public boolean disablePlotMobsSpawn = false; @Comment("Lock gamemode to plot default when player enters their plot (disables '/plot gm' command)") public boolean lockPlotGamemode = false; diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java index 9fef9b6..549890c 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java @@ -80,7 +80,7 @@ public void onMobSpawn(CreatureSpawnEvent e) { Location location = e.getLocation(); Plot plot = PlotManager.getPlot(location); if (plot != null) { - if (!VirtualRealty.getPluginConfiguration().plotMobsSpawn) { + if (VirtualRealty.getPluginConfiguration().disablePlotMobsSpawn) { if (e.getEntity() instanceof Monster) { e.setCancelled(true); }