From e14828dbc97ad42489a02ddea8bbedd96756e19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Mon, 24 Oct 2022 21:22:28 +0200 Subject: [PATCH 01/10] v2.5.0 --- pom.xml | 2 +- .../modnmetl/virtualrealty/VirtualRealty.java | 5 +- .../virtualrealty/commands/SubCommand.java | 13 - .../plot/subcommand/DraftSubCommand.java | 99 +----- .../plot/subcommand/StakeSubCommand.java | 171 --------- .../configs/MessagesConfiguration.java | 21 +- .../player/PlayerActionListener.java | 334 +++++++++++++++++- .../protection/PlotProtectionListener.java | 9 +- .../listeners/stake/DraftListener.java | 5 +- .../managers/ConfirmationManager.java | 4 + .../virtualrealty/managers/PlotManager.java | 21 +- .../managers/PlotMemberManager.java | 21 -- .../modnmetl/virtualrealty/objects/Plot.java | 97 +++-- .../objects/data/PlotMember.java | 59 +++- .../modnmetl/virtualrealty/sql/Database.java | 77 ++-- 15 files changed, 510 insertions(+), 428 deletions(-) delete mode 100644 src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java diff --git a/pom.xml b/pom.xml index 3c76670..7af17b8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.modnmetl virtualrealty - 2.4.0 + 2.5.0 jar A plot creation and management plugin for Minecraft diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index a282938..8be4b41 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -19,7 +19,6 @@ import com.modnmetl.virtualrealty.managers.DynmapManager; import com.modnmetl.virtualrealty.managers.MetricsManager; import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.managers.PlotMemberManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.registry.VirtualPlaceholders; import com.modnmetl.virtualrealty.sql.Database; @@ -30,12 +29,10 @@ import com.zaxxer.hikari.HikariDataSource; import lombok.Getter; import lombok.Setter; -import net.minecraft.server.v1_13_R2.MinecraftServer; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.PluginCommand; -import org.bukkit.craftbukkit.v1_13_R2.CraftServer; import org.bukkit.permissions.Permission; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; @@ -161,7 +158,7 @@ public void onEnable() { return; } PlotManager.loadPlots(); - PlotMemberManager.loadMembers(); + PlotManager.loadMembers(); if (pluginConfiguration.dynmapMarkers) { dynmapManager = new DynmapManager(this); dynmapManager.registerDynmap(); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java index c5493ff..a1d71ff 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java @@ -115,19 +115,6 @@ public void assertPermission(String permission) throws InsufficientPermissionsEx } } - public boolean canCreateInWorld(Player player) { - switch (WorldsSetting.valueOf(VirtualRealty.getPluginConfiguration().worldsSetting.toUpperCase())) { - case ALL: - break; - case INCLUDED: - if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().noneMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false; - break; - case EXCLUDED: - if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().anyMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false; - } - return true; - } - public boolean isBypass() { return this.bypass; } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java index 57d4667..feb9272 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java @@ -38,104 +38,7 @@ public DraftSubCommand(CommandSender sender, Command command, String label, Stri public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { assertPlayer(); Player player = ((Player) sender); - if (DraftListener.DRAFT_MAP.containsKey(player)) { - player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack()); - player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack()); - DraftListener.DRAFT_MAP.get(player).getKey().removeGrid(); - DraftListener.DRAFT_MAP.remove(player); - ConfirmationManager.removeStakeConfirmations(ConfirmationType.STAKE, player.getUniqueId()); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeDisabled); - return; - } - PlayerInventory inv; - ItemStack claimItem; - if (VirtualRealty.legacyVersion) { - inv = player.getInventory(); - claimItem = player.getItemInHand(); - } else { - inv = player.getInventory(); - claimItem = inv.getItemInMainHand(); - } - NBTItem claimNbtItem; - if (!(claimItem.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) - && - (claimNbtItem = new NBTItem(claimItem)).getString("vrplot_item") != null && claimNbtItem.getString("vrplot_item").equals("CLAIM"))) { - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notHoldingPlotClaim); - return; - } - PlotItem plotItem = PlotItem.fromItemStack(claimItem); - Plot plot = PlotManager.getPlot(player.getLocation()); - String replacement = null; - if (plot == null) { - if (!canCreateInWorld(player)) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); - return; - } - replacement = VirtualRealty.getMessages().createFeature; - } else { - if (plotItem.getPlotSize().equals(plot.getPlotSize())) { - if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { - replacement = VirtualRealty.getMessages().claimFeature; - } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { - replacement = VirtualRealty.getMessages().extendFeature; - } - } else { - if (!canCreateInWorld(player)) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); - return; - } - replacement = VirtualRealty.getMessages().createFeature; - } - } - String finalReplacement = replacement; - if (plot != null && plotItem.getPlotSize().equals(plot.getPlotSize()) && plot.getPlotSize() != PlotSize.CUSTOM) { - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot); - GridStructure previewStructure = new GridStructure(((Player) sender), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 0, plot.getCreatedLocation()); - previewStructure.preview(player.getLocation(), true, false); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed); - PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); - DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(previewStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem))); - inv.remove(claimItem); - if (VirtualRealty.legacyVersion) { - player.setItemInHand(draftItem.getItemStack()); - } else { - inv.setItemInMainHand(draftItem.getItemStack()); - } - VirtualRealty.getMessages().draftEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") - .replaceAll("%feature%", finalReplacement) - )); - return; - } - PlotSize plotSize = PlotSize.valueOf(claimNbtItem.getString("vrplot_size")); - Cuboid cuboid = RegionUtil.getRegion(player.getLocation(), Direction.byYaw(player.getLocation().getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth()); - if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision); - if (!GridStructure.isCuboidGridDisplaying(player, 0)) { - new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, ((Player) sender).getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true); - } - return; - } - if (RegionUtil.isCollidingWithBedrock(cuboid)) { - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledBedrock); - GridStructure.isCuboidGridDisplaying(player, 0); - if (!GridStructure.isCuboidGridDisplaying(player, 0)) { - new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, ((Player) sender).getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true); - } - return; - } - PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); - GridStructure draftStructure = new GridStructure(player, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), 0, ((Player) sender).getWorld(), 0, player.getLocation()); - DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(draftStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem))); - inv.remove(claimItem); - if (VirtualRealty.legacyVersion) { - player.setItemInHand(draftItem.getItemStack()); - } else { - inv.setItemInMainHand(draftItem.getItemStack()); - } - draftStructure.preview(player.getLocation(), true, false); - VirtualRealty.getMessages().draftEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") - .replaceAll("%feature%", finalReplacement) - )); + } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java index 6aebde8..d596a26 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java @@ -44,178 +44,7 @@ public StakeSubCommand(CommandSender sender, Command command, String label, Stri public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { assertPlayer(); Player player = ((Player) sender); - if (!DraftListener.DRAFT_MAP.containsKey(player)) { - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noDraftClaimEnabled); - return; - } - GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey(); - PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey(); - Cuboid cuboid = RegionUtil.getRegion(gridStructure.getPreviewLocation(), Direction.byYaw(gridStructure.getPreviewLocation().getYaw()), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth()); - Plot plot = PlotManager.getPlot(gridStructure.getPreviewLocation()); - if (plot != null) { - if (plotItem.getPlotSize().equals(plot.getPlotSize())) { - if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { - for (String s : VirtualRealty.getMessages().claimConfirmation) { - player.sendMessage(VirtualRealty.PREFIX + s); - } - Confirmation confirmation = new Confirmation(ConfirmationType.CLAIM, (Player) sender, "YES") { - @Override - public void success() { - ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); - this.getSender().getInventory().remove(plotItemStack); - plot.setOwnedBy(this.getSender().getUniqueId()); - plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); - gridStructure.removeGrid(); - DraftListener.DRAFT_MAP.remove(this.getSender()); - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - plot.update(); - this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().plotClaimed); - } - @Override - public void failed() { - this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); - this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); - this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); - DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); - DraftListener.DRAFT_MAP.remove(this.getSender()); - this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); - DraftListener.DRAFT_MAP.remove(this.getSender()); - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - } - - @Override - public void expiry() { - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - } - }; - ConfirmationManager.confirmations.add(confirmation); - return; - } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { - for (String s : VirtualRealty.getMessages().extendConfirmation) { - player.sendMessage(VirtualRealty.PREFIX + s); - } - Confirmation confirmation = new Confirmation(ConfirmationType.EXTEND, (Player) sender, "YES") { - @Override - public void success() { - PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey(); - ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); - this.getSender().getInventory().remove(plotItemStack); - if (plot.isOwnershipExpired()) - plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); - else - plot.setOwnedUntilDate(plot.getOwnedUntilDate().plusDays(plotItem.getAdditionalDays())); - gridStructure.removeGrid(); - DraftListener.DRAFT_MAP.remove(this.getSender()); - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - plot.update(); - this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().leaseExtended.replaceAll("%plot_id%", String.valueOf(plot.getID())).replaceAll("%date%", Plot.SHORT_PLOT_DATE_FORMAT.format(plot.getOwnedUntilDate()))); - } - - @Override - public void failed() { - this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); - this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); - this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); - DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); - DraftListener.DRAFT_MAP.remove(this.getSender()); - this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); - DraftListener.DRAFT_MAP.remove(this.getSender()); - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - } - - @Override - public void expiry() { - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - } - }; - ConfirmationManager.confirmations.add(confirmation); - return; - } - } - } - if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { - player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack()); - player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack()); - DraftListener.DRAFT_MAP.get(player).getKey().removeGrid(); - DraftListener.DRAFT_MAP.remove(player); - gridStructure.removeGrid(); - gridStructure.setDisplayTicks(20L * 6); - gridStructure.preview(true, true); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision); - return; - } - for (String s : VirtualRealty.getMessages().stakeConfirmation) { - sender.sendMessage(VirtualRealty.PREFIX + s); - } - Confirmation confirmation = new Confirmation(ConfirmationType.STAKE, (Player) sender, "YES") { - @Override - public void success() { - GridStructure gridStructure = DraftListener.DRAFT_MAP.get(this.getSender()).getKey(); - PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey(); - PlotSize plotSize = plotItem.getPlotSize(); - ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); - NBTItem item = new NBTItem(plotItemStack); - gridStructure.removeGrid(); - this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); - long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.isNatural()); - AbstractMap.SimpleEntry floorData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_floor_material"), item.getByte("vrplot_floor_data")); - AbstractMap.SimpleEntry borderData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_border_material"), item.getByte("vrplot_border_data")); - if (!plotItem.isNatural()) { - if (VirtualRealty.legacyVersion) { - plot.setFloorMaterial(Material.valueOf(floorData.getKey()), floorData.getValue()); - plot.setBorderMaterial(Material.valueOf(borderData.getKey()), borderData.getValue()); - } else { - plot.setFloorMaterial(Bukkit.createBlockData(floorData.getKey()).getMaterial(), floorData.getValue()); - plot.setBorderMaterial(Bukkit.createBlockData(borderData.getKey()).getMaterial(), borderData.getValue()); - } - } - plot.setOwnedBy(this.getSender().getUniqueId()); - if (plotItem.getAdditionalDays() == 0) { - plot.setOwnedUntilDate(Plot.MAX_DATE); - } else { - plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); - } - this.getSender().getInventory().remove(plotItemStack); - long timeEnd = System.currentTimeMillis(); - BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); - BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); - BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart))); - textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))})); - textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); - textComponent.addExtra(textComponent2); - textComponent.addExtra(textComponent3); - new Chat(textComponent).sendTo(this.getSender()); - new BukkitRunnable() { - @Override - public void run() { - gridStructure.setCuboidId(plot.getID()); - gridStructure.setDisplayTicks(20 * 6); - gridStructure.preview(true, false); - } - }.runTaskLater(VirtualRealty.getInstance(), 20); - DraftListener.DRAFT_MAP.remove(this.getSender()); - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - plot.update(); - } - @Override - public void failed() { - this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); - this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); - this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); - DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); - DraftListener.DRAFT_MAP.remove(this.getSender()); - this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); - DraftListener.DRAFT_MAP.remove(this.getSender()); - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - } - @Override - public void expiry() { - ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); - } - }; - ConfirmationManager.confirmations.add(confirmation); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java index cc2f741..c484c48 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java @@ -96,20 +96,19 @@ public class MessagesConfiguration extends OkaeriConfig { public String enteredProtectedArea = "§6You have entered a protected area!"; public String leftProtectedArea = "§6You have left a protected area!"; - //Draft + //Claim Mode public String notHoldingPlotClaim = "§cYou currently don't hold any plot claim item in your hand."; - public String cantPlaceDraftItems = "§cYou can't place draft items."; - public String noDraftClaimEnabled = "§cYou don't have plot draft claim enabled."; - public String draftModeDisabled = "§aDraft mode successfully disabled!"; - public String draftModeCancelledBedrock = "§cDraft cancelled. Colliding with bedrock."; - public String draftModeCancelledCollision = "§cDraft cancelled. Colliding with another plot."; - public String draftModeDisabledDueToDeath = "§cDraft mode has been disabled due to death."; - public List draftEnabled = Arrays.asList( + public String cantPlaceClaimItems = "§cYou can't place claim items."; + public String claimModeDisabled = "§aClaim mode successfully disabled!"; + public String claimModeCancelledBedrock = "§cClaim cancelled. Colliding with bedrock."; + public String claimModeCancelledCollision = "§cClaim cancelled. Colliding with another plot."; + public String claimModeDisabledDueToDeath = "§cClaim mode has been disabled due to death."; + public List claimEnabled = Arrays.asList( " ", - " §8§l«§8§m §8[§aDraft Mode§8]§m §8§l»", + " §8§l«§8§m §8[§aClaim Mode§8]§m §8§l»", " ", - " §8§l» §7Type §a/plot stake §7to %feature%.", - " §8§l» §7If you want to leave draft mode type §a/plot draft", + " §8§l» §aLeft-Click §7to %feature%.", + " §8§l» §7If you want to leave claim mode §cRight-Click.", " " ); diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java index f0445e2..5b86a64 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java @@ -1,16 +1,41 @@ package com.modnmetl.virtualrealty.listeners.player; import com.modnmetl.virtualrealty.VirtualRealty; +import com.modnmetl.virtualrealty.enums.ConfirmationType; +import com.modnmetl.virtualrealty.enums.Direction; +import com.modnmetl.virtualrealty.enums.PlotSize; +import com.modnmetl.virtualrealty.enums.WorldsSetting; +import com.modnmetl.virtualrealty.enums.items.VItem; import com.modnmetl.virtualrealty.listeners.VirtualListener; +import com.modnmetl.virtualrealty.listeners.stake.DraftListener; +import com.modnmetl.virtualrealty.managers.ConfirmationManager; +import com.modnmetl.virtualrealty.managers.PlotManager; +import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.objects.data.Confirmation; +import com.modnmetl.virtualrealty.objects.data.PlotItem; +import com.modnmetl.virtualrealty.objects.region.Cuboid; +import com.modnmetl.virtualrealty.objects.region.GridStructure; +import com.modnmetl.virtualrealty.utils.RegionUtil; +import com.modnmetl.virtualrealty.utils.multiversion.Chat; +import de.tr7zw.nbtapi.NBTItem; +import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.scheduler.BukkitRunnable; +import java.time.LocalDateTime; +import java.util.AbstractMap; + public class PlayerActionListener extends VirtualListener { public PlayerActionListener(VirtualRealty plugin) { @@ -34,4 +59,311 @@ public void run() { }.runTaskLater(VirtualRealty.getInstance(), 5); } + + @EventHandler + public void onPlotItemStake(PlayerInteractEvent e) { + Player player = e.getPlayer(); + if (!player.isOp()) return; + if (!(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) return; + if (!DraftListener.DRAFT_MAP.containsKey(player)) return; + GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey(); + PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey(); + Cuboid cuboid = RegionUtil.getRegion(gridStructure.getPreviewLocation(), Direction.byYaw(gridStructure.getPreviewLocation().getYaw()), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth()); + Plot plot = PlotManager.getPlot(gridStructure.getPreviewLocation()); + if (plot != null) { + if (plotItem.getPlotSize().equals(plot.getPlotSize())) { + if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { + if (ConfirmationManager.doesConfirmationExist(ConfirmationType.CLAIM, player.getUniqueId())) { + player.sendMessage(VirtualRealty.PREFIX + "§cYou already have a confirmation to confirm!"); + return; + } + for (String s : VirtualRealty.getMessages().claimConfirmation) { + player.sendMessage(VirtualRealty.PREFIX + s); + } + Confirmation confirmation = new Confirmation(ConfirmationType.CLAIM, player, "YES") { + @Override + public void success() { + ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); + this.getSender().getInventory().remove(plotItemStack); + plot.setOwnedBy(this.getSender().getUniqueId()); + plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); + gridStructure.removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + plot.update(); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().plotClaimed); + } + + @Override + public void failed() { + this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); + DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + + @Override + public void expiry() { + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + }; + ConfirmationManager.confirmations.add(confirmation); + return; + } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { + if (ConfirmationManager.doesConfirmationExist(ConfirmationType.EXTEND, player.getUniqueId())) { + player.sendMessage(VirtualRealty.PREFIX + "§cYou already have a confirmation to confirm!"); + return; + } + for (String s : VirtualRealty.getMessages().extendConfirmation) { + player.sendMessage(VirtualRealty.PREFIX + s); + } + Confirmation confirmation = new Confirmation(ConfirmationType.EXTEND, player, "YES") { + @Override + public void success() { + PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey(); + ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); + this.getSender().getInventory().remove(plotItemStack); + if (plot.isOwnershipExpired()) + plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); + else + plot.setOwnedUntilDate(plot.getOwnedUntilDate().plusDays(plotItem.getAdditionalDays())); + gridStructure.removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + plot.update(); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().leaseExtended.replaceAll("%plot_id%", String.valueOf(plot.getID())).replaceAll("%date%", Plot.SHORT_PLOT_DATE_FORMAT.format(plot.getOwnedUntilDate()))); + } + + @Override + public void failed() { + this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); + DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + + @Override + public void expiry() { + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + }; + ConfirmationManager.confirmations.add(confirmation); + return; + } + } + } + if (ConfirmationManager.doesConfirmationExist(ConfirmationType.STAKE, player.getUniqueId())) { + player.sendMessage(VirtualRealty.PREFIX + "§cYou already have a confirmation to confirm!"); + return; + } + if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { + player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack()); + player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack()); + DraftListener.DRAFT_MAP.get(player).getKey().removeGrid(); + DraftListener.DRAFT_MAP.remove(player); + gridStructure.removeGrid(); + gridStructure.setDisplayTicks(20L * 6); + gridStructure.preview(true, true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledCollision); + return; + } + for (String s : VirtualRealty.getMessages().stakeConfirmation) { + player.sendMessage(VirtualRealty.PREFIX + s); + } + Confirmation confirmation = new Confirmation(ConfirmationType.STAKE, player, "YES") { + @Override + public void success() { + GridStructure gridStructure = DraftListener.DRAFT_MAP.get(this.getSender()).getKey(); + PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey(); + PlotSize plotSize = plotItem.getPlotSize(); + ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); + NBTItem item = new NBTItem(plotItemStack); + gridStructure.removeGrid(); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); + long timeStart = System.currentTimeMillis(); + Plot plot = PlotManager.createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.isNatural()); + AbstractMap.SimpleEntry floorData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_floor_material"), item.getByte("vrplot_floor_data")); + AbstractMap.SimpleEntry borderData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_border_material"), item.getByte("vrplot_border_data")); + if (!plotItem.isNatural()) { + if (VirtualRealty.legacyVersion) { + plot.setFloorMaterial(Material.valueOf(floorData.getKey()), floorData.getValue()); + plot.setBorderMaterial(Material.valueOf(borderData.getKey()), borderData.getValue()); + } else { + plot.setFloorMaterial(Bukkit.createBlockData(floorData.getKey()).getMaterial(), floorData.getValue()); + plot.setBorderMaterial(Bukkit.createBlockData(borderData.getKey()).getMaterial(), borderData.getValue()); + } + } + plot.setOwnedBy(this.getSender().getUniqueId()); + if (plotItem.getAdditionalDays() == 0) { + plot.setOwnedUntilDate(Plot.MAX_DATE); + } else { + plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); + } + this.getSender().getInventory().remove(plotItemStack); + long timeEnd = System.currentTimeMillis(); + BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); + BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); + BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart))); + textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))})); + textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); + textComponent.addExtra(textComponent2); + textComponent.addExtra(textComponent3); + new Chat(textComponent).sendTo(this.getSender()); + new BukkitRunnable() { + @Override + public void run() { + gridStructure.setCuboidId(plot.getID()); + gridStructure.setDisplayTicks(20 * 6); + gridStructure.preview(true, false); + } + }.runTaskLater(VirtualRealty.getInstance(), 20); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + plot.update(); + } + @Override + public void failed() { + this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); + DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + @Override + public void expiry() { + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + }; + ConfirmationManager.confirmations.add(confirmation); + } + + @EventHandler + public void onPlotItemDraft(PlayerInteractEvent e) { + Player player = e.getPlayer(); + if (!player.isOp()) return; + if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; + if (DraftListener.DRAFT_MAP.containsKey(player)) { + player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack()); + player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack()); + DraftListener.DRAFT_MAP.get(player).getKey().removeGrid(); + DraftListener.DRAFT_MAP.remove(player); + ConfirmationManager.removeStakeConfirmations(ConfirmationType.STAKE, player.getUniqueId()); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeDisabled); + return; + } + PlayerInventory inv; + ItemStack claimItem; + if (VirtualRealty.legacyVersion) { + inv = player.getInventory(); + claimItem = player.getItemInHand(); + } else { + inv = player.getInventory(); + claimItem = inv.getItemInMainHand(); + } + NBTItem claimNbtItem; + if (!(claimItem.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) + && + (claimNbtItem = new NBTItem(claimItem)).getString("vrplot_item") != null && claimNbtItem.getString("vrplot_item").equals("CLAIM"))) { + //player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notHoldingPlotClaim); + return; + } + PlotItem plotItem = PlotItem.fromItemStack(claimItem); + Plot plot = PlotManager.getPlot(player.getLocation()); + String replacement = null; + if (plot == null) { + if (!canCreateInWorld(player)) { + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); + return; + } + replacement = VirtualRealty.getMessages().createFeature; + } else { + if (plotItem.getPlotSize().equals(plot.getPlotSize())) { + if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { + replacement = VirtualRealty.getMessages().claimFeature; + } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { + replacement = VirtualRealty.getMessages().extendFeature; + } + } else { + if (!canCreateInWorld(player)) { + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); + return; + } + replacement = VirtualRealty.getMessages().createFeature; + } + } + String finalReplacement = replacement; + if (plot != null && plotItem.getPlotSize().equals(plot.getPlotSize()) && plot.getPlotSize() != PlotSize.CUSTOM) { + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot); + GridStructure previewStructure = new GridStructure((player), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), player.getWorld(), 0, plot.getCreatedLocation()); + previewStructure.preview(player.getLocation(), true, false); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed); + PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); + DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(previewStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem))); + inv.remove(claimItem); + if (VirtualRealty.legacyVersion) { + player.setItemInHand(draftItem.getItemStack()); + } else { + inv.setItemInMainHand(draftItem.getItemStack()); + } + VirtualRealty.getMessages().claimEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") + .replaceAll("%feature%", finalReplacement) + )); + return; + } + PlotSize plotSize = PlotSize.valueOf(claimNbtItem.getString("vrplot_size")); + Cuboid cuboid = RegionUtil.getRegion(player.getLocation(), Direction.byYaw(player.getLocation().getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth()); + if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledCollision); + if (!GridStructure.isCuboidGridDisplaying(player, 0)) { + new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, player.getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true); + } + return; + } + if (RegionUtil.isCollidingWithBedrock(cuboid)) { + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledBedrock); + GridStructure.isCuboidGridDisplaying(player, 0); + if (!GridStructure.isCuboidGridDisplaying(player, 0)) { + new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, player.getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true); + } + return; + } + PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); + GridStructure draftStructure = new GridStructure(player, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), 0, player.getWorld(), 0, player.getLocation()); + DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(draftStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem))); + inv.remove(claimItem); + if (VirtualRealty.legacyVersion) { + player.setItemInHand(draftItem.getItemStack()); + } else { + inv.setItemInMainHand(draftItem.getItemStack()); + } + draftStructure.preview(player.getLocation(), true, false); + VirtualRealty.getMessages().claimEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") + .replaceAll("%feature%", finalReplacement) + )); + } + + public boolean canCreateInWorld(Player player) { + switch (WorldsSetting.valueOf(VirtualRealty.getPluginConfiguration().worldsSetting.toUpperCase())) { + case ALL: + break; + case INCLUDED: + if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().noneMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false; + break; + case EXCLUDED: + if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().anyMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false; + } + return true; + } + } 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 343d2bf..6666f9a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java @@ -27,7 +27,6 @@ import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.material.Crops; import org.bukkit.permissions.Permission; import java.util.ArrayList; @@ -776,8 +775,9 @@ public void onBlockExplode(BlockExplodeEvent e) { @EventHandler public void onFireSpread(BlockSpreadEvent e) { Plot plot = PlotManager.getBorderedPlot(e.getNewState().getLocation()); - if (plot != null) - e.setCancelled(true); + if (!(plot != null && (e.getSource().getType() == Material.FIRE && (e.getSource().getType() == e.getNewState().getType() || e.getNewState().getType() == Material.AIR)))) return; + e.setCancelled(true); + VirtualRealty.debug("Cancelled " + e.getClass().getSimpleName() + " [Fire Spread]: " + e.getSource().getLocation()); } @EventHandler @@ -787,9 +787,8 @@ public void onFireBurn(BlockBurnEvent e) { Plot toPlot = PlotManager.getPlot(e.getBlock().getLocation()); if (toPlot == null) return; if (fromPlot != null) { - if (toPlot.getID() != fromPlot.getID()) { + if (toPlot.getID() != fromPlot.getID()) e.setCancelled(true); - } } else { e.setCancelled(true); } diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java index 921406c..d7fc2aa 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java @@ -16,7 +16,6 @@ import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; import java.util.HashMap; import java.util.Map; @@ -67,7 +66,7 @@ public void onPlayerDeath(PlayerDeathEvent e) { player.getInventory().addItem(DRAFT_MAP.get(player).getValue().getKey().getItemStack()); DRAFT_MAP.get(player).getKey().removeGrid(); DRAFT_MAP.remove(player); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeDisabledDueToDeath); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeDisabledDueToDeath); } @EventHandler @@ -81,7 +80,7 @@ public void onBlockPlace(BlockPlaceEvent e) { } if (itemInHand.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) && (new NBTItem(itemInHand)).hasKey("vrplot_item")) { e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantPlaceDraftItems); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantPlaceClaimItems); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java index 2215906..f332a89 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java @@ -13,6 +13,10 @@ public class ConfirmationManager { @Getter public static final List confirmations = new ArrayList<>(); + public static boolean doesConfirmationExist(ConfirmationType confirmationType, UUID player) { + return confirmations.stream().anyMatch(confirmation -> confirmation.getConfirmationType() == confirmationType && confirmation.getSender().getUniqueId().equals(player)); + } + public static void removeConfirmations(int plotID, ConfirmationType confirmationType) { confirmations.removeIf(confirmation -> confirmation.getPlotID() == plotID && confirmation.getConfirmationType() == confirmationType); } diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java index b89133a..2e0ab16 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java @@ -1,16 +1,20 @@ package com.modnmetl.virtualrealty.managers; import com.modnmetl.virtualrealty.enums.PlotSize; +import com.modnmetl.virtualrealty.objects.data.PlotMember; import com.modnmetl.virtualrealty.objects.math.BlockVector2; import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.objects.region.Cuboid; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.math.BlockVector3; import com.modnmetl.virtualrealty.sql.Database; +import lombok.Data; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; +import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; @@ -21,14 +25,21 @@ public class PlotManager { private static final Set plots = new LinkedHashSet<>(); public static void loadPlots() { - plots.clear(); - try { - ResultSet rs = Database.getInstance().getStatement().executeQuery("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`"); + try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`"); ResultSet rs = ps.executeQuery()) { + plots.clear(); while (rs.next()) { plots.add(new Plot(rs)); } - } catch (SQLException ex) { - ex.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void loadMembers() { + try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`"); ResultSet rs = ps.executeQuery()) { + while (rs.next()) new PlotMember(rs); + } catch (Exception e) { + e.printStackTrace(); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java deleted file mode 100644 index b8e7037..0000000 --- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.modnmetl.virtualrealty.managers; - -import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.objects.data.PlotMember; -import com.modnmetl.virtualrealty.sql.Database; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class PlotMemberManager { - - public static void loadMembers() { - try { - ResultSet rs = Database.getInstance().getStatement().executeQuery("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`"); - while (rs.next()) new PlotMember(rs); - } catch (SQLException e) { - e.printStackTrace(); - } - } - -} diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java index 50b18ae..00dd938 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java @@ -24,9 +24,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; +import java.sql.*; import java.time.*; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; @@ -617,12 +615,33 @@ public void insert() { for (RegionPermission permission : this.nonMemberPermissions) { permissions.append(permission.name()).append("¦"); } - Database.getInstance().getStatement().execute("INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + - "` (`ID`, `ownedBy`, `nonMemberPermissions`, `assignedBy`, `ownedUntilDate`, `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`, `createdLocation`, `created`, `modified`, `selectedGameMode`) " + - "VALUES ('" + this.ID + "', '" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "', '" + permissions + "', '" + this.assignedBy + "', '" + Timestamp.valueOf(this.ownedUntilDate) + "', '" + - this.floorMaterial + ":" + this.floorData + "', '" + this.borderMaterial + ":" + this.borderData + "', '" + this.plotSize + "', '" + this.length + "', '" + this.width + "', '" + - this.height + "', '" + serializedLocation + "', '" + Timestamp.from(Instant.now()) + "', '" + Timestamp.from(Instant.now()) + "', '" + this.selectedGameMode.name() - + "')"); + try (Connection conn = Database.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement( + "INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + + "` (`ID`, `ownedBy`, `nonMemberPermissions`, `assignedBy`, `ownedUntilDate`," + + " `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`," + + " `createdLocation`, `created`, `modified`, `selectedGameMode`) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + )) { + ps.setInt(1, this.ID); + ps.setString(2, (this.ownedBy == null ? "" : this.ownedBy.toString())); + ps.setString(3, permissions.toString()); + ps.setString(4, this.assignedBy); + ps.setTimestamp(5, Timestamp.valueOf(this.ownedUntilDate)); + ps.setString(6, this.floorMaterial + ":" + this.floorData); + ps.setString(7, this.borderMaterial + ":" + this.borderData); + ps.setString(8, this.plotSize.toString()); + ps.setInt(9, this.length); + ps.setInt(10, this.width); + ps.setInt(11, this.height); + ps.setString(12, serializedLocation); + ps.setTimestamp(13, Timestamp.from(Instant.now())); + ps.setTimestamp(14, Timestamp.from(Instant.now())); + ps.setString(15, this.selectedGameMode.name()); + ps.execute(); + } catch (Exception e) { + e.printStackTrace(); + } } @SneakyThrows @@ -631,21 +650,41 @@ public void update() { for (RegionPermission permission : this.nonMemberPermissions) { permissions.append(permission.name()).append("¦"); } - Database.getInstance().getStatement().execute("UPDATE `" + - VirtualRealty.getPluginConfiguration().mysql.plotsTableName + - "` SET `ownedBy`='" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "'," + - " `nonMemberPermissions`='" + permissions + "'," + - " `assignedBy`='" + this.assignedBy + "'," + - " `ownedUntilDate`='" + Timestamp.valueOf(this.ownedUntilDate) + "'," + - " `floorMaterial`='" + this.floorMaterial + ":" + this.floorData + "'," + - " `borderMaterial`='" + this.borderMaterial + ":" + this.borderData + "'," + - " `plotSize`='" + this.plotSize + "'," + - " `length`='" + this.length + "'," + - " `width`='" + this.width + "'," + - " `height`='" + this.height + "'," + - " `modified`='" + (this.modified != null ? Timestamp.from(this.modified) : Timestamp.from(Instant.now())) + "'," + - " `selectedGameMode`='" + this.selectedGameMode.name() + "'" + - " WHERE `ID`='" + this.ID + "'"); + try (Connection conn = Database.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement( + "UPDATE `" + + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + + "` SET `ownedBy`= ?," + + " `nonMemberPermissions`= ?," + + " `assignedBy`= ?," + + " `ownedUntilDate`= ?," + + " `floorMaterial`= ?," + + " `borderMaterial`= ?," + + " `plotSize`= ?," + + " `length`= ?," + + " `width`= ?," + + " `height`= ?," + + " `modified`= ?," + + " `selectedGameMode`= ?" + + " WHERE `ID`= ?" + )) { + ps.setString(1, (this.ownedBy == null ? "" : this.ownedBy.toString())); + ps.setString(2, permissions.toString()); + ps.setString(3, this.assignedBy); + ps.setTimestamp(4, Timestamp.valueOf(this.ownedUntilDate)); + ps.setString(5, this.floorMaterial + ":" + this.floorData); + ps.setString(6, this.borderMaterial + ":" + this.borderData); + ps.setString(7, this.plotSize.toString()); + ps.setInt(8, this.length); + ps.setInt(9, this.width); + ps.setInt(10, this.height); + ps.setTimestamp(11, (this.modified != null ? Timestamp.from(this.modified) : Timestamp.from(Instant.now()))); + ps.setString(12, this.selectedGameMode.name()); + ps.setInt(13, this.ID); + ps.execute(); + } catch (Exception e) { + e.printStackTrace(); + } } public void remove(CommandSender sender) { @@ -663,9 +702,13 @@ public void remove(CommandSender sender) { if (VirtualRealty.getDynmapManager() != null) { DynmapManager.removeDynMapMarker(this); } - try { - Database.getInstance().getStatement().execute("DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` WHERE `ID` = '" + ID + "';"); - } catch (SQLException e) { + try (Connection conn = Database.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement( + "DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` WHERE `ID` = ?" + )) { + ps.setInt(1, this.ID); + ps.execute(); + } catch (Exception e) { e.printStackTrace(); } PlotManager.removePlotFromList(this); diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java index 7abf8f4..386cac5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java @@ -11,7 +11,11 @@ import lombok.SneakyThrows; import org.bukkit.GameMode; +import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.Timestamp; +import java.time.Instant; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -109,10 +113,21 @@ public void insert() { for (ManagementPermission permission : this.managementPermissions) { managementPermissions.append(permission.name()).append("¦"); } - Database.getInstance().getStatement().execute("INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + - "` (`uuid`, `plot`, `selectedGameMode`, `permissions`, `managementPermissions`) " + - "VALUES ('" + this.uuid.toString() + "', '" + this.plot.getID() + "', '" + this.getSelectedGameMode().name() + "', '" + permissions + "', '" + managementPermissions - + "')"); + try (Connection conn = Database.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement( + "INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + + "` (`uuid`, `plot`, `selectedGameMode`, `permissions`, `managementPermissions`) " + + "VALUES (?, ?, ?, ?, ?)" + )) { + ps.setString(1, this.uuid.toString()); + ps.setInt(2, this.plot.getID()); + ps.setString(3, this.getSelectedGameMode().name()); + ps.setString(4, permissions.toString()); + ps.setString(5, managementPermissions.toString()); + ps.execute(); + } catch (Exception e) { + e.printStackTrace(); + } } @SneakyThrows @@ -125,17 +140,39 @@ public void update() { for (ManagementPermission permission : this.managementPermissions) { managementPermissions.append(permission.name()).append("¦"); } - Database.getInstance().getStatement().execute("UPDATE `" + - VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + - "` SET `permissions`='" + permissions + "'," + - "`managementPermissions`='" + managementPermissions + "'," + - "`selectedGameMode`='" + selectedGameMode.name() + "'" + - " WHERE `uuid`='" + this.uuid.toString() + "' AND `plot`='" + this.plot.getID() + "'"); + try (Connection conn = Database.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement( + "UPDATE `" + + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + + "` SET `permissions`= ?," + + "`managementPermissions`= ?," + + "`selectedGameMode`= ?" + + " WHERE `uuid`= ? AND `plot`= ?" + )) { + ps.setString(1, permissions.toString()); + ps.setString(2, managementPermissions.toString()); + ps.setString(3, selectedGameMode.name()); + ps.setString(4, this.uuid.toString()); + ps.setInt(5, this.plot.getID()); + ps.execute(); + } catch (Exception e) { + e.printStackTrace(); + } } @SneakyThrows public void delete() { - Database.getInstance().getStatement().execute("DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "` WHERE `uuid` = '" + this.uuid + "' AND `plot`=" + plot.getID() + ";"); + try (Connection conn = Database.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement( + "DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`" + + " WHERE `uuid` = ? AND `plot` = ?" + )) { + ps.setString(1, this.uuid.toString()); + ps.setInt(2, plot.getID()); + ps.execute(); + } catch (Exception e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/com/modnmetl/virtualrealty/sql/Database.java b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java index b422b4a..43d2776 100644 --- a/src/main/java/com/modnmetl/virtualrealty/sql/Database.java +++ b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java @@ -4,12 +4,14 @@ import com.modnmetl.virtualrealty.configs.PluginConfiguration; import com.zaxxer.hikari.HikariDataSource; import lombok.Getter; +import lombok.SneakyThrows; import org.sqlite.SQLiteDataSource; import javax.sql.DataSource; import java.io.File; import java.io.PrintWriter; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; @@ -23,21 +25,14 @@ public class Database { @Getter private final DataSource dataSource; - @Getter - private final Connection connection; - @Getter - private final Statement statement; - public Database(File file) throws SQLException { + public Database(File file) { dataModel = VirtualRealty.getPluginConfiguration().dataModel; SQLiteDataSource sqLiteDataSource = new SQLiteDataSource(); sqLiteDataSource.setUrl("jdbc:sqlite:" + file.getAbsolutePath()); dataSource = sqLiteDataSource; - connection = dataSource.getConnection(); - statement = connection.createStatement(); instance = this; createTables(); - updateTables(); } public Database(String hostname, int port, String username, String password, String database) throws SQLException { @@ -50,65 +45,34 @@ public Database(String hostname, int port, String username, String password, Str hikariDataSource.setPassword(password); } dataSource.setLogWriter(new PrintWriter(System.out)); - connection = dataSource.getConnection(); - statement = connection.createStatement(); instance = this; createTables(); - updateTables(); } - private void createTables() { - try { - statement.execute("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID` INT(12) NOT NULL, `ownedBy` VARCHAR(36) NOT NULL, `nonMemberPermissions` TEXT NOT NULL, `assignedBy` VARCHAR(36) NOT NULL, `ownedUntilDate` DATETIME NOT NULL, `floorMaterial` VARCHAR(32) NOT NULL, `borderMaterial` VARCHAR(32) NOT NULL, `plotSize` VARCHAR(32) NOT NULL, `length` INT(24) NOT NULL, `width` INT(24) NOT NULL, `height` INT(24) NOT NULL, `createdLocation` TEXT(500) NOT NULL, `created` DATETIME, `modified` DATETIME, `selectedGameMode` TEXT, PRIMARY KEY(`ID`))"); - statement.execute("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "` (`uuid` VARCHAR(36) NOT NULL, `plot` INT(11) NOT NULL, `selectedGameMode` TEXT NOT NULL, `permissions` TEXT NOT NULL, `managementPermissions` TEXT NOT NULL)"); - } catch (SQLException ex) { - ex.printStackTrace(); - } + @SneakyThrows + public Connection getConnection() { + return dataSource.getConnection(); } - private void updateTables() { - if (dataModel == PluginConfiguration.DataModel.MYSQL) { - try { - statement.execute("ALTER TABLE IF EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `borderMaterial` VARCHAR(32) AFTER `floorMaterial`;"); - } catch (SQLException ignored) {} - try { - statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` DROP `members`;"); - } catch (SQLException ignored) {} - try { - statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `created` DATETIME AFTER `createdLocation`;"); - } catch (SQLException ignored) {} - try { - statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `modified` DATETIME AFTER `created`;"); - } catch (SQLException ignored) {} - try { - statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `selectedGameMode` TEXT;"); - } catch (SQLException ignored) {} - try { - statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `nonMemberPermissions` TEXT NOT NULL AFTER `ownedBy`;"); - } catch (SQLException ignored) {} + + private void createTables() { + try (Connection conn = getConnection(); + PreparedStatement ps = conn.prepareStatement("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID` INT(12) NOT NULL, `ownedBy` VARCHAR(36) NOT NULL, `nonMemberPermissions` TEXT NOT NULL, `assignedBy` VARCHAR(36) NOT NULL, `ownedUntilDate` DATETIME NOT NULL, `floorMaterial` VARCHAR(32) NOT NULL, `borderMaterial` VARCHAR(32) NOT NULL, `plotSize` VARCHAR(32) NOT NULL, `length` INT(24) NOT NULL, `width` INT(24) NOT NULL, `height` INT(24) NOT NULL, `createdLocation` TEXT(500) NOT NULL, `created` DATETIME, `modified` DATETIME, `selectedGameMode` TEXT, PRIMARY KEY(`ID`))")) { + ps.execute(); + } catch (Exception e) { + e.printStackTrace(); } - if (dataModel == PluginConfiguration.DataModel.SQLITE) { - try { - statement.execute("SELECT `nonMemberPermissions` FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`"); - } catch (SQLException ex) { - try { - statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` RENAME TO `_" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "_old`;"); - createTables(); - statement.execute("INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID`, `ownedBy`, `nonMemberPermissions`, `assignedBy`, `ownedUntilDate`, `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`, `createdLocation`, `created`, `modified`, `selectedGameMode`)" + - " SELECT `ID`, `ownedBy`, '" + "" + "', `assignedBy`, `ownedUntilDate`, `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`, `createdLocation`, `created`, `modified`, '" + "" + "'" + - " FROM _" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "_old;"); - } catch (SQLException e) { - e.printStackTrace(); - } - } + try (Connection conn = getConnection(); + PreparedStatement ps = conn.prepareStatement("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "` (`uuid` VARCHAR(36) NOT NULL, `plot` INT(11) NOT NULL, `selectedGameMode` TEXT NOT NULL, `permissions` TEXT NOT NULL, `managementPermissions` TEXT NOT NULL)")) { + ps.execute(); + } catch (Exception e) { + e.printStackTrace(); } } public static void connectToDatabase(File databaseFile) throws SQLException { - if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.SQLITE) { - new Database(databaseFile); - } - if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.MYSQL) { + if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.SQLITE) new Database(databaseFile); + if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.MYSQL) new Database( VirtualRealty.getPluginConfiguration().mysql.hostname, VirtualRealty.getPluginConfiguration().mysql.port, @@ -116,7 +80,6 @@ public static void connectToDatabase(File databaseFile) throws SQLException { VirtualRealty.getPluginConfiguration().mysql.password, VirtualRealty.getPluginConfiguration().mysql.database ); - } VirtualRealty.debug("Connected to database"); } From 5e32fdf79bfa20b49699db03e62dc3759993ca0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Mon, 24 Oct 2022 21:35:14 +0200 Subject: [PATCH 02/10] v2.5.0 - small DB change --- src/main/java/com/modnmetl/virtualrealty/objects/Plot.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java index 00dd938..8532e5e 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java @@ -626,7 +626,7 @@ public void insert() { ps.setInt(1, this.ID); ps.setString(2, (this.ownedBy == null ? "" : this.ownedBy.toString())); ps.setString(3, permissions.toString()); - ps.setString(4, this.assignedBy); + ps.setString(4, (this.assignedBy == null ? "null" : this.assignedBy)); ps.setTimestamp(5, Timestamp.valueOf(this.ownedUntilDate)); ps.setString(6, this.floorMaterial + ":" + this.floorData); ps.setString(7, this.borderMaterial + ":" + this.borderData); @@ -670,7 +670,7 @@ public void update() { )) { ps.setString(1, (this.ownedBy == null ? "" : this.ownedBy.toString())); ps.setString(2, permissions.toString()); - ps.setString(3, this.assignedBy); + ps.setString(3, (this.assignedBy == null ? "null" : this.assignedBy)); ps.setTimestamp(4, Timestamp.valueOf(this.ownedUntilDate)); ps.setString(5, this.floorMaterial + ":" + this.floorData); ps.setString(6, this.borderMaterial + ":" + this.borderData); From 4f4738ab6c8d94387fa569097e8ea5137ef8093c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Tue, 25 Oct 2022 12:59:10 +0200 Subject: [PATCH 03/10] v2.5.0 - pre-release fixes --- .../commands/vrplot/subcommand/ListSubCommand.java | 2 +- .../listeners/player/PlayerActionListener.java | 3 +++ .../virtualrealty/managers/DynmapManager.java | 1 - .../java/com/modnmetl/virtualrealty/objects/Plot.java | 11 ++++++++--- .../virtualrealty/utils/data/SchematicUtil.java | 4 +++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java index 55cece8..39a8554 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java @@ -43,7 +43,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a LocalDateTime localDateTime = plot.getOwnedUntilDate(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); StringBuilder ownedBy = new StringBuilder(); - ownedBy.append((plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : VirtualRealty.getMessages().available)); + ownedBy.append((plot.getOwnedBy() != null ? ((Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName()) : VirtualRealty.getMessages().available)); boolean isOwned = !ownedBy.toString().equals(VirtualRealty.getMessages().available); for (int i = ownedBy.length(); i < 16; i++) { ownedBy.append(" "); diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java index 5b86a64..6388097 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java @@ -66,6 +66,7 @@ public void onPlotItemStake(PlayerInteractEvent e) { if (!player.isOp()) return; if (!(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) return; if (!DraftListener.DRAFT_MAP.containsKey(player)) return; + e.setCancelled(true); GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey(); PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey(); Cuboid cuboid = RegionUtil.getRegion(gridStructure.getPreviewLocation(), Direction.byYaw(gridStructure.getPreviewLocation().getYaw()), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth()); @@ -254,6 +255,7 @@ public void onPlotItemDraft(PlayerInteractEvent e) { if (!player.isOp()) return; if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if (DraftListener.DRAFT_MAP.containsKey(player)) { + e.setCancelled(true); player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack()); player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack()); DraftListener.DRAFT_MAP.get(player).getKey().removeGrid(); @@ -278,6 +280,7 @@ public void onPlotItemDraft(PlayerInteractEvent e) { //player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notHoldingPlotClaim); return; } + e.setCancelled(true); PlotItem plotItem = PlotItem.fromItemStack(claimItem); Plot plot = PlotManager.getPlot(player.getLocation()); String replacement = null; diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java index 654de7b..d59aa31 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java @@ -116,7 +116,6 @@ public static void resetPlotMarker(Plot plot) { marker.setFillStyle(opacity, color); marker.setLineStyle(2, 0.8, 0x474747); marker.setMarkerSet(VirtualRealty.getDynmapManager().markerset); - VirtualRealty.debug("Updated dynmap marker #" + plot.getID()); } public static void removeDynMapMarker(Plot plot) { diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java index 8532e5e..5834c50 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java @@ -103,9 +103,14 @@ public Plot(ResultSet rs) { this.assignedBy = rs.getString("assignedBy").equalsIgnoreCase("null") ? null : rs.getString("assignedBy"); DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral(' ').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter(); if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.SQLITE) { - this.ownedUntilDate = LocalDateTime.parse(rs.getString("ownedUntilDate"), dateTimeFormatter); - if (rs.getString("created") != null) - this.createdAt = LocalDateTime.parse(rs.getString("created"), dateTimeFormatter); + this.ownedUntilDate = rs.getTimestamp("ownedUntilDate").toLocalDateTime(); + if (rs.getString("created") != null) { + try { + this.createdAt = rs.getTimestamp("created").toLocalDateTime(); + } catch (Exception ignored) { + this.createdAt = LocalDateTime.parse(rs.getString("created"), dateTimeFormatter); + } + } } else { this.ownedUntilDate = rs.getTimestamp("ownedUntilDate").toLocalDateTime(); if (rs.getTimestamp("created") != null) 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 df452d1..e6f728e 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java @@ -92,7 +92,9 @@ public static void paste(int plotID) { e.printStackTrace(); } } else { - oldBlock.setBlockData(Bukkit.createBlockData("minecraft:" + block.getBlockData()), false); + oldBlock.setBlockData( + Bukkit.createBlockData("minecraft:" + + block.getBlockData()), false); } } VirtualRealty.debug("Pasted " + blocks.size() + " blocks in: " + (System.currentTimeMillis() - time) + " ms"); From cc5c48bd9100079236fc73b8b6b6e1cfd8799529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Thu, 3 Nov 2022 17:03:25 +0100 Subject: [PATCH 04/10] v2.5.0 - pre-release improvements --- .../modnmetl/virtualrealty/VirtualRealty.java | 151 +++++++++++++----- .../commands/CommandManager.java | 11 +- .../commands/plot/PlotCommand.java | 2 - .../plot/subcommand/AddSubCommand.java | 10 +- .../plot/subcommand/DraftSubCommand.java | 44 ----- .../plot/subcommand/GmSubCommand.java | 2 +- .../plot/subcommand/InfoSubCommand.java | 2 +- .../plot/subcommand/KickSubCommand.java | 10 +- .../plot/subcommand/ListSubCommand.java | 8 +- .../plot/subcommand/StakeSubCommand.java | 50 ------ .../plot/subcommand/TpSubCommand.java | 2 +- .../vrplot/subcommand/AssignSubCommand.java | 2 +- .../vrplot/subcommand/CreateSubCommand.java | 39 ++++- .../vrplot/subcommand/InfoSubCommand.java | 15 +- .../vrplot/subcommand/ListSubCommand.java | 4 +- .../vrplot/subcommand/ReloadSubCommand.java | 4 +- .../vrplot/subcommand/RemoveSubCommand.java | 4 +- .../vrplot/subcommand/SetSubCommand.java | 8 +- .../vrplot/subcommand/TpSubCommand.java | 2 +- .../vrplot/subcommand/UnassignSubCommand.java | 2 +- .../vrplot/subcommand/VisualSubCommand.java | 13 +- .../configs/MessagesConfiguration.java | 1 + .../configs/PluginConfiguration.java | 12 +- .../listeners/PlotEntranceListener.java | 2 +- .../player/PlayerActionListener.java | 73 ++++++--- .../protection/BorderProtectionListener.java | 4 +- .../protection/PlotProtectionListener.java | 74 ++++----- .../protection/WorldProtectionListener.java | 20 +-- .../listeners/stake/ConfirmationListener.java | 22 --- .../listeners/stake/DraftListener.java | 8 +- .../managers/ConfirmationManager.java | 6 +- .../virtualrealty/managers/DynmapManager.java | 2 +- .../managers/MetricsManager.java | 2 +- .../virtualrealty/managers/PlotManager.java | 68 +++++--- .../modnmetl/virtualrealty/objects/Plot.java | 18 +-- .../virtualrealty/objects/data/PlotItem.java | 9 +- .../objects/data/PlotMember.java | 2 +- .../objects/region/GridStructure.java | 27 ++-- .../registry/VirtualPlaceholders.java | 2 +- .../virtualrealty/utils/RegionUtil.java | 2 +- .../utils/data/OldSchematicUtil.java | 2 +- .../utils/data/SchematicUtil.java | 125 +++++++++++---- .../utils/data/VirtualLocation.java | 27 ++++ 43 files changed, 521 insertions(+), 372 deletions(-) delete mode 100644 src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java delete mode 100644 src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java create mode 100644 src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualLocation.java diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index 8be4b41..536b6c0 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -56,7 +56,9 @@ public final class VirtualRealty extends JavaPlugin { @Getter private static VirtualRealty instance; @Getter - public MetricsManager metricsManager; + private MetricsManager metricsManager; + @Getter + private PlotManager plotManager; @Getter public ConfigurationFactory configFactory = new ConfigurationFactory(); @@ -77,6 +79,7 @@ public final class VirtualRealty extends JavaPlugin { private static Object premium; public static boolean upToDate; public static String latestVersion; + public static boolean developmentBuild; //FILES @Getter @@ -94,8 +97,8 @@ public final class VirtualRealty extends JavaPlugin { @Override public void onEnable() { - classLoader = getClassLoader(); instance = this; + classLoader = getClassLoader(); try { jarFiles.add(new JarFile(getFile())); } catch (IOException e) { @@ -108,47 +111,32 @@ public void onEnable() { plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain"); plotsSchemaFolder.mkdirs(); reloadConfigs(); - this.locale = new Locale(pluginConfiguration.locale.split("_")[0], pluginConfiguration.locale.split("_")[1]); + this.locale = new Locale(getPluginConfiguration().locale.split("_")[0], getPluginConfiguration().locale.split("_")[1]); configureMessages(); - if (ServerVersion.valueOf(pluginConfiguration.initServerVersion) == ServerVersion.LEGACY && currentServerVersion == ServerVersion.MODERN) { + if (ServerVersion.valueOf(getPluginConfiguration().initServerVersion) == ServerVersion.LEGACY && currentServerVersion == ServerVersion.MODERN) { this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « "); - this.getLogger().severe(" You cannot migrate existing legacy plots (1.8-1.12) to a non-legacy server version (1.13 and higher)"); + this.getLogger().severe(" You cannot migrate existing legacy plots (<1.13) to a non-legacy server version (1.13 and higher)"); this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « "); this.getPluginLoader().disablePlugin(this); return; } - if (ServerVersion.valueOf(pluginConfiguration.initServerVersion) == ServerVersion.MODERN && currentServerVersion == ServerVersion.LEGACY) { + if (ServerVersion.valueOf(getPluginConfiguration().initServerVersion) == ServerVersion.MODERN && currentServerVersion == ServerVersion.LEGACY) { this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « "); - this.getLogger().severe(" You cannot migrate existing non-legacy plots (1.13 and higher) to a legacy server version (1.8-1.12)"); + this.getLogger().severe(" You cannot migrate existing non-legacy plots (1.13 and higher) to a legacy server version (<1.13)"); this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « "); this.getPluginLoader().disablePlugin(this); return; } - String[] updateCheck = UpdateChecker.getUpdate(); - if (updateCheck != null) { - if (!updateCheck[0].equals(this.getDescription().getVersion())) { - upToDate = false; - latestVersion = updateCheck[0]; - this.getLogger().info("A newer version is available!"); - this.getLogger().info("The current version you use: " + this.getDescription().getVersion()); - this.getLogger().info("Latest version available: " + updateCheck[0]); - this.getLogger().info("Download link: https://www.spigotmc.org/resources/virtual-realty.95599/"); - } else { - upToDate = true; - latestVersion = this.getDescription().getVersion(); - this.getLogger().info("Plugin is up to date!"); - } - } + checkUpdates(); if (!pluginConfiguration.license.key.isEmpty() && !pluginConfiguration.license.email.isEmpty()) { try { - new Loader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion(), getLoader(), VirtualRealty.getPluginConfiguration().loaderDebugMode); + new Loader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion(), getLoader(), pluginConfiguration.loaderDebugMode); } catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException e) { e.printStackTrace(); getLogger().log(Level.WARNING, "Load of premium features failed."); } } - metricsManager = new MetricsManager(this, 14066); - metricsManager.registerMetrics(); + loadMetrics(); loadSizesConfiguration(); try { Database.connectToDatabase(databaseFile); @@ -157,19 +145,12 @@ public void onEnable() { this.getPluginLoader().disablePlugin(this); return; } - PlotManager.loadPlots(); - PlotManager.loadMembers(); - if (pluginConfiguration.dynmapMarkers) { - dynmapManager = new DynmapManager(this); - dynmapManager.registerDynmap(); - } + loadPlotsData(); + loadDynMapHook(); registerCommands(); - configureCommands(); + loadCommandsConfiguration(); registerListeners(); - if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { - new VirtualPlaceholders(this).register(); - debug("Registered new placeholders"); - } + registerPlaceholders(); debug("Server version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion()); } @@ -186,7 +167,7 @@ public void onDisable() { gridStructureEntryEntry.getKey().removeGrid(); }); DraftListener.DRAFT_MAP.clear(); - PlotManager.getPlots().forEach(Plot::update); + plotManager.getPlots().forEach(Plot::update); tasks.forEach(BukkitTask::cancel); try { DataSource dataSource; @@ -203,8 +184,93 @@ public void onDisable() { FileUtils.deleteQuietly(loaderFile); } - public static void debug(String message) { - if (VirtualRealty.getPluginConfiguration().debugMode) VirtualRealty.getInstance().getLogger().warning("DEBUG > " + message); + public void registerPlaceholders() { + if (!Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) return; + new VirtualPlaceholders(this).register(); + debug("Registered new placeholders"); + } + + public void checkUpdates() { + String[] currentVersionNumbers = this.getDescription().getVersion().split("\\."); + String[] updateCheck = UpdateChecker.getUpdate(); + if (updateCheck != null) { + String updateVersion = updateCheck[0]; + String[] cloudVersionNumbers = updateVersion.split("\\."); + int currentMajor = Integer.parseInt(currentVersionNumbers[0]); + int currentMinor = Integer.parseInt(currentVersionNumbers[1]); + int currentPatch = Integer.parseInt(currentVersionNumbers[2]); + + int updateMajor = Integer.parseInt(cloudVersionNumbers[0]); + int updateMinor = Integer.parseInt(cloudVersionNumbers[1]); + int updatePatch = Integer.parseInt(cloudVersionNumbers[2]); + + boolean patchUpdate = updatePatch > currentPatch; + boolean minorUpdate = updateMinor > currentMinor; + boolean majorUpdate = updateMajor > currentMajor; + + boolean majorDevelopment = currentMajor > updateMajor; + boolean minorDevelopment = currentMinor > updateMinor; + + if (currentMajor == updateMajor && currentMinor == updateMinor && currentPatch == updatePatch) { + upToDate = true; + latestVersion = this.getDescription().getVersion(); + this.getLogger().info("Plugin is up to date!"); + return; + } + if (majorUpdate) { + registerUpdate(updateVersion, false); + } else { + if (minorUpdate) { + if (majorDevelopment) { + registerUpdate(updateVersion, true); + return; + } + registerUpdate(updateVersion, false); + } else { + if (patchUpdate) { + if (majorDevelopment || minorDevelopment) { + registerUpdate(updateVersion, true); + return; + } + registerUpdate(updateVersion, false); + } else { + registerUpdate(updateVersion, true); + } + } + } + } + } + + private void registerUpdate(String version, boolean development) { + upToDate = false; + latestVersion = version; + if (development) { + developmentBuild = true; + this.getLogger().warning("You are running a development build!"); + return; + } + this.getLogger().info("A newer version is available!"); + this.getLogger().info("The current version you use: " + this.getDescription().getVersion()); + this.getLogger().info("Latest version available: " + version); + this.getLogger().info("Download link: https://www.spigotmc.org/resources/virtual-realty.95599/"); + } + + public void loadPlotsData() { + plotManager = new PlotManager(this); + plotManager.loadPlots(); + plotManager.loadMembers(); + } + + public void loadDynMapHook() { + if (getPluginConfiguration().dynmapMarkers) { + dynmapManager = new DynmapManager(this); + dynmapManager.registerDynmap(); + } + } + + public void loadMetrics() { + metricsManager = new MetricsManager(this, 14066); + metricsManager.registerMetrics(); } public void configureMessages() { @@ -213,7 +279,7 @@ public void configureMessages() { configFactory.loadMessagesConfiguration(messagesConfigurationFile); } - public void configureCommands() { + public void loadCommandsConfiguration() { commandsConfiguration = configFactory.loadCommandsConfiguration(commandsConfigurationFile); commandsConfiguration.refreshHelpMessages(); commandsConfiguration.assignAliases(); @@ -386,4 +452,9 @@ public void setClassLoader(ClassLoader newClassLoader) { classLoader = newClassLoader; } + public static void debug(String message) { + if (!VirtualRealty.getPluginConfiguration().debugMode) return; + VirtualRealty.getInstance().getLogger().warning("DEBUG > " + message); + } + } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java index 2a9fba8..ab50b35 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java @@ -128,7 +128,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman case "SET": { if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null; if (args.length == 2) { - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { if (args[1].isEmpty()) { tabCompleter.add(String.valueOf(plot.getID())); } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) { @@ -226,7 +226,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman case "UNASSIGN": { if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null; if (args.length == 2) { - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { if (args[1].isEmpty()) { tabCompleter.add(String.valueOf(plot.getID())); } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) { @@ -252,7 +252,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman case "TP": { if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null; if (args.length == 2) { - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { if (args[1].isEmpty()) { tabCompleter.add(String.valueOf(plot.getID())); } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) { @@ -372,7 +372,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman case "KICK": case "ADD": { if (args.length == 2) { - PlotManager.getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> { + PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> { if (finalArgs[1].isEmpty()) { tabCompleter.add(String.valueOf(plot.getID())); } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[0].toLowerCase())) { @@ -383,6 +383,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman } if (args.length == 3) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + if (onlinePlayer.getName().equals(player.getName())) continue; if (args[2].isEmpty()) { tabCompleter.add(onlinePlayer.getName()); } else if (onlinePlayer.getName().toLowerCase().startsWith(args[1].toLowerCase())) { @@ -394,7 +395,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman } case "TP": { if (args.length == 2) { - PlotManager.getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> { + PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> { if (finalArgs1[1].isEmpty()) { tabCompleter.add(String.valueOf(plot.getID())); } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs1[0].toLowerCase())) { diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java index e20ae96..bc6b388 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java @@ -26,8 +26,6 @@ public class PlotCommand implements CommandExecutor { HELP_LIST.add(" "); HELP_LIST.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); HELP_LIST.add(" §a/plot %panel_command% §8- §7Opens your plots panel"); - HELP_LIST.add(" §a/plot %draft_command% §8- §7Shows layout of potential new plot"); - HELP_LIST.add(" §a/plot %stake_command% §8- §7Creates the plot shown with draft"); HELP_LIST.add(" §a/plot %info_command% §8- §7Shows plot info"); HELP_LIST.add(" §a/plot %gm_command% §8- §7Changes gamemode"); HELP_LIST.add(" §a/plot %add_command% §8- §7Adds a member"); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java index b4cd4d1..2a97e8e 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java @@ -54,7 +54,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; @@ -70,7 +70,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a return; } } else { - if (plot.getPlotOwner().getUniqueId() != player.getUniqueId()) { + if (!plot.getOwnedBy().equals(player.getUniqueId())) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); return; } @@ -80,7 +80,11 @@ public void exec(CommandSender sender, Command command, String label, String[] a return; } if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantAddYourself); + if (plot.getOwnedBy().equals(player.getUniqueId())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantAddYourself); + } else { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().alreadyInMembers); + } return; } if (plot.getMember(offlinePlayer.getUniqueId()) != null) { diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java deleted file mode 100644 index feb9272..0000000 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.modnmetl.virtualrealty.commands.plot.subcommand; - -import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.ConfirmationType; -import com.modnmetl.virtualrealty.enums.Direction; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.enums.items.VItem; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.listeners.stake.DraftListener; -import com.modnmetl.virtualrealty.managers.ConfirmationManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.PlotItem; -import com.modnmetl.virtualrealty.objects.region.Cuboid; -import com.modnmetl.virtualrealty.objects.region.GridStructure; -import com.modnmetl.virtualrealty.utils.RegionUtil; -import de.tr7zw.nbtapi.NBTItem; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - -import java.util.AbstractMap; -import java.util.LinkedList; - -public class DraftSubCommand extends SubCommand { - - public DraftSubCommand() {} - - public DraftSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { - super(sender, command, label, args, new LinkedList<>()); - } - - @Override - public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { - assertPlayer(); - Player player = ((Player) sender); - - } - -} diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java index 0ffa378..b1e5444 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java @@ -64,7 +64,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeDisabled); return; } - Plot plot = PlotManager.getBorderedPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(player.getLocation()); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java index 9762fb0..defa1f2 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java @@ -28,7 +28,7 @@ public InfoSubCommand(CommandSender sender, Command command, String label, Strin public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { assertPlayer(); Player player = ((Player) sender); - Plot plot = PlotManager.getPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java index 2a9fc7b..ae2dcf5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java @@ -53,7 +53,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; @@ -69,7 +69,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a return; } } else { - if (plot.getPlotOwner().getUniqueId() != player.getUniqueId()) { + if (!plot.getOwnedBy().equals(player.getUniqueId())) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); return; } @@ -79,7 +79,11 @@ public void exec(CommandSender sender, Command command, String label, String[] a return; } if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickYourself); + if (plot.getOwnedBy().equals(player.getUniqueId())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickYourself); + } else { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickOwner); + } return; } PlotMember member = plot.getMember(offlinePlayer.getUniqueId()); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java index 9850083..7cc3315 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java @@ -30,14 +30,14 @@ public void exec(CommandSender sender, Command command, String label, String[] a assertPlayer(); Player player = ((Player) sender); boolean hasPlot = false; - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(player.getUniqueId()) && plot.getOwnedUntilDate().isAfter(LocalDateTime.now())) { hasPlot = true; break; } } boolean isMember = false; - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { if (plot.getMember(player.getUniqueId()) != null) { isMember = true; break; @@ -53,7 +53,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a if (hasPlot) { sender.sendMessage("§7§m "); sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |"); - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { LocalDateTime localDateTime = plot.getOwnedUntilDate(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); @@ -79,7 +79,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(" "); sender.sendMessage("§7§m "); sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |"); - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { if (plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId()) && plot.hasMembershipAccess(player.getUniqueId())) { StringBuilder ownedBy = new StringBuilder(); ownedBy.append((plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : VirtualRealty.getMessages().available)); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java deleted file mode 100644 index d596a26..0000000 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.modnmetl.virtualrealty.commands.plot.subcommand; - -import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.ConfirmationType; -import com.modnmetl.virtualrealty.enums.Direction; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.listeners.stake.DraftListener; -import com.modnmetl.virtualrealty.managers.ConfirmationManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.Confirmation; -import com.modnmetl.virtualrealty.objects.data.PlotItem; -import com.modnmetl.virtualrealty.objects.region.Cuboid; -import com.modnmetl.virtualrealty.objects.region.GridStructure; -import com.modnmetl.virtualrealty.utils.RegionUtil; -import com.modnmetl.virtualrealty.utils.multiversion.Chat; -import de.tr7zw.nbtapi.NBTItem; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; - -import java.time.LocalDateTime; -import java.util.*; - -public class StakeSubCommand extends SubCommand { - - public StakeSubCommand() {} - - public StakeSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { - super(sender, command, label, args, new LinkedList<>()); - } - - @Override - public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { - assertPlayer(); - Player player = ((Player) sender); - - } - -} diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java index cff3d50..5bea990 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java @@ -43,7 +43,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java index a44b8c7..26ac896 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java @@ -62,7 +62,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java index a2135d1..7fa7449 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java @@ -84,7 +84,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a } else { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.createPlot(location, PlotSize.AREA, length, height, width, true); + Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.AREA, length, height, width, true); long timeEnd = System.currentTimeMillis(); BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); @@ -97,7 +97,16 @@ public void exec(CommandSender sender, Command command, String label, String[] a new BukkitRunnable() { @Override public void run() { - new GridStructure(player, plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false); + new GridStructure( + player, + plot.getLength(), + plot.getHeight(), + plot.getWidth(), + plot.getID(), + ((Player) sender).getWorld(), + GridStructure.DISPLAY_TICKS, + plot.getCreatedLocation() + ).preview(true, false); } }.runTaskLater(VirtualRealty.getInstance(), 20); } @@ -143,7 +152,7 @@ public void run() { } sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.createPlot(location, plotSize, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), natural); + Plot plot = PlotManager.getInstance().createPlot(location, plotSize, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), natural); if (!natural) { if (floorMaterial != null) { plot.setFloorMaterial(floorMaterial, floorData); @@ -164,7 +173,16 @@ public void run() { new BukkitRunnable() { @Override public void run() { - new GridStructure(player, plot.getPlotSize().getLength(), plot.getPlotSize().getHeight(), plot.getPlotSize().getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false); + new GridStructure( + player, + plot.getPlotSize().getLength(), + plot.getPlotSize().getHeight(), + plot.getPlotSize().getWidth(), + plot.getID(), + ((Player) sender).getWorld(), + GridStructure.DISPLAY_TICKS, + plot.getCreatedLocation() + ).preview(true, false); } }.runTaskLater(VirtualRealty.getInstance(), 20); } @@ -233,7 +251,7 @@ public void run() { } sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.createPlot(location, PlotSize.CUSTOM, length, height, width, natural); + Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.CUSTOM, length, height, width, natural); if (!natural) { if (floorMaterial != null) { plot.setFloorMaterial(floorMaterial, floorData); @@ -254,7 +272,16 @@ public void run() { new BukkitRunnable() { @Override public void run() { - new GridStructure(player, plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false); + new GridStructure( + player, + plot.getLength(), + plot.getHeight(), + plot.getWidth(), + plot.getID(), + ((Player) sender).getWorld(), + GridStructure.DISPLAY_TICKS, + plot.getCreatedLocation() + ).preview(true, false); } }.runTaskLater(VirtualRealty.getInstance(), 20); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java index 2ed6a86..6c4750a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java @@ -5,7 +5,6 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; -import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -30,7 +29,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a assertPermission(); if (args.length < 2) { assertPlayer(); - Plot plot = PlotManager.getPlot(((Player) sender).getLocation()); + Plot plot = PlotManager.getInstance().getPlot(((Player) sender).getLocation()); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot); return; @@ -45,19 +44,19 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return; } - if (PlotManager.getPlots().isEmpty()) { + if (PlotManager.getInstance().getPlots().isEmpty()) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots); return; } - if (plotID < PlotManager.getPlotMinID()) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getPlotMinID()))); + if (plotID < PlotManager.getInstance().getPlotMinID()) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getInstance().getPlotMinID()))); return; } - if (plotID > PlotManager.getPlotMaxID()) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getPlotMaxID()))); + if (plotID > PlotManager.getInstance().getPlotMaxID()) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getInstance().getPlotMaxID()))); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java index 39a8554..570efdb 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java @@ -30,7 +30,7 @@ public ListSubCommand(CommandSender sender, Command command, String label, Strin @Override public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception { assertPermission(); - if (PlotManager.getPlots().isEmpty()) { + if (PlotManager.getInstance().getPlots().isEmpty()) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots); return; } @@ -39,7 +39,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(" "); sender.sendMessage("§7§m "); sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |"); - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { LocalDateTime localDateTime = plot.getOwnedUntilDate(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); StringBuilder ownedBy = new StringBuilder(); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java index 85111a9..3a377a7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java @@ -31,7 +31,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a VirtualRealty.getDynmapManager().markerset.deleteMarkerSet(); } VirtualRealty.getDynmapManager().registerDynmap(); - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { DynmapManager.resetPlotMarker(plot); } } else { @@ -40,7 +40,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a } } } - PlotManager.loadPlots(); + PlotManager.getInstance().loadPlots(); VirtualRealty.getInstance().loadSizesConfiguration(); } catch (Exception exception) { exception.printStackTrace(); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java index e4a5336..8e6edc2 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java @@ -49,7 +49,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; @@ -81,7 +81,7 @@ public void expiry() { ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); } }; - ConfirmationManager.confirmations.add(confirmation); + ConfirmationManager.addConfirmation(confirmation); } } else { plot.remove(sender); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java index eae1663..84ce257 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java @@ -75,7 +75,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; @@ -137,7 +137,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; @@ -175,7 +175,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; @@ -224,7 +224,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().invalidDateProvided); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java index 9aa0b72..e68595a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java @@ -44,7 +44,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java index f484c45..4814ef3 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java @@ -41,7 +41,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return; } - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java index e7ff5fd..52dbeb2 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java @@ -26,7 +26,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a assertPlayer(); assertPermission(); Player player = ((Player) sender); - Plot plot = PlotManager.getPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot); return; @@ -35,7 +35,16 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryActive); return; } - GridStructure previewStructure = new GridStructure(((Player) sender), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()); + GridStructure previewStructure = new GridStructure( + ((Player) sender), + plot.getLength(), + plot.getHeight(), + plot.getWidth(), + plot.getID(), + ((Player) sender).getWorld(), + GridStructure.DISPLAY_TICKS, + plot.getCreatedLocation() + ); previewStructure.preview(player.getLocation(), true, false); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed); } diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java index c484c48..32de2f7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java @@ -79,6 +79,7 @@ public class MessagesConfiguration extends OkaeriConfig { public String unassigned = "§aPlot has been unassigned!"; public String cantAddYourself = "§cYou can't add yourself to the plot!"; public String cantKickYourself = "§cYou can't kick yourself from the plot!"; + public String cantKickOwner = "§cYou can't kick the owner!"; public String alreadyInMembers = "§cThis player is already one of the plot members!"; public String standingOnPlot = "§cYou are standing on a plot!"; public String notStandingOnPlot = "§cYou aren't standing on any plot!"; diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java index 0b95a6d..3ec3cce 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java @@ -22,14 +22,14 @@ @Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE) public class PluginConfiguration extends OkaeriConfig { - @Comment("Changing this value will break your plugin!") + @Comment("Changing this value might break your plugin!") @CustomKey("initial-version") public String initServerVersion = VirtualRealty.legacyVersion ? ServerVersion.LEGACY.toString() : ServerVersion.MODERN.toString(); - @Comment("Debug mode") + @Comment("Debug mode (Displays more detailed info about plugin executions)") public boolean debugMode = false; - @Comment("Loader debug mode (only for devs)") + @Comment("Local loader mode (for devs)") public boolean loaderDebugMode = false; @Comment("Here you put your license details") @@ -47,6 +47,9 @@ public static class License extends OkaeriConfig { public boolean enablePlotGamemode = false; @Comment("Set your wanted language (locale)") + @Comment("You can create your own configuration for your language") + @Comment("To do so: go into the `messages` folder and create new file called `messages_%locale%.yml`") + @Comment("Replace `%locale%` with your locale (It doesn't matter if it conforms to the standard, it should just match the locale here in `config.yml`)") public String locale = "en_GB"; @Comment("Set which gamemode players change to when they enter their plot") @@ -88,7 +91,8 @@ public GameMode getDefaultPlotGamemode() { try { return GameMode.valueOf(plotGamemode); } catch (Exception e) { - VirtualRealty.getInstance().getLogger().warning("Couldn't parse plot-gamemode from config.yml\nUsing default: SURVIVAL"); + VirtualRealty.getInstance().getLogger().warning("Couldn't parse plot-gamemode from config.yml"); + VirtualRealty.getInstance().getLogger().warning("Using default: SURVIVAL"); return GameMode.SURVIVAL; } } diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java index e9a129d..c1cb6b4 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java @@ -34,7 +34,7 @@ public void onPlotMove(PlayerMoveEvent e) { Player player = e.getPlayer(); Location to = e.getTo(); if (to == null) return; - Plot plot = PlotManager.getPlot(to); + Plot plot = PlotManager.getInstance().getPlot(to); if (plot != null) { OfflinePlayer offlinePlayer; String enterPlotString = VirtualRealty.getMessages().enteredAvailablePlot; diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java index 6388097..ba95fce 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java @@ -50,11 +50,15 @@ public void onPlayerJoin(PlayerJoinEvent e) { new BukkitRunnable() { @Override public void run() { - player.sendMessage(VirtualRealty.PREFIX + "§7A new version of VirtualRealty plugin is available. §a[" + VirtualRealty.latestVersion + "]"); - TextComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aDownload the new version of the plugin here!"); - textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ new TextComponent("§a§oClick here to download the update!") })); - textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/")); - player.spigot().sendMessage(textComponent); + if (VirtualRealty.developmentBuild) { + player.sendMessage(VirtualRealty.PREFIX + "§6You are running a development build of VirtualRealty plugin. §7[" + VirtualRealty.getInstance().getDescription().getVersion() + "]"); + } else { + player.sendMessage(VirtualRealty.PREFIX + "§7A new version of VirtualRealty plugin is available. §a[" + VirtualRealty.latestVersion + "]"); + TextComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aDownload the new version of the plugin here!"); + textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick here to download the update!")})); + textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/")); + player.spigot().sendMessage(textComponent); + } } }.runTaskLater(VirtualRealty.getInstance(), 5); } @@ -63,14 +67,13 @@ public void run() { @EventHandler public void onPlotItemStake(PlayerInteractEvent e) { Player player = e.getPlayer(); - if (!player.isOp()) return; if (!(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) return; if (!DraftListener.DRAFT_MAP.containsKey(player)) return; e.setCancelled(true); GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey(); PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey(); Cuboid cuboid = RegionUtil.getRegion(gridStructure.getPreviewLocation(), Direction.byYaw(gridStructure.getPreviewLocation().getYaw()), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth()); - Plot plot = PlotManager.getPlot(gridStructure.getPreviewLocation()); + Plot plot = PlotManager.getInstance().getPlot(gridStructure.getPreviewLocation()); if (plot != null) { if (plotItem.getPlotSize().equals(plot.getPlotSize())) { if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { @@ -112,7 +115,7 @@ public void expiry() { ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); } }; - ConfirmationManager.confirmations.add(confirmation); + ConfirmationManager.addConfirmation(confirmation); return; } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { if (ConfirmationManager.doesConfirmationExist(ConfirmationType.EXTEND, player.getUniqueId())) { @@ -156,7 +159,7 @@ public void expiry() { ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); } }; - ConfirmationManager.confirmations.add(confirmation); + ConfirmationManager.addConfirmation(confirmation); return; } } @@ -190,7 +193,7 @@ public void success() { gridStructure.removeGrid(); this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.isNatural()); + Plot plot = PlotManager.getInstance().createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.isNatural()); AbstractMap.SimpleEntry floorData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_floor_material"), item.getByte("vrplot_floor_data")); AbstractMap.SimpleEntry borderData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_border_material"), item.getByte("vrplot_border_data")); if (!plotItem.isNatural()) { @@ -246,13 +249,12 @@ public void expiry() { ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); } }; - ConfirmationManager.confirmations.add(confirmation); + ConfirmationManager.addConfirmation(confirmation); } @EventHandler public void onPlotItemDraft(PlayerInteractEvent e) { Player player = e.getPlayer(); - if (!player.isOp()) return; if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if (DraftListener.DRAFT_MAP.containsKey(player)) { e.setCancelled(true); @@ -277,12 +279,11 @@ public void onPlotItemDraft(PlayerInteractEvent e) { if (!(claimItem.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) && (claimNbtItem = new NBTItem(claimItem)).getString("vrplot_item") != null && claimNbtItem.getString("vrplot_item").equals("CLAIM"))) { - //player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notHoldingPlotClaim); return; } e.setCancelled(true); PlotItem plotItem = PlotItem.fromItemStack(claimItem); - Plot plot = PlotManager.getPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); String replacement = null; if (plot == null) { if (!canCreateInWorld(player)) { @@ -308,7 +309,16 @@ public void onPlotItemDraft(PlayerInteractEvent e) { String finalReplacement = replacement; if (plot != null && plotItem.getPlotSize().equals(plot.getPlotSize()) && plot.getPlotSize() != PlotSize.CUSTOM) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot); - GridStructure previewStructure = new GridStructure((player), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), player.getWorld(), 0, plot.getCreatedLocation()); + GridStructure previewStructure = new GridStructure( + player, + plot.getLength(), + plot.getHeight(), + plot.getWidth(), + plot.getID(), + player.getWorld(), + 0, + plot.getCreatedLocation() + ); previewStructure.preview(player.getLocation(), true, false); player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed); PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); @@ -329,7 +339,16 @@ public void onPlotItemDraft(PlayerInteractEvent e) { if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledCollision); if (!GridStructure.isCuboidGridDisplaying(player, 0)) { - new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, player.getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true); + new GridStructure( + player, + plotSize.getLength(), + plotSize.getHeight(), + plotSize.getWidth(), + 0, + player.getWorld(), + GridStructure.DISPLAY_TICKS, + player.getLocation() + ).preview(player.getLocation(),true, true); } return; } @@ -337,12 +356,30 @@ public void onPlotItemDraft(PlayerInteractEvent e) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledBedrock); GridStructure.isCuboidGridDisplaying(player, 0); if (!GridStructure.isCuboidGridDisplaying(player, 0)) { - new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, player.getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true); + new GridStructure( + player, + plotSize.getLength(), + plotSize.getHeight(), + plotSize.getWidth(), + 0, + player.getWorld(), + GridStructure.DISPLAY_TICKS, + player.getLocation() + ).preview(player.getLocation(),true, true); } return; } PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); - GridStructure draftStructure = new GridStructure(player, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), 0, player.getWorld(), 0, player.getLocation()); + GridStructure draftStructure = new GridStructure( + player, + plotItem.getLength(), + plotItem.getHeight(), + plotItem.getWidth(), + 0, + player.getWorld(), + 0, + player.getLocation() + ); DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(draftStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem))); inv.remove(claimItem); if (VirtualRealty.legacyVersion) { diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java index e39ba01..af236e3 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java @@ -17,7 +17,7 @@ public BorderProtectionListener(VirtualRealty plugin) { @EventHandler public void onBorderBreak(BlockBreakEvent e) { - Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlock().getLocation()); if (plot == null) return; if (e.getPlayer().isOp()) return; if (!plot.getBorderBlocks().contains(e.getBlock())) return; @@ -27,7 +27,7 @@ public void onBorderBreak(BlockBreakEvent e) { @EventHandler public void onBorderPlace(BlockPlaceEvent e) { - Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlock().getLocation()); if (plot == null) return; if (e.getPlayer().isOp()) return; if (!plot.getBorderBlocks().contains(e.getBlock())) return; 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 6666f9a..fc122ff 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java @@ -78,7 +78,7 @@ 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); + Plot plot = PlotManager.getInstance().getPlot(location); if (plot != null) { if (VirtualRealty.getPluginConfiguration().disablePlotMobsSpawn) { e.setCancelled(true); @@ -101,7 +101,7 @@ public void onCropInteract(PlayerInteractEvent e) { } else { if (e.getClickedBlock().getType() != Material.FARMLAND) return; } - Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -137,7 +137,7 @@ public void onBlockInteract(PlayerInteractEvent e) { if (e.getHand() == EquipmentSlot.OFF_HAND) return; if (!e.getClickedBlock().getType().isInteractable() && !(e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE"))) return; } - Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; boolean isModernSwitch = !VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch; @@ -206,7 +206,7 @@ public void onChestEvent(PlayerInteractEvent e) { 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()); + Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -235,7 +235,7 @@ public void onPotInteract(PlayerInteractEvent e) { Player player = e.getPlayer(); if (e.getClickedBlock() == null) return; if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; - Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -278,7 +278,7 @@ public void onPotInteract(PlayerInteractEvent e) { public void onLiquidPlace(PlayerBucketEmptyEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getBorderedPlot(e.getBlockClicked().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlockClicked().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -306,7 +306,7 @@ public void onVehicleDestroy(VehicleDestroyEvent e) { if (e.isCancelled()) return; if (!(e.getAttacker() instanceof Player)) return; Player player = (Player) e.getAttacker(); - Plot plot = PlotManager.getBorderedPlot(e.getVehicle().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getVehicle().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -333,7 +333,7 @@ public void onVehicleDestroy(VehicleDestroyEvent e) { public void onLiquidTake(PlayerBucketFillEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getBorderedPlot(e.getBlockClicked().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlockClicked().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -359,7 +359,7 @@ public void onLiquidTake(PlayerBucketFillEvent e) { @EventHandler(priority = EventPriority.LOW) public void onBlockPlace(BlockPlaceEvent e) { Player player = e.getPlayer(); - Plot plot = PlotManager.getBorderedPlot(e.getBlockPlaced().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlockPlaced().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -386,7 +386,7 @@ public void onBlockPlace(BlockPlaceEvent e) { public void onBlockBreak(BlockBreakEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -413,11 +413,11 @@ public void onBlockBreak(BlockBreakEvent e) { public void onPistonRetract(BlockPistonRetractEvent e) { if (e.isCancelled()) return; Block piston = e.getBlock(); - Plot fromPlot = PlotManager.getPlot(piston.getLocation()); + Plot fromPlot = PlotManager.getInstance().getPlot(piston.getLocation()); e.getBlocks().forEach(block -> { Location toLocation = block.getLocation(); - Plot toPlot = PlotManager.getPlot(toLocation); - Plot toBorderedPlot = PlotManager.getBorderedPlot(toLocation); + Plot toPlot = PlotManager.getInstance().getPlot(toLocation); + Plot toBorderedPlot = PlotManager.getInstance().getBorderedPlot(toLocation); if (fromPlot != null) { if (toPlot == null) { e.setCancelled(true); @@ -435,8 +435,8 @@ public void onBlockMove(BlockPistonExtendEvent e) { if (e.isCancelled()) return; for (Block block : e.getBlocks()) { Location blockLocation = block.getLocation(); - Plot plot = PlotManager.getPlot(blockLocation); - Plot borderedPlot = PlotManager.getBorderedPlot(blockLocation); + Plot plot = PlotManager.getInstance().getPlot(blockLocation); + Plot borderedPlot = PlotManager.getInstance().getBorderedPlot(blockLocation); if (borderedPlot != null) { if (plot == null) { e.setCancelled(true); @@ -453,7 +453,7 @@ public void onIgniteEvent(BlockIgniteEvent e) { Player player = e.getPlayer(); if (player == null) return; if (e.getIgnitingBlock() == null) return; - Plot plot = PlotManager.getBorderedPlot(e.getIgnitingBlock().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getIgnitingBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -479,8 +479,8 @@ public void onIgniteEvent(BlockIgniteEvent e) { public void onBlockIgnite(BlockIgniteEvent e){ if (e.isCancelled()) return; if (e.getCause() != BlockIgniteEvent.IgniteCause.SPREAD) return; - Plot fromPlot = PlotManager.getPlot(e.getBlock().getLocation()); - Plot toPlot = PlotManager.getPlot(e.getIgnitingBlock().getLocation()); + Plot fromPlot = PlotManager.getInstance().getPlot(e.getBlock().getLocation()); + Plot toPlot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation()); if (toPlot != null && fromPlot == null) { e.setCancelled(true); } @@ -492,8 +492,8 @@ public void onTreeGrow(StructureGrowEvent e) { for (BlockState block : new ArrayList<>(e.getBlocks())) { Location saplingLocation = e.getLocation(); Location blockLocation = block.getLocation(); - Plot fromPlot = PlotManager.getPlot(saplingLocation); - Plot toPlot = PlotManager.getPlot(blockLocation); + Plot fromPlot = PlotManager.getInstance().getPlot(saplingLocation); + Plot toPlot = PlotManager.getInstance().getPlot(blockLocation); if (fromPlot != null) { if (toPlot != null) { if (fromPlot.getID() == toPlot.getID()) return; @@ -514,8 +514,8 @@ public void onDragonEggMove(BlockFromToEvent e) { if (block == Material.DRAGON_EGG || block == Material.LAVA || block == Material.WATER) { Location fromLocation = e.getBlock().getLocation(); Location toLocation = e.getToBlock().getLocation(); - Plot fromPlot = PlotManager.getPlot(fromLocation); - Plot toPlot = PlotManager.getPlot(toLocation); + Plot fromPlot = PlotManager.getInstance().getPlot(fromLocation); + Plot toPlot = PlotManager.getInstance().getPlot(toLocation); if (toPlot != null) { if (fromPlot == null) { e.setCancelled(true); @@ -532,7 +532,7 @@ public void onProjectileLaunch(ProjectileLaunchEvent e) { if (e.getEntity().getShooter() == null) return; if (!(e.getEntity().getShooter() instanceof Player)) return; Player shooter = ((Player) e.getEntity().getShooter()); - Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation()); if (plot == null) return; if (hasPermission(shooter, PLOT_BUILD)) return; if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player) e.getEntity().getShooter()).getUniqueId())) @@ -546,7 +546,7 @@ public void onProjectileHit(ProjectileHitEvent e) { if (e.getEntity().getShooter() == null) return; if (!(e.getEntity().getShooter() instanceof Player)) return; Player shooter = ((Player) e.getEntity().getShooter()); - Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation()); if (plot == null) return; if (hasPermission(shooter, PLOT_BUILD)) return; if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player) e.getEntity().getShooter()).getUniqueId())) @@ -558,7 +558,7 @@ public void onProjectileHit(ProjectileHitEvent e) { @EventHandler(priority = EventPriority.LOW) public void onArmorStandChange(PlayerArmorStandManipulateEvent e) { if (e.isCancelled()) return; - Plot plot = PlotManager.getPlot(e.getPlayer().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getPlayer().getLocation()); Player player = e.getPlayer(); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; @@ -587,7 +587,7 @@ public void onItemFrameDamage(HangingBreakByEntityEvent e) { if (e.isCancelled()) return; if (!(e.getRemover() instanceof Player)) return; Player player = (Player) e.getRemover(); - Plot plot = PlotManager.getPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -614,7 +614,7 @@ public void onItemFrameDamage(HangingBreakByEntityEvent e) { public void onItemFrameRotate(PlayerInteractEntityEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (!(e.getRightClicked() instanceof ItemFrame)) return; if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; @@ -645,7 +645,7 @@ private void onInteract(PlayerInteractEvent e) { 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()); + Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -673,7 +673,7 @@ public void onHangingPlace(HangingPlaceEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); if (player == null) return; - Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -702,7 +702,7 @@ public void onEntityDamage(EntityDamageByEntityEvent e) { 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()); + Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -731,7 +731,7 @@ public void onStaticEntityDamage(EntityDamageByEntityEvent e) { if (e.getEntity() instanceof Creature || e.getEntity() instanceof Player) return; if (!(e.getDamager() instanceof Player)) return; Player player = (Player) e.getDamager(); - Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -757,7 +757,7 @@ public void onStaticEntityDamage(EntityDamageByEntityEvent e) { @EventHandler(priority = EventPriority.LOW) public void onEntityExplode(EntityExplodeEvent e) { for (Block block : new ArrayList<>(e.blockList())) { - Plot plot = PlotManager.getBorderedPlot(block.getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(block.getLocation()); if (plot != null) e.blockList().remove(block); } @@ -766,7 +766,7 @@ public void onEntityExplode(EntityExplodeEvent e) { @EventHandler(priority = EventPriority.LOW) public void onBlockExplode(BlockExplodeEvent e) { for (Block block : new ArrayList<>(e.blockList())) { - Plot plot = PlotManager.getBorderedPlot(block.getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(block.getLocation()); if (plot != null) e.blockList().remove(block); } @@ -774,7 +774,7 @@ public void onBlockExplode(BlockExplodeEvent e) { @EventHandler public void onFireSpread(BlockSpreadEvent e) { - Plot plot = PlotManager.getBorderedPlot(e.getNewState().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getNewState().getLocation()); if (!(plot != null && (e.getSource().getType() == Material.FIRE && (e.getSource().getType() == e.getNewState().getType() || e.getNewState().getType() == Material.AIR)))) return; e.setCancelled(true); VirtualRealty.debug("Cancelled " + e.getClass().getSimpleName() + " [Fire Spread]: " + e.getSource().getLocation()); @@ -783,8 +783,8 @@ public void onFireSpread(BlockSpreadEvent e) { @EventHandler public void onFireBurn(BlockBurnEvent e) { if (!VirtualRealty.legacyVersion) { - Plot fromPlot = PlotManager.getPlot(e.getIgnitingBlock().getLocation()); - Plot toPlot = PlotManager.getPlot(e.getBlock().getLocation()); + Plot fromPlot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation()); + Plot toPlot = PlotManager.getInstance().getPlot(e.getBlock().getLocation()); if (toPlot == null) return; if (fromPlot != null) { if (toPlot.getID() != fromPlot.getID()) @@ -801,7 +801,7 @@ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) { if (!((e.getDamager() instanceof Projectile) && ((Projectile) e.getDamager()).getShooter() instanceof Player)) return; Player player = ((Player) ((Projectile) e.getDamager()).getShooter()); - Plot plot = PlotManager.getBorderedPlot(e.getDamager().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getDamager().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { 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 a5a1c6e..469854c 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java @@ -45,7 +45,7 @@ public void onBlockInteract(PlayerInteractEvent e) { if (e.getHand() == EquipmentSlot.OFF_HAND) return; if (!e.getClickedBlock().getType().isInteractable()) return; } - Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; try { @@ -75,7 +75,7 @@ public void onChestClick(PlayerInteractEvent e) { if (e.getClickedBlock().getType() != Material.CHEST) return; if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (player.isSneaking() && e.isBlockInHand()) return; - Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.CHEST_ACCESS)) return; @@ -87,7 +87,7 @@ public void onChestClick(PlayerInteractEvent e) { public void onBlockPlace(BlockPlaceEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(e.getBlockPlaced().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlockPlaced().getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.PLACE)) return; @@ -99,7 +99,7 @@ public void onBlockPlace(BlockPlaceEvent e) { public void onBlockBreak(BlockBreakEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(e.getBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.BREAK)) return; @@ -113,7 +113,7 @@ public void onIgniteEvent(BlockIgniteEvent e) { Player player = e.getPlayer(); if (player == null) return; if (e.getIgnitingBlock() == null) return; - Plot plot = PlotManager.getBorderedPlot(e.getIgnitingBlock().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getIgnitingBlock().getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.ITEM_USE)) return; @@ -124,7 +124,7 @@ public void onIgniteEvent(BlockIgniteEvent e) { @EventHandler(priority = EventPriority.LOW) public void onArmorStandChange(PlayerArmorStandManipulateEvent e) { if (e.isCancelled()) return; - Plot plot = PlotManager.getPlot(e.getPlayer().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getPlayer().getLocation()); Player player = e.getPlayer(); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; @@ -138,7 +138,7 @@ public void onItemFrameDamage(HangingBreakByEntityEvent e) { if (e.isCancelled()) return; if (!(e.getRemover() instanceof Player)) return; Player player = (Player) e.getRemover(); - Plot plot = PlotManager.getPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) return; @@ -151,7 +151,7 @@ public void onItemFrameRotate(PlayerInteractEntityEvent e) { if (e.isCancelled()) return; if (!e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.ITEM_USE)) return; @@ -165,7 +165,7 @@ public void onEntityDamage(EntityDamageByEntityEvent e) { if (e.isCancelled()) return; if (!(e.getDamager() instanceof Player)) return; Player player = (Player) e.getDamager(); - Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation()); if (plot == null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) return; @@ -179,7 +179,7 @@ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) { if (!((e.getDamager() instanceof Projectile) && ((Projectile) e.getDamager()).getShooter() instanceof Player)) return; Player player = ((Player) ((Projectile) e.getDamager()).getShooter()); - Plot plot = PlotManager.getBorderedPlot(e.getDamager().getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(e.getDamager().getLocation()); if (plot == null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) return; diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java index 459b961..af26182 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java @@ -1,37 +1,15 @@ package com.modnmetl.virtualrealty.listeners.stake; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.commands.plot.subcommand.StakeSubCommand; -import com.modnmetl.virtualrealty.commands.vrplot.subcommand.RemoveSubCommand; -import com.modnmetl.virtualrealty.enums.ConfirmationType; -import com.modnmetl.virtualrealty.enums.PlotSize; import com.modnmetl.virtualrealty.listeners.VirtualListener; import com.modnmetl.virtualrealty.managers.ConfirmationManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.Confirmation; -import com.modnmetl.virtualrealty.objects.data.PlotItem; -import com.modnmetl.virtualrealty.objects.region.GridStructure; -import com.modnmetl.virtualrealty.utils.multiversion.Chat; -import de.tr7zw.nbtapi.NBTItem; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; -import javax.persistence.Version; -import java.awt.event.KeyEvent; -import java.time.LocalDateTime; -import java.util.AbstractMap; - public class ConfirmationListener extends VirtualListener { public ConfirmationListener(VirtualRealty plugin) { diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java index d7fc2aa..0b02b11 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java @@ -72,15 +72,9 @@ public void onPlayerDeath(PlayerDeathEvent e) { @EventHandler public void onBlockPlace(BlockPlaceEvent e) { Player player = e.getPlayer(); - ItemStack itemInHand; - if (VirtualRealty.legacyVersion) { - itemInHand = player.getItemInHand(); - } else { - itemInHand = player.getInventory().getItemInMainHand(); - } + ItemStack itemInHand = VirtualRealty.legacyVersion ? player.getItemInHand() : player.getInventory().getItemInMainHand(); if (itemInHand.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) && (new NBTItem(itemInHand)).hasKey("vrplot_item")) { e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantPlaceClaimItems); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java index f332a89..e52db8a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java @@ -11,7 +11,11 @@ public class ConfirmationManager { @Getter - public static final List confirmations = new ArrayList<>(); + private static final List confirmations = new ArrayList<>(); + + public static void addConfirmation(Confirmation confirmation) { + confirmations.add(confirmation); + } public static boolean doesConfirmationExist(ConfirmationType confirmationType, UUID player) { return confirmations.stream().anyMatch(confirmation -> confirmation.getConfirmationType() == confirmationType && confirmation.getSender().getUniqueId().equals(player)); diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java index d59aa31..623df28 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java @@ -66,7 +66,7 @@ public void run() { } } catch (IOException ignored) {} VirtualRealty.debug("Registering plots markers.."); - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { resetPlotMarker(plot); } VirtualRealty.debug("Registered plots markers"); diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java index 391ea13..480196f 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java @@ -34,7 +34,7 @@ public void registerMetrics() { int largePlots = 0; int customPlots = 0; int areas = 0; - for (Plot plot : PlotManager.getPlots()) { + for (Plot plot : PlotManager.getInstance().getPlots()) { switch (plot.getPlotSize()) { case SMALL: { smallPlots++; diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java index 2e0ab16..0a356e7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java @@ -19,12 +19,23 @@ import java.sql.SQLException; import java.util.*; +@Data public class PlotManager { - @Getter - private static final Set plots = new LinkedHashSet<>(); + private final VirtualRealty plugin; - public static void loadPlots() { + private final Set plots; + + private final List plotMembers; + + public PlotManager(VirtualRealty plugin) { + this.plugin = plugin; + this.plots = new LinkedHashSet<>(); + this.plotMembers = new ArrayList<>(); + } + + + public void loadPlots() { try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`"); ResultSet rs = ps.executeQuery()) { plots.clear(); while (rs.next()) { @@ -35,15 +46,30 @@ public static void loadPlots() { } } - public static void loadMembers() { + public void loadMembers() { try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`"); ResultSet rs = ps.executeQuery()) { - while (rs.next()) new PlotMember(rs); + while (rs.next()) { + plotMembers.add(new PlotMember(rs)); + } + checkDupes(); } catch (Exception e) { e.printStackTrace(); } } - public static Plot createPlot(Location creationLocation, PlotSize plotSize, int length, int height, int width, boolean natural) { + public void checkDupes() { + HashMap dupes = new HashMap<>(); + for (PlotMember plotMember : plotMembers) { + if (dupes.containsKey(plotMember.getUuid()) && dupes.get(plotMember.getUuid()) == plotMember.getPlot().getID()) { + VirtualRealty.debug("Found duped plot member: " + plotMember.getUuid() + " | " + plotMember.getPlot().getID() + " - Removing.."); + plotMember.getPlot().removeMember(plotMember); + } else { + dupes.put(plotMember.getUuid(), plotMember.getPlot().getID()); + } + } + } + + public Plot createPlot(Location creationLocation, PlotSize plotSize, int length, int height, int width, boolean natural) { Plot plot = new Plot(creationLocation, Material.matchMaterial(VirtualRealty.legacyVersion ? "GRASS" : "GRASS_BLOCK"), Material.matchMaterial(VirtualRealty.legacyVersion ? "STEP" : "STONE_BRICK_SLAB"), plotSize, length, width, height, natural); plots.add(plot); long time = System.currentTimeMillis(); @@ -52,7 +78,7 @@ public static Plot createPlot(Location creationLocation, PlotSize plotSize, int return plot; } - public static Plot getPlot(int ID) { + public Plot getPlot(int ID) { for (Plot plot : plots) { if (plot.getID() == ID) { return plot; @@ -61,7 +87,7 @@ public static Plot getPlot(int ID) { return null; } - public static List getPlots(String world) { + public List getPlots(String world) { List newPlots = new LinkedList<>(); for (Plot plot : plots) { if (plot.getCreatedWorldString().equals(world)) newPlots.add(plot); @@ -69,7 +95,7 @@ public static List getPlots(String world) { return newPlots; } - public static HashMap getPlots(UUID owner) { + public HashMap getPlots(UUID owner) { HashMap plotHashMap = new HashMap<>(); for (Plot plot : plots) { if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(owner)) { @@ -79,7 +105,7 @@ public static HashMap getPlots(UUID owner) { return plotHashMap; } - public static HashMap getAccessPlots(UUID player) { + public HashMap getAccessPlots(UUID player) { HashMap plotHashMap = new HashMap<>(); for (Plot plot : plots) { if (plot.getMember(player) != null || (plot.getOwnedBy() != null && plot.getPlotOwner().getUniqueId() == player)) { @@ -89,17 +115,17 @@ public static HashMap getAccessPlots(UUID player) { return plotHashMap; } - public static int getPlotMinID() { + public int getPlotMinID() { return plots.isEmpty() ? 0 : plots.stream().findFirst().get().getID(); } - public static int getPlotMaxID() { - Plot[] plotArray = PlotManager.plots.toArray(new Plot[0]); + public int getPlotMaxID() { + Plot[] plotArray = plots.toArray(new Plot[0]); Plot lastPlot = plotArray[plotArray.length - 1]; return lastPlot.getID(); } - public static List getPlayerPlots(UUID owner) { + public List getPlayerPlots(UUID owner) { LinkedList playerPlots = new LinkedList<>(); for (Plot plot : plots) { if (plot.getOwnedBy() != null) { @@ -111,7 +137,7 @@ public static List getPlayerPlots(UUID owner) { return playerPlots; } - public static Plot getPlot(Location location) { + public Plot getPlot(Location location) { BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); for (Plot plot : plots) { Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); @@ -122,17 +148,17 @@ public static Plot getPlot(Location location) { return null; } - public static void removePlotFromList(Plot plot) { + public void removePlotFromList(Plot plot) { plots.remove(plot); } - public static boolean isLocationInPlot(Location location, Plot plot) { + public boolean isLocationInPlot(Location location, Plot plot) { BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); return region.isIn(newVector, location.getWorld()); } - public static Plot getBorderedPlot(Location location) { + public Plot getBorderedPlot(Location location) { BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); for (Plot plot : plots) { Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld()); @@ -143,10 +169,14 @@ public static Plot getBorderedPlot(Location location) { return null; } - public static boolean isLocationInBorderedPlot(Location location, Plot plot) { + public boolean isLocationInBorderedPlot(Location location, Plot plot) { BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld()); return region.isIn(newVector, plot.getCreatedWorld()); } + public static PlotManager getInstance() { + return VirtualRealty.getInstance().getPlotManager(); + } + } \ No newline at end of file diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java index 5834c50..3a75326 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java @@ -57,7 +57,7 @@ public class Plot { private LocalDateTime createdAt; public Plot(Location location, Material floorMaterial, Material borderMaterial, PlotSize plotSize, int length, int width, int height, boolean natural) { - this.ID = PlotManager.getPlots().isEmpty() ? 10000 : PlotManager.getPlotMaxID() + 1; + this.ID = PlotManager.getInstance().getPlots().isEmpty() ? 10000 : PlotManager.getInstance().getPlotMaxID() + 1; this.ownedBy = null; this.members = new LinkedList<>(); this.nonMemberPermissions = new HashSet<>(VirtualRealty.getPermissions().getDefaultNonMemberPlotPerms()); @@ -236,10 +236,7 @@ public int getZMax() { public void setOwnedBy(UUID ownedBy) { modified(); this.ownedBy = ownedBy; - PlotMember plotMember = getMember(ownedBy); - if (plotMember != null) { - removeMember(plotMember); - } + members.clear(); updateMarker(); } @@ -478,25 +475,25 @@ public void prepareBlocks(Location location, boolean natural) { case SOUTH: { location1 = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() - 1); location2 = new Location(location.getWorld(), location.getBlockX() - width, location.getBlockY() + height, location.getBlockZ() + length); - SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock())); + SchematicUtil.save(ID, location1.getBlock(), location2.getBlock()); break; } case WEST: { location1 = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() + 1); location2 = new Location(location.getWorld(), location.getBlockX() - length, location.getBlockY() + height, location.getBlockZ() - width); - SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock())); + SchematicUtil.save(ID, location1.getBlock(), location2.getBlock()); break; } case NORTH: { location1 = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() - 10, location.getBlockZ() + 1); location2 = new Location(location.getWorld(), location.getBlockX() + width, location.getBlockY() + height, location.getBlockZ() - length); - SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock())); + SchematicUtil.save(ID, location1.getBlock(), location2.getBlock()); break; } case EAST: { location1 = new Location(location.getWorld(), location.getBlockX() + length, location.getBlockY() - 10, location.getBlockZ() - 1); location2 = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() + height, location.getBlockZ() + width); - SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock())); + SchematicUtil.save(ID, location1.getBlock(), location2.getBlock()); break; } } @@ -599,7 +596,6 @@ public void unloadPlot() { } else { long time = System.currentTimeMillis(); SchematicUtil.paste(ID); - VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms"); } } @@ -716,7 +712,7 @@ public void remove(CommandSender sender) { } catch (Exception e) { e.printStackTrace(); } - PlotManager.removePlotFromList(this); + PlotManager.getInstance().removePlotFromList(this); VirtualRealty.debug("Removed plot #" + this.ID); } diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java index 3c975c8..94cd20b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java @@ -38,12 +38,9 @@ public class PlotItem { private UUID uuid; public ItemStack getItemStack() { - ItemBuilder itemBuilder; - if (uuid == null) { - itemBuilder = new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b")); - } else { - itemBuilder = new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b", uuid)); - } + ItemBuilder itemBuilder = (uuid == null) + ? new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b")) + : new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b", uuid)); switch (itemType) { case CLAIM: { itemBuilder diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java index 386cac5..2331247 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java @@ -40,7 +40,7 @@ public PlotMember(UUID uuid, Plot plot) { @SneakyThrows public PlotMember(ResultSet rs) { this.uuid = UUID.fromString(rs.getString("uuid")); - Plot plot = PlotManager.getPlot(rs.getInt("plot")); + Plot plot = PlotManager.getInstance().getPlot(rs.getInt("plot")); this.plot = plot; this.selectedGameMode = GameMode.valueOf(rs.getString("selectedGameMode")); Set plotPermissions = new HashSet<>(); 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 1537d2b..f02d0d9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java @@ -23,6 +23,8 @@ @Data public class GridStructure { + public static final long DISPLAY_TICKS = 20 * 10; + public static final HashMap> ACTIVE_GRIDS = new HashMap<>(); private final Player viewer; @@ -69,7 +71,7 @@ public void preview(Location playerPreviewLocation, boolean visualization, boole if (!VirtualRealty.legacyVersion) maxDistance = viewer.getClientViewDistance() * 16; changedBlocks.clear(); - Plot plot = PlotManager.getPlot(cuboidId); + Plot plot = PlotManager.getInstance().getPlot(cuboidId); LinkedList blocks = new LinkedList<>(); LinkedList borderBlocks = new LinkedList<>(); Direction direction = Direction.byYaw(previewLocation.getYaw()); @@ -109,10 +111,7 @@ public void preview(Location playerPreviewLocation, boolean visualization, boole default: throw new IllegalStateException("Unexpected value: " + direction); } - Location distanceCalculateLoc = previewLocation; - if (playerPreviewLocation != null) { - distanceCalculateLoc = playerPreviewLocation; - } + Location distanceCalculateLoc = playerPreviewLocation != null ? playerPreviewLocation : previewLocation; 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) { @@ -213,27 +212,35 @@ public void removeGrid() { for (VirtualBlock changedBlock : changedBlocks) { Block changedBukkitBlock = changedBlock.getBlock(getCreatedWorld()); if (VirtualRealty.legacyVersion) { - viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getType(), changedBukkitBlock.getData()); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getType(), changedBukkitBlock.getData()); + }); } else { - viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getBlockData()); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getBlockData()); + }); } } } private void swapBlocks(LinkedList blocks, boolean collidingArea) { - Plot plot = PlotManager.getPlot(previewLocation); + Plot plot = PlotManager.getInstance().getPlot(previewLocation); for (Block block : blocks) { Location blockLocation = block.getLocation(); VirtualBlock convertedBlock; if (VirtualRealty.legacyVersion) { convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getType().getId(), block.getData()); - viewer.sendBlockChange(blockLocation, Objects.requireNonNull(Material.matchMaterial("STAINED_GLASS")), ((plot != null && plot.getID() == cuboidId) ? (byte)1 : collidingArea ? (byte)14 : (byte)5)); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + viewer.sendBlockChange(blockLocation, Objects.requireNonNull(Material.matchMaterial("STAINED_GLASS")), ((plot != null && plot.getID() == cuboidId) ? (byte) 1 : collidingArea ? (byte) 14 : (byte) 5)); + }); } else { convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getBlockData().getAsString()); BlockData greenBlockData = Material.LIME_STAINED_GLASS.createBlockData(); BlockData redBlockData = Material.RED_STAINED_GLASS.createBlockData(); BlockData orangeBlockData = Material.ORANGE_STAINED_GLASS.createBlockData(); - viewer.sendBlockChange(blockLocation, ((plot != null && plot.getID() == cuboidId) ? orangeBlockData : collidingArea ? redBlockData : greenBlockData)); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + viewer.sendBlockChange(blockLocation, ((plot != null && plot.getID() == cuboidId) ? orangeBlockData : collidingArea ? redBlockData : greenBlockData)); + }); } changedBlocks.add(convertedBlock); } diff --git a/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java index 2a929a9..1073fb5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java +++ b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java @@ -101,7 +101,7 @@ public boolean canRegister(){ public String onPlaceholderRequest(Player player, @NotNull String identifier){ if(player == null) return ""; - Plot plot = PlotManager.getBorderedPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getBorderedPlot(player.getLocation()); if (identifier.equals("plot_id")) { if (plot == null) return ""; return String.valueOf(plot.getID()); diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java index f8a61b4..8fa21c7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java @@ -53,7 +53,7 @@ public static boolean isCollidingWithBedrock(Cuboid cuboid) { public static boolean isCollidingWithAnotherPlot(Cuboid cuboid) { long time = System.currentTimeMillis(); - for (Plot plot : PlotManager.getPlots(cuboid.getWorld().getName())) { + for (Plot plot : PlotManager.getInstance().getPlots(cuboid.getWorld().getName())) { for (BlockVector2 blockVector2 : plot.getCuboid().getFlatRegion()) { if (cuboid.isIn(blockVector2, cuboid.getWorld(), VirtualRealty.getPluginConfiguration().plotSpacing)) { VirtualRealty.debug("Collision checked! (Found) " + (System.currentTimeMillis() - time) + " ms | Spacing: " + VirtualRealty.getPluginConfiguration().plotSpacing); diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java index d5164a1..f349c82 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java @@ -26,7 +26,7 @@ public static void paste(int plotID, Location l) { long time = System.currentTimeMillis(); String[] blocks = load(plotID); if (blocks == null) return; - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); Location location = new Location(plot.getCreatedWorld(), plot.getBorderBottomLeftCorner().getBlockX(), plot.getBorderBottomLeftCorner().getBlockY(), plot.getBorderBottomLeftCorner().getBlockZ()); Location location2 = new Location(plot.getCreatedWorld(), plot.getBorderTopRightCorner().getBlockX(), plot.getBorderTopRightCorner().getBlockY(), plot.getBorderTopRightCorner().getBlockZ()); Block pos1Block = location.getBlock(); 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 e6f728e..590398a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java @@ -4,6 +4,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; +import lombok.Getter; import lombok.SneakyThrows; import org.apache.commons.lang.SerializationUtils; import org.bukkit.Bukkit; @@ -11,10 +12,15 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.scheduler.BukkitRunnable; +import javax.swing.*; import java.io.*; import java.lang.reflect.Method; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public class SchematicUtil { @@ -52,7 +58,7 @@ public static LinkedList getStructure(Block block, Block block2) { public static void paste(int plotID) { List blocks = load(plotID); if (blocks == null) return; - Plot plot = PlotManager.getPlot(plotID); + Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) return; long time = System.currentTimeMillis(); Location location = plot.getBorderBottomLeftCorner().toLocation(plot.getCreatedWorld()); @@ -67,50 +73,99 @@ public static void paste(int plotID) { int maxY = Math.max(pos1Block.getY(), pos2Block.getY()); World world = location.getWorld(); if (world == null) return; - int i = 0; - for (int x = minX; x <= maxX; x++) { - for (int z = minZ; z <= maxZ; z++) { - for (int y = maxY; y > minY; y--) { - Block block = world.getBlockAt(x, y, z); + List virtualLocations = new ArrayList<>(); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + for (int x = minX; x <= maxX; x++) { + for (int z = minZ; z <= maxZ; z++) { + for (int y = maxY; y > minY; y--) { + virtualLocations.add(new VirtualLocation(x,y,z)); + } + } + } + Bukkit.getScheduler().scheduleSyncDelayedTask(VirtualRealty.getInstance(), () -> { + int i = 0; + for (VirtualLocation virtualLocation : virtualLocations) { + Block block = world.getBlockAt(virtualLocation.getX(), virtualLocation.getY(), virtualLocation.getZ()); if (block.getType() == Material.AIR) continue; block.setType(Material.AIR); i++; } - } + VirtualRealty.debug("Pasted " + i + " air blocks in: " + (System.currentTimeMillis() - time) + " ms"); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + List> chunks = chunkArrayList(blocks, 15000); + Bukkit.getScheduler().scheduleSyncDelayedTask(VirtualRealty.getInstance(), () -> { + for (int j = 0; j < chunks.size(); j++) { + int finalJ = j; + new BukkitRunnable() { + @Override + public void run() { + List virtualBlocks = chunks.get(finalJ); + for (VirtualBlock block : virtualBlocks) { + Location blockLocation = new Location(plot.getCreatedWorld(), block.getX(), block.getY(), block.getZ()); + Block oldBlock = blockLocation.getBlock(); + if (VirtualRealty.legacyVersion) { + try { + oldBlock.setType(VMaterial.getMaterial(block.getMaterial())); + Method m = Block.class.getDeclaredMethod("setData", byte.class); + m.setAccessible(true); + m.invoke(oldBlock, block.getData()); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + oldBlock.setBlockData( + Bukkit.createBlockData("minecraft:" + block.getBlockData()), + false + ); + } + } + VirtualRealty.debug("Pasted chunk #" + finalJ); + } + }.runTaskLater(VirtualRealty.getInstance(), 2L * finalJ); + } + VirtualRealty.debug("Pasted " + blocks.size() + " blocks in: " + (System.currentTimeMillis() - time) + " ms"); + VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms"); + }); + }); + }); + }); + } + + private static ArrayList> chunkArrayList(List arrayToChunk, int chunkSize) { + ArrayList> chunkList = new ArrayList<>(); + int guide = arrayToChunk.size(); + int index = 0; + int tale = chunkSize; + while (tale < arrayToChunk.size()){ + chunkList.add(arrayToChunk.subList(index, tale)); + guide = guide - chunkSize; + index = index + chunkSize; + tale = tale + chunkSize; } - VirtualRealty.debug("Pasted " + i + " air blocks in: " + (System.currentTimeMillis() - time) + " ms"); - for (VirtualBlock block : blocks) { - Location blockLocation = new Location(plot.getCreatedWorld(), block.getX(), block.getY(), block.getZ()); - Block oldBlock = blockLocation.getBlock(); - if (VirtualRealty.legacyVersion) { - try { - oldBlock.setType(VMaterial.getMaterial(block.getMaterial())); - Method m = Block.class.getDeclaredMethod("setData", byte.class); - m.setAccessible(true); - m.invoke(oldBlock, block.getData()); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - oldBlock.setBlockData( - Bukkit.createBlockData("minecraft:" + - block.getBlockData()), false); - } + if (guide >0) { + chunkList.add(arrayToChunk.subList(index, index + guide)); } - VirtualRealty.debug("Pasted " + blocks.size() + " blocks in: " + (System.currentTimeMillis() - time) + " ms"); + return chunkList; } @SneakyThrows - public static void save(int plotID, LinkedList blocks) { + public static void save(int plotID, Block block1, Block block2) { long time = System.currentTimeMillis(); - File f = new File(VirtualRealty.plotsSchemaFolder, (VirtualRealty.legacyVersion ? LEGACY_REGION_PREFIX : REGION_PREFIX) + plotID + REGION_SUFFIX); - long serialization = System.currentTimeMillis(); - byte[] data = SerializationUtils.serialize(blocks); - VirtualRealty.debug("Serialized in: " + (System.currentTimeMillis() - serialization) + " ms"); - long compression = System.currentTimeMillis(); - new DataCompressor().compressData(data, f); - VirtualRealty.debug("Compressed in: " + (System.currentTimeMillis() - compression) + " ms"); - VirtualRealty.debug("Region saved in: " + (System.currentTimeMillis() - time) + " ms"); + LinkedList blocks = SchematicUtil.getStructure(block1, block2); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + File f = new File(VirtualRealty.plotsSchemaFolder, (VirtualRealty.legacyVersion ? LEGACY_REGION_PREFIX : REGION_PREFIX) + plotID + REGION_SUFFIX); + long serialization = System.currentTimeMillis(); + byte[] data = SerializationUtils.serialize(blocks); + VirtualRealty.debug("Serialized in: " + (System.currentTimeMillis() - serialization) + " ms"); + long compression = System.currentTimeMillis(); + try { + new DataCompressor().compressData(data, f); + } catch (IOException e) { + throw new RuntimeException(e); + } + VirtualRealty.debug("Compressed in: " + (System.currentTimeMillis() - compression) + " ms"); + VirtualRealty.debug("Region saved in: " + (System.currentTimeMillis() - time) + " ms"); + }); } @SneakyThrows diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualLocation.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualLocation.java new file mode 100644 index 0000000..be66d50 --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualLocation.java @@ -0,0 +1,27 @@ +package com.modnmetl.virtualrealty.utils.data; + +import lombok.Data; +import org.bukkit.World; +import org.bukkit.block.Block; + +import java.io.Serializable; + +@Data +public class VirtualLocation implements Serializable { + + private int x; + private int y; + private int z; + + public VirtualLocation(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Block getBlock(World world) { + return world.getBlockAt(x,y,z); + } + + +} From 55cc3094fd1372de92bee87faebad05b00f3d150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Thu, 3 Nov 2022 20:28:56 +0100 Subject: [PATCH 05/10] v2.5.0 - pre-release improvements --- .../modnmetl/virtualrealty/VirtualRealty.java | 2 +- .../virtualrealty/commands/SubCommand.java | 16 +- .../commands/plot/PlotCommand.java | 9 +- .../plot/subcommand/AddSubCommand.java | 26 +- .../plot/subcommand/InfoSubCommand.java | 23 +- .../plot/subcommand/KickSubCommand.java | 19 +- .../plot/subcommand/ListSubCommand.java | 30 +- .../plot/subcommand/TpSubCommand.java | 11 +- .../vrplot/subcommand/AssignSubCommand.java | 12 +- .../vrplot/subcommand/CreateSubCommand.java | 344 +++++++++--------- .../vrplot/subcommand/ListSubCommand.java | 5 +- .../vrplot/subcommand/RemoveSubCommand.java | 59 +-- .../vrplot/subcommand/VersionSubCommand.java | 3 +- .../configs/PluginConfiguration.java | 5 +- .../virtualrealty/enums/Direction.java | 2 +- .../{WorldsSetting.java => WorldSetting.java} | 2 +- .../player/PlayerActionListener.java | 40 +- .../virtualrealty/managers/DynmapManager.java | 14 +- .../virtualrealty/managers/PlotManager.java | 5 +- .../virtualrealty/objects/Executable.java | 2 - .../modnmetl/virtualrealty/objects/Plot.java | 115 +++--- .../objects/data/Confirmation.java | 3 +- .../virtualrealty/utils/data/SkullUtil.java | 5 +- .../utils/{ => loader}/Loader.java | 2 +- .../utils/multiversion/Chat.java | 24 -- .../utils/multiversion/ChatMessage.java | 43 +++ 26 files changed, 423 insertions(+), 398 deletions(-) rename src/main/java/com/modnmetl/virtualrealty/enums/{WorldsSetting.java => WorldSetting.java} (75%) rename src/main/java/com/modnmetl/virtualrealty/utils/{ => loader}/Loader.java (98%) delete mode 100644 src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java create mode 100644 src/main/java/com/modnmetl/virtualrealty/utils/multiversion/ChatMessage.java diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index 536b6c0..f69fac0 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -22,7 +22,7 @@ import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.registry.VirtualPlaceholders; import com.modnmetl.virtualrealty.sql.Database; -import com.modnmetl.virtualrealty.utils.Loader; +import com.modnmetl.virtualrealty.utils.loader.Loader; import com.modnmetl.virtualrealty.utils.configuration.ConfigurationFactory; import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; import com.modnmetl.virtualrealty.utils.UpdateChecker; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java index a1d71ff..cd77dc5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java @@ -1,10 +1,10 @@ package com.modnmetl.virtualrealty.commands; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.WorldsSetting; import com.modnmetl.virtualrealty.enums.commands.CommandType; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.Getter; import lombok.Setter; import lombok.SneakyThrows; @@ -62,7 +62,7 @@ public SubCommand(CommandSender sender, Command command, String label, String[] public void assertPlayer() throws FailedCommandException { if (!(commandSender instanceof Player)) { - commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cmdOnlyPlayers); + ChatMessage.of(VirtualRealty.getMessages().cmdOnlyPlayers).sendWithPrefix(commandSender); throw new FailedCommandException(); } } @@ -96,9 +96,9 @@ public String getDefaultPermission() { public void assertPermission() throws InsufficientPermissionsException { if (!commandSender.hasPermission(getDefaultPermission())) { if (commandSender.isOp()) { - commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", getDefaultPermission())); + ChatMessage.of(VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", getDefaultPermission())).sendWithPrefix(commandSender); } else { - commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", getDefaultPermission())); + ChatMessage.of(VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", getDefaultPermission())).sendWithPrefix(commandSender); } throw new InsufficientPermissionsException(); } @@ -107,9 +107,9 @@ public void assertPermission() throws InsufficientPermissionsException { public void assertPermission(String permission) throws InsufficientPermissionsException { if (!commandSender.hasPermission(permission)) { if (commandSender.isOp()) { - commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", permission)); + ChatMessage.of(VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", permission)).sendWithPrefix(commandSender); } else { - commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", permission)); + ChatMessage.of(VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", permission)).sendWithPrefix(commandSender); } throw new InsufficientPermissionsException(); } @@ -121,7 +121,9 @@ public boolean isBypass() { public void printHelp() throws FailedCommandException { for (String s : HELP_LIST) { - commandSender.sendMessage(s.replaceAll("%command%", getSubCommandName())); + String message = s.replaceAll("%command%", getSubCommandName()); + if (message.contains("%command%")) + ChatMessage.of(message).send(commandSender); } throw new FailedCommandException(); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java index bc6b388..3b9c5f4 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.commands.SubCommand; import com.modnmetl.virtualrealty.enums.commands.CommandType; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.Command; @@ -52,10 +53,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St try { Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getLoader()); } catch (Exception e) { - sender.sendMessage("§aThis function is available with a valid license key"); + ChatMessage.of("§aThis function is available with a valid license key").send(sender); TextComponent linkComponent = new TextComponent("§fhttps://modnmetl.com/"); linkComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://modnmetl.com/category/virtual-realty-plugin-61eef16fe2eeab00116a3e64")); - sender.spigot().sendMessage(new TextComponent("§aPlease visit "), linkComponent, new TextComponent(" §ato purchase one")); + ChatMessage.of(new TextComponent("§aPlease visit "), linkComponent, new TextComponent(" §ato purchase one")).send(sender); return false; } } @@ -72,8 +73,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St e.printStackTrace(); } else { if (e.getCause() instanceof FailedCommandException) return false; - sender.sendMessage("§cAn error occurred while executing the command."); - sender.sendMessage("§cCheck console for details."); + ChatMessage.of("§cAn error occurred while executing the command.").send(sender); + ChatMessage.of("§cCheck console for details.").send(sender); VirtualRealty.getInstance().getLogger().log(Level.SEVERE, "Failed command execution | Command Sender: " + sender.getName()); VirtualRealty.getInstance().getLogger().log(Level.SEVERE, "To print more details add \"--error\" argument at the end of the command."); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java index 2a97e8e..39fc46b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java @@ -7,6 +7,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.PlotMember; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -46,53 +47,50 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(player); return; } OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[2]); if (offlinePlayer.getFirstPlayed() == 0) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(player); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } if (!plot.hasMembershipAccess(player.getUniqueId())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot); + ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender); return; } PlotMember plotMember = plot.getMember(player.getUniqueId()); if (plotMember != null) { if (!plotMember.hasManagementPermission(ManagementPermission.ADD_MEMBER)) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); + ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender); return; } } else { if (!plot.getOwnedBy().equals(player.getUniqueId())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); + ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender); return; } } if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + ChatMessage.of(VirtualRealty.getMessages().ownershipExpired).sendWithPrefix(sender); return; } if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) { - if (plot.getOwnedBy().equals(player.getUniqueId())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantAddYourself); - } else { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().alreadyInMembers); - } + boolean equals = plot.getOwnedBy().equals(player.getUniqueId()); + ChatMessage.of(equals ? VirtualRealty.getMessages().cantAddYourself : VirtualRealty.getMessages().alreadyInMembers).sendWithPrefix(sender); return; } if (plot.getMember(offlinePlayer.getUniqueId()) != null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().alreadyInMembers); + ChatMessage.of(VirtualRealty.getMessages().alreadyInMembers).sendWithPrefix(sender); return; } plot.addMember(offlinePlayer.getUniqueId()); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerAdd.replaceAll("%player%", offlinePlayer.getName())); + ChatMessage.of(VirtualRealty.getMessages().playerAdd.replaceAll("%player%", offlinePlayer.getName())).sendWithPrefix(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java index defa1f2..466ab97 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -39,21 +40,21 @@ public void exec(CommandSender sender, Command command, String label, String[] a private void printInfo(CommandSender sender, Plot plot) { LocalDateTime localDateTime = plot.getOwnedUntilDate(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); - sender.sendMessage(" "); - sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - sender.sendMessage(" §7Plot ID §8§l‣ §f" + plot.getID()); - sender.sendMessage(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable")); + ChatMessage.of(" ").send(sender); + ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").send(sender); + ChatMessage.of(" §7Plot ID §8§l‣ §f" + plot.getID()).send(sender); + ChatMessage.of(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable")).send(sender); if (plot.getMembers().size() != 0) { - sender.sendMessage(" §7Members §8§l↴"); + ChatMessage.of(" §7Members §8§l↴").send(sender); for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) { - sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()); + ChatMessage.of(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()).send(sender); } } - sender.sendMessage(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime)); - sender.sendMessage(" §7Size §8§l‣ §f" + plot.getPlotSize()); - sender.sendMessage(" §7Length §8§l‣ §f" + plot.getLength()); - sender.sendMessage(" §7Height §8§l‣ §f" + plot.getHeight()); - sender.sendMessage(" §7Width §8§l‣ §f" + plot.getWidth()); + ChatMessage.of(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime)).send(sender); + ChatMessage.of(" §7Size §8§l‣ §f" + plot.getPlotSize()).send(sender); + ChatMessage.of(" §7Length §8§l‣ §f" + plot.getLength()).send(sender); + ChatMessage.of(" §7Height §8§l‣ §f" + plot.getHeight()).send(sender); + ChatMessage.of(" §7Width §8§l‣ §f" + plot.getWidth()).send(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java index ae2dcf5..b3d2a1d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java @@ -7,6 +7,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.PlotMember; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -45,54 +46,58 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return; } OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[2]); if (offlinePlayer.getName() == null) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; } if (!plot.hasMembershipAccess(player.getUniqueId())) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot); return; } PlotMember plotMember = plot.getMember(player.getUniqueId()); if (plotMember != null) { if (!plotMember.hasManagementPermission(ManagementPermission.KICK_MEMBER)) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); return; } } else { if (!plot.getOwnedBy().equals(player.getUniqueId())) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); return; } } if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); return; } if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) { - if (plot.getOwnedBy().equals(player.getUniqueId())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickYourself); - } else { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickOwner); - } + boolean equals = plot.getOwnedBy().equals(player.getUniqueId()); + ChatMessage.of(equals ? VirtualRealty.getMessages().cantKickYourself : VirtualRealty.getMessages().cantKickOwner).sendWithPrefix(sender); return; } PlotMember member = plot.getMember(offlinePlayer.getUniqueId()); if (member == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender); return; } plot.removeMember(member); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerKick.replaceAll("%player%", offlinePlayer.getName())); + ChatMessage.of(VirtualRealty.getMessages().playerKick.replaceAll("%player%", offlinePlayer.getName())).sendWithPrefix(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java index 7cc3315..2b248e9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; @@ -47,12 +48,12 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlayerPlotsFound); return; } - sender.sendMessage(" "); - sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - sender.sendMessage(" "); + ChatMessage.of(" ").send(sender); + ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").send(sender); + ChatMessage.of(" ").send(sender); if (hasPlot) { - sender.sendMessage("§7§m "); - sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |"); + ChatMessage.of("§7§m ").send(sender); + ChatMessage.of("§7| §a§l§oID§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |").send(sender); for (Plot plot : PlotManager.getInstance().getPlots()) { if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { LocalDateTime localDateTime = plot.getOwnedUntilDate(); @@ -68,17 +69,17 @@ public void exec(CommandSender sender, Command command, String label, String[] a size.append(" "); } BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + (isOwned ? " " : "") + dateTimeFormatter.format(localDateTime) + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString()); - sender.sendMessage(textComponent.toLegacyText()); + ChatMessage.of(textComponent.toLegacyText()).send(sender); } } - sender.sendMessage("§7§m "); + ChatMessage.of("§7§m ").send(sender); } if (isMember) { - sender.sendMessage(" "); - sender.sendMessage("§7 §fMember of §8§l↴"); - sender.sendMessage(" "); - sender.sendMessage("§7§m "); - sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |"); + ChatMessage.of(" ").send(sender); + ChatMessage.of("§7 §fMember of §8§l↴").send(sender); + ChatMessage.of(" ").send(sender); + ChatMessage.of("§7§m ").send(sender); + ChatMessage.of("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |").send(sender); for (Plot plot : PlotManager.getInstance().getPlots()) { if (plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId()) && plot.hasMembershipAccess(player.getUniqueId())) { StringBuilder ownedBy = new StringBuilder(); @@ -92,11 +93,12 @@ public void exec(CommandSender sender, Command command, String label, String[] a size.append(" "); } BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + (isOwned ? " " : "") + ownedBy + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString()); - sender.sendMessage(textComponent.toLegacyText()); + ChatMessage.of(textComponent.toLegacyText()).send(sender); } } - sender.sendMessage("§7§m "); + ChatMessage.of("§7§m ").send(sender); } + } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java index 5bea990..e9b391b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -40,24 +41,24 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } if (!plot.hasMembershipAccess(player.getUniqueId())) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot); + ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender); return; } if (plot.isOwnershipExpired()) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + ChatMessage.of(VirtualRealty.getMessages().ownershipExpired).sendWithPrefix(sender); return; } plot.teleportPlayer(player); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot); + ChatMessage.of(VirtualRealty.getMessages().teleportedToPlot).sendWithPrefix(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java index 26ac896..ef29c16 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.UUIDUtils; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -45,7 +46,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); return; } try { @@ -55,16 +56,16 @@ public void exec(CommandSender sender, Command command, String label, String[] a offlinePlayer = Bukkit.getOfflinePlayer(args[2]); } if (offlinePlayer.getName() == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender); return; } } catch (NullPointerException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } if (sender instanceof Player) { @@ -75,7 +76,8 @@ public void exec(CommandSender sender, Command command, String label, String[] a plot.setAssignedBy("SHOP_PURCHASE"); } plot.setOwnedBy(offlinePlayer.getUniqueId()); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().assignedToBy.replaceAll("%assigned_to%", offlinePlayer.getName()).replaceAll("%assigned_by%", sender.getName())); + String text = VirtualRealty.getMessages().assignedToBy.replaceAll("%assigned_to%", offlinePlayer.getName()).replaceAll("%assigned_by%", sender.getName()); + ChatMessage.of(text).sendWithPrefix(sender); plot.update(); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java index 7fa7449..0896a02 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java @@ -10,7 +10,7 @@ import com.modnmetl.virtualrealty.objects.region.Cuboid; import com.modnmetl.virtualrealty.objects.region.GridStructure; import com.modnmetl.virtualrealty.utils.RegionUtil; -import com.modnmetl.virtualrealty.utils.multiversion.Chat; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; @@ -59,199 +59,104 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotSize = PlotSize.valueOf(args[1].toUpperCase()); } catch (IllegalArgumentException ignored) {} - if (plotSize != null) { - if (plotSize == PlotSize.AREA) { - int length = plotSize.getLength(); - int height = plotSize.getHeight(); - int width = plotSize.getWidth(); - if (args.length > 2) { - try { - length = Integer.parseInt(args[2]); - height = Integer.parseInt(args[3]); - width = Integer.parseInt(args[4]); - } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); - return; - } - } - if (length < 1 || width < 1 || height < 1) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().graterThenZero); + if (plotSize == null) { + ChatMessage.of(VirtualRealty.getMessages().sizeNotRecognised).sendWithPrefix(sender); + return; + } + if (plotSize == PlotSize.AREA) { + int length = plotSize.getLength(); + int height = plotSize.getHeight(); + int width = plotSize.getWidth(); + if (args.length > 2) { + try { + length = Integer.parseInt(args[2]); + height = Integer.parseInt(args[3]); + width = Integer.parseInt(args[4]); + } catch (IllegalArgumentException e) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); return; } - Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width); - if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting); - } else { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); - long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.AREA, length, height, width, true); - long timeEnd = System.currentTimeMillis(); - BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); - BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); - BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart))); - textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))})); - textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); - textComponent.addExtra(textComponent2); - textComponent.addExtra(textComponent3); - new Chat(textComponent).sendTo(player); - new BukkitRunnable() { - @Override - public void run() { - new GridStructure( - player, - plot.getLength(), - plot.getHeight(), - plot.getWidth(), - plot.getID(), - ((Player) sender).getWorld(), - GridStructure.DISPLAY_TICKS, - plot.getCreatedLocation() - ).preview(true, false); - } - }.runTaskLater(VirtualRealty.getInstance(), 20); - } - } else { - Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth()); - if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting); - } else { - boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural")); - Material floorMaterial = null; - byte floorData = 0; - Material borderMaterial = null; - byte borderData = 0; - if (args.length >= 3 && !natural) { - try { - floorMaterial = VMaterial.getMaterial(args[2].split(":")[0].toUpperCase()); - if (floorMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); - return; - } - } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); - return; - } - if (args[2].split(":").length == 2) { - floorData = Byte.parseByte(args[2].split(":")[1]); - } - } - if (args.length >= 4) { - try { - borderMaterial = VMaterial.getMaterial(args[3].split(":")[0].toUpperCase()); - if (borderMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); - return; - } - } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); - return; - } - if (args[3].split(":").length == 2) { - borderData = Byte.parseByte(args[3].split(":")[1]); - } - } - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); - long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.getInstance().createPlot(location, plotSize, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), natural); - if (!natural) { - if (floorMaterial != null) { - plot.setFloorMaterial(floorMaterial, floorData); - } - if (borderMaterial != null) { - plot.setBorderMaterial(borderMaterial, borderData); - } - } - long timeEnd = System.currentTimeMillis(); - BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); - BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); - BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart))); - textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))})); - textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); - textComponent.addExtra(textComponent2); - textComponent.addExtra(textComponent3); - new Chat(textComponent).sendTo(player); - new BukkitRunnable() { - @Override - public void run() { - new GridStructure( - player, - plot.getPlotSize().getLength(), - plot.getPlotSize().getHeight(), - plot.getPlotSize().getWidth(), - plot.getID(), - ((Player) sender).getWorld(), - GridStructure.DISPLAY_TICKS, - plot.getCreatedLocation() - ).preview(true, false); - } - }.runTaskLater(VirtualRealty.getInstance(), 20); - } } + if (length < 1 || width < 1 || height < 1) { + ChatMessage.of(VirtualRealty.getMessages().graterThenZero).sendWithPrefix(sender); + return; + } + Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width); + if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { + ChatMessage.of(VirtualRealty.getMessages().cantCreateOnExisting).sendWithPrefix(sender); + return; + } + ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender); + long timeStart = System.currentTimeMillis(); + Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.AREA, length, height, width, true); + long timeEnd = System.currentTimeMillis(); + BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); + BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); + BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart))); + textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))})); + textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); + textComponent.addExtra(textComponent2); + textComponent.addExtra(textComponent3); + ChatMessage.of(textComponent).send(player); + new BukkitRunnable() { + @Override + public void run() { + new GridStructure( + player, + plot.getLength(), + plot.getHeight(), + plot.getWidth(), + plot.getID(), + ((Player) sender).getWorld(), + GridStructure.DISPLAY_TICKS, + plot.getCreatedLocation() + ).preview(true, false); + } + }.runTaskLater(VirtualRealty.getInstance(), 20); } else { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().sizeNotRecognised); - } - } else { - int length; - int height; - int width; - try { - length = Integer.parseInt(args[1]); - height = Integer.parseInt(args[2]); - width = Integer.parseInt(args[3]); - } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); - return; - } - if (length < 1 || width < 1 || height < 1) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().graterThenZero); - return; - } - if (length > 500 || width > 500 || height > 500) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().hardLimit); - return; - } - Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width); - if (RegionUtil.isCollidingWithAnotherPlot(cuboid) || RegionUtil.isCollidingWithBedrock(cuboid)) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting); - } else { + Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth()); + if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { + ChatMessage.of(VirtualRealty.getMessages().cantCreateOnExisting).sendWithPrefix(sender); + return; + } boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural")); Material floorMaterial = null; byte floorData = 0; - if (args.length >= 5 && !natural) { + Material borderMaterial = null; + byte borderData = 0; + if (args.length >= 3 && !natural) { try { - floorMaterial = VMaterial.getMaterial(args[4].split(":")[0].toUpperCase()); + floorMaterial = VMaterial.getMaterial(args[2].split(":")[0].toUpperCase()); if (floorMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); + ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender); return; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); + ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender); return; } - if (args[4].split(":").length == 2) { - floorData = Byte.parseByte(args[4].split(":")[1]); + if (args[2].split(":").length == 2) { + floorData = Byte.parseByte(args[2].split(":")[1]); } } - Material borderMaterial = null; - byte borderData = 0; - if (args.length >= 6) { + if (args.length >= 4) { try { - borderMaterial = VMaterial.getMaterial(args[5].split(":")[0].toUpperCase()); + borderMaterial = VMaterial.getMaterial(args[3].split(":")[0].toUpperCase()); if (borderMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); + ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender); return; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); + ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender); return; } - if (args[5].split(":").length == 2) { - borderData = Byte.parseByte(args[5].split(":")[1]); + if (args[3].split(":").length == 2) { + borderData = Byte.parseByte(args[3].split(":")[1]); } } - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); + ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.CUSTOM, length, height, width, natural); + Plot plot = PlotManager.getInstance().createPlot(location, plotSize, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), natural); if (!natural) { if (floorMaterial != null) { plot.setFloorMaterial(floorMaterial, floorData); @@ -268,15 +173,15 @@ public void run() { textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); textComponent.addExtra(textComponent2); textComponent.addExtra(textComponent3); - new Chat(textComponent).sendTo(player); + ChatMessage.of(textComponent).send(player); new BukkitRunnable() { @Override public void run() { new GridStructure( player, - plot.getLength(), - plot.getHeight(), - plot.getWidth(), + plot.getPlotSize().getLength(), + plot.getPlotSize().getHeight(), + plot.getPlotSize().getWidth(), plot.getID(), ((Player) sender).getWorld(), GridStructure.DISPLAY_TICKS, @@ -285,6 +190,101 @@ public void run() { } }.runTaskLater(VirtualRealty.getInstance(), 20); } + } else { + int length; + int height; + int width; + try { + length = Integer.parseInt(args[1]); + height = Integer.parseInt(args[2]); + width = Integer.parseInt(args[3]); + } catch (IllegalArgumentException e) { + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); + return; + } + if (length < 1 || width < 1 || height < 1) { + ChatMessage.of(VirtualRealty.getMessages().graterThenZero).sendWithPrefix(sender); + return; + } + if (length > 500 || width > 500 || height > 500) { + ChatMessage.of(VirtualRealty.getMessages().hardLimit).sendWithPrefix(sender); + return; + } + Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width); + if (RegionUtil.isCollidingWithAnotherPlot(cuboid) || RegionUtil.isCollidingWithBedrock(cuboid)) { + ChatMessage.of(VirtualRealty.getMessages().cantCreateOnExisting).sendWithPrefix(sender); + return; + } + boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural")); + Material floorMaterial = null; + byte floorData = 0; + if (args.length >= 5 && !natural) { + try { + floorMaterial = VMaterial.getMaterial(args[4].split(":")[0].toUpperCase()); + if (floorMaterial == null) { + ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender); + return; + } + } catch (IllegalArgumentException e) { + ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender); + return; + } + if (args[4].split(":").length == 2) { + floorData = Byte.parseByte(args[4].split(":")[1]); + } + } + Material borderMaterial = null; + byte borderData = 0; + if (args.length >= 6) { + try { + borderMaterial = VMaterial.getMaterial(args[5].split(":")[0].toUpperCase()); + if (borderMaterial == null) { + ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender); + return; + } + } catch (IllegalArgumentException e) { + ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender); + return; + } + if (args[5].split(":").length == 2) { + borderData = Byte.parseByte(args[5].split(":")[1]); + } + } + ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender); + long timeStart = System.currentTimeMillis(); + Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.CUSTOM, length, height, width, natural); + if (!natural) { + if (floorMaterial != null) { + plot.setFloorMaterial(floorMaterial, floorData); + } + if (borderMaterial != null) { + plot.setBorderMaterial(borderMaterial, borderData); + } + } + long timeEnd = System.currentTimeMillis(); + BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); + BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); + BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart))); + textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))})); + textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); + textComponent.addExtra(textComponent2); + textComponent.addExtra(textComponent3); + ChatMessage.of(textComponent).send(player); + new BukkitRunnable() { + @Override + public void run() { + new GridStructure( + player, + plot.getLength(), + plot.getHeight(), + plot.getWidth(), + plot.getID(), + ((Player) sender).getWorld(), + GridStructure.DISPLAY_TICKS, + plot.getCreatedLocation() + ).preview(true, false); + } + }.runTaskLater(VirtualRealty.getInstance(), 20); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java index 570efdb..ce20039 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java @@ -5,8 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.Chat; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; @@ -55,7 +54,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + ownedBy.substring(0, 14) + "§8 §f" + (isOwned ? " " : "") + dateTimeFormatter.format(localDateTime) + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString()); textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))})); textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); - new Chat(textComponent).sendTo(sender); + ChatMessage.of(textComponent).send(sender); } sender.sendMessage("§7§m "); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java index 8e6edc2..3cfe267 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java @@ -8,6 +8,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.Confirmation; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -54,38 +55,38 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return; } - if (sender instanceof Player) { - if (this.isBypass()) { - plot.remove(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); - } else { - for (String s : VirtualRealty.getMessages().removeConfirmation) { - sender.sendMessage(VirtualRealty.PREFIX + s.replaceAll("%plot_id%", String.valueOf(plot.getID()))); + if (!(sender instanceof Player)) { + plot.remove(sender); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); + return; + } + if (this.isBypass()) { + plot.remove(sender); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); + } else { + for (String s : VirtualRealty.getMessages().removeConfirmation) { + sender.sendMessage(VirtualRealty.PREFIX + s.replaceAll("%plot_id%", String.valueOf(plot.getID()))); + } + Confirmation confirmation = new Confirmation(ConfirmationType.REMOVE, (Player) sender, plot.getID(), "YES") { + @Override + public void success() { + plot.remove(((Player) sender).getKiller()); + ChatMessage.of(VirtualRealty.getMessages().removedPlot).sendWithPrefix(sender); + ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); } - Confirmation confirmation = new Confirmation(ConfirmationType.REMOVE, (Player) sender, plot.getID(), "YES") { - @Override - public void success() { - plot.remove(((Player) sender).getKiller()); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); - ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); - } - @Override - public void failed() { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removalCancelled); - ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); - } + @Override + public void failed() { + ChatMessage.of(VirtualRealty.getMessages().removalCancelled).sendWithPrefix(sender); + ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); + } - @Override - public void expiry() { - ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); - } - }; - ConfirmationManager.addConfirmation(confirmation); - } - } else { - plot.remove(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); + @Override + public void expiry() { + ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); + } + }; + ConfirmationManager.addConfirmation(confirmation); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java index 693f7f5..601a561 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java @@ -3,6 +3,7 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; @@ -28,7 +29,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick here to download new version!")})); textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/")); } - sender.spigot().sendMessage(new TextComponent(VirtualRealty.PREFIX + "Version: §a" + VirtualRealty.getInstance().getDescription().getVersion()), textComponent); + ChatMessage.of(new TextComponent("Version: §a" + VirtualRealty.getInstance().getDescription().getVersion()), textComponent).send(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java index 3ec3cce..2e8a597 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java @@ -1,6 +1,6 @@ package com.modnmetl.virtualrealty.configs; -import com.modnmetl.virtualrealty.enums.WorldsSetting; +import com.modnmetl.virtualrealty.enums.WorldSetting; import com.modnmetl.virtualrealty.enums.dynmap.HighlightType; import com.modnmetl.virtualrealty.enums.ServerVersion; import eu.okaeri.configs.OkaeriConfig; @@ -9,7 +9,6 @@ import lombok.NoArgsConstructor; import org.bukkit.GameMode; -import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.*; @@ -66,7 +65,7 @@ public static class License extends OkaeriConfig { @Comment("ALL - all worlds are capable of creating plots with plot claim items and 'worlds-list' setting is skipped") @Comment("INCLUDED - only worlds included in 'worlds-list' setting are capable of creating plots with plot claim items") @Comment("EXCLUDED - all worlds mentioned in 'worlds-list' setting won't be capable of creating plots with plot claim items") - public String worldsSetting = WorldsSetting.ALL.name(); + public String worldsSetting = WorldSetting.ALL.name(); @Comment("List of worlds") public List worldsList = Arrays.asList("%world%", "%world%_nether", "%world%_the_end"); diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java b/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java index 772a253..d03e5b1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java +++ b/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java @@ -18,7 +18,7 @@ public enum Direction { public static Direction byYaw(float yaw) { float absoluteYaw = Math.abs(yaw); Direction direction = null; - if(absoluteYaw > 315 || absoluteYaw <= 45) { + if (absoluteYaw > 315 || absoluteYaw <= 45) { //south direction = SOUTH; } else if(absoluteYaw > 45 && absoluteYaw <= 135) { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/WorldsSetting.java b/src/main/java/com/modnmetl/virtualrealty/enums/WorldSetting.java similarity index 75% rename from src/main/java/com/modnmetl/virtualrealty/enums/WorldsSetting.java rename to src/main/java/com/modnmetl/virtualrealty/enums/WorldSetting.java index 076f39a..9cfc903 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/WorldsSetting.java +++ b/src/main/java/com/modnmetl/virtualrealty/enums/WorldSetting.java @@ -1,6 +1,6 @@ package com.modnmetl.virtualrealty.enums; -public enum WorldsSetting { +public enum WorldSetting { ALL, INCLUDED, diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java index ba95fce..fef2b57 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java @@ -4,7 +4,7 @@ import com.modnmetl.virtualrealty.enums.ConfirmationType; import com.modnmetl.virtualrealty.enums.Direction; import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.enums.WorldsSetting; +import com.modnmetl.virtualrealty.enums.WorldSetting; import com.modnmetl.virtualrealty.enums.items.VItem; import com.modnmetl.virtualrealty.listeners.VirtualListener; import com.modnmetl.virtualrealty.listeners.stake.DraftListener; @@ -16,7 +16,7 @@ import com.modnmetl.virtualrealty.objects.region.Cuboid; import com.modnmetl.virtualrealty.objects.region.GridStructure; import com.modnmetl.virtualrealty.utils.RegionUtil; -import com.modnmetl.virtualrealty.utils.multiversion.Chat; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import de.tr7zw.nbtapi.NBTItem; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; @@ -220,7 +220,7 @@ public void success() { textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); textComponent.addExtra(textComponent2); textComponent.addExtra(textComponent3); - new Chat(textComponent).sendTo(this.getSender()); + ChatMessage.of(textComponent).send(this.getSender()); new BukkitRunnable() { @Override public void run() { @@ -266,15 +266,8 @@ public void onPlotItemDraft(PlayerInteractEvent e) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeDisabled); return; } - PlayerInventory inv; - ItemStack claimItem; - if (VirtualRealty.legacyVersion) { - inv = player.getInventory(); - claimItem = player.getItemInHand(); - } else { - inv = player.getInventory(); - claimItem = inv.getItemInMainHand(); - } + PlayerInventory inv = player.getInventory(); + ItemStack claimItem = VirtualRealty.legacyVersion ? player.getItemInHand() : inv.getItemInMainHand(); NBTItem claimNbtItem; if (!(claimItem.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) && @@ -284,29 +277,29 @@ public void onPlotItemDraft(PlayerInteractEvent e) { e.setCancelled(true); PlotItem plotItem = PlotItem.fromItemStack(claimItem); Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); - String replacement = null; + String featureName = null; if (plot == null) { if (!canCreateInWorld(player)) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); return; } - replacement = VirtualRealty.getMessages().createFeature; + featureName = VirtualRealty.getMessages().createFeature; } else { if (plotItem.getPlotSize().equals(plot.getPlotSize())) { if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { - replacement = VirtualRealty.getMessages().claimFeature; + featureName = VirtualRealty.getMessages().claimFeature; } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { - replacement = VirtualRealty.getMessages().extendFeature; + featureName = VirtualRealty.getMessages().extendFeature; } } else { if (!canCreateInWorld(player)) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); return; } - replacement = VirtualRealty.getMessages().createFeature; + featureName = VirtualRealty.getMessages().createFeature; } } - String finalReplacement = replacement; + String finalFeatureName = featureName; if (plot != null && plotItem.getPlotSize().equals(plot.getPlotSize()) && plot.getPlotSize() != PlotSize.CUSTOM) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot); GridStructure previewStructure = new GridStructure( @@ -324,13 +317,14 @@ public void onPlotItemDraft(PlayerInteractEvent e) { PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(previewStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem))); inv.remove(claimItem); + ItemStack draftItemStack = draftItem.getItemStack(); if (VirtualRealty.legacyVersion) { - player.setItemInHand(draftItem.getItemStack()); + player.setItemInHand(draftItemStack); } else { - inv.setItemInMainHand(draftItem.getItemStack()); + inv.setItemInMainHand(draftItemStack); } VirtualRealty.getMessages().claimEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") - .replaceAll("%feature%", finalReplacement) + .replaceAll("%feature%", finalFeatureName) )); return; } @@ -389,12 +383,12 @@ public void onPlotItemDraft(PlayerInteractEvent e) { } draftStructure.preview(player.getLocation(), true, false); VirtualRealty.getMessages().claimEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") - .replaceAll("%feature%", finalReplacement) + .replaceAll("%feature%", finalFeatureName) )); } public boolean canCreateInWorld(Player player) { - switch (WorldsSetting.valueOf(VirtualRealty.getPluginConfiguration().worldsSetting.toUpperCase())) { + switch (WorldSetting.valueOf(VirtualRealty.getPluginConfiguration().worldsSetting.toUpperCase())) { case ALL: break; case INCLUDED: diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java index 623df28..89a4aca 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java @@ -78,9 +78,7 @@ public void run() { private static AreaMarker getAreaMarker(String areaMarkerName) { if (VirtualRealty.getDynmapManager() == null) return null; for (AreaMarker areaMarker : VirtualRealty.getDynmapManager().markerset.getAreaMarkers()) { - if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) { - return areaMarker; - } + if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) return areaMarker; } return null; } @@ -119,12 +117,12 @@ public static void resetPlotMarker(Plot plot) { } public static void removeDynMapMarker(Plot plot) { - if (VirtualRealty.getDynmapManager() == null || !VirtualRealty.getDynmapManager().isDynmapPresent() || VirtualRealty.getDynmapManager().dapi == null || VirtualRealty.getDynmapManager().markerset == null) return; + if (VirtualRealty.getDynmapManager() == null || !VirtualRealty.getDynmapManager().isDynmapPresent() || VirtualRealty.getDynmapManager().dapi == null || VirtualRealty.getDynmapManager().markerset == null) + return; AreaMarker marker = VirtualRealty.getDynmapManager().markerset.findAreaMarker("virtualrealty.plots." + plot.getID()); - if (marker != null) { - areaMarkers.remove(marker); - marker.deleteMarker(); - } + if (marker == null) return; + areaMarkers.remove(marker); + marker.deleteMarker(); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java index 0a356e7..2305af2 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java @@ -2,21 +2,18 @@ import com.modnmetl.virtualrealty.enums.PlotSize; import com.modnmetl.virtualrealty.objects.data.PlotMember; -import com.modnmetl.virtualrealty.objects.math.BlockVector2; import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.objects.region.Cuboid; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.math.BlockVector3; import com.modnmetl.virtualrealty.sql.Database; import lombok.Data; -import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.*; @Data @@ -148,7 +145,7 @@ public Plot getPlot(Location location) { return null; } - public void removePlotFromList(Plot plot) { + public void removePlotFromCollection(Plot plot) { plots.remove(plot); } diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java b/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java index 1dfa53d..03f4762 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java @@ -3,9 +3,7 @@ public interface Executable { void success(); - void failed(); - void expiry(); } diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java index 3a75326..c166f44 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java @@ -8,6 +8,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.data.PlotMember; import com.modnmetl.virtualrealty.objects.region.Cuboid; +import com.modnmetl.virtualrealty.objects.region.GridStructure; import com.modnmetl.virtualrealty.sql.Database; import com.modnmetl.virtualrealty.utils.EnumUtils; import com.modnmetl.virtualrealty.utils.data.OldSchematicUtil; @@ -176,11 +177,10 @@ public boolean hasMembershipAccess(UUID uuid) { public void togglePermission(RegionPermission plotPermission) { modified(); - if (nonMemberPermissions.contains(plotPermission)) { + if (nonMemberPermissions.contains(plotPermission)) nonMemberPermissions.remove(plotPermission); - } else { - nonMemberPermissions.add(plotPermission); - } + else + nonMemberPermissions.add(plotPermission); } public boolean hasPermission(RegionPermission plotPermission) { @@ -213,30 +213,36 @@ public void removeMember(PlotMember plotMember) { plotMember.delete(); } + public void removeAllMembers() { + for (PlotMember member : members) { + removeMember(member); + } + } + public boolean isOwnershipExpired() { return ownedUntilDate.isBefore(LocalDateTime.now()); } public int getXMin() { - return Math.min(this.getBorderBottomLeftCorner().getBlockX(), this.borderTopRightCorner.getBlockX()); + return Math.min(this.borderBottomLeftCorner.getBlockX(), this.borderTopRightCorner.getBlockX()); } public int getXMax() { - return Math.max(this.getBorderBottomLeftCorner().getBlockX(), this.borderTopRightCorner.getBlockX()); + return Math.max(this.borderBottomLeftCorner.getBlockX(), this.borderTopRightCorner.getBlockX()); } public int getZMin() { - return Math.min(this.getBorderBottomLeftCorner().getBlockZ(), this.borderTopRightCorner.getBlockZ()); + return Math.min(this.borderBottomLeftCorner.getBlockZ(), this.borderTopRightCorner.getBlockZ()); } public int getZMax() { - return Math.max(this.getBorderBottomLeftCorner().getBlockZ(), this.borderTopRightCorner.getBlockZ()); + return Math.max(this.borderBottomLeftCorner.getBlockZ(), this.borderTopRightCorner.getBlockZ()); } public void setOwnedBy(UUID ownedBy) { modified(); this.ownedBy = ownedBy; - members.clear(); + removeAllMembers(); updateMarker(); } @@ -366,7 +372,7 @@ public void initialize(boolean natural) { long time = System.currentTimeMillis(); prepareCorners(); if (plotSize != PlotSize.AREA) prepareBlocks(createdLocation, natural); - VirtualRealty.debug("Plot initialize time: " + (System.currentTimeMillis() - time) + " ms"); + VirtualRealty.debug("Plot initialization time: " + (System.currentTimeMillis() - time) + " ms"); } public Set getBorderBlocks() { @@ -570,52 +576,57 @@ public void prepareBlocks(Location location, boolean natural) { } public void unloadPlot() { - if (SchematicUtil.isOldSerialization(ID)) { - long time = System.currentTimeMillis(); - Location location = null; - switch (createdDirection) { - case SOUTH: { - location = new Location(getCreatedWorld(), createdLocation.getBlockX() - width, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1); - break; - } - case WEST: { - location = new Location(getCreatedWorld(), createdLocation.getBlockX() - length, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - width); - break; - } - case NORTH: { - location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - length); - break; - } - case EAST: { - location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1); - break; - } - } - OldSchematicUtil.paste(ID, location); - VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms (Old Serialization)"); - } else { - long time = System.currentTimeMillis(); + if (!SchematicUtil.isOldSerialization(ID)) { SchematicUtil.paste(ID); + return; } + long time = System.currentTimeMillis(); + Location location = null; + switch (createdDirection) { + case SOUTH: { + location = new Location(getCreatedWorld(), createdLocation.getBlockX() - width, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1); + break; + } + case WEST: { + location = new Location(getCreatedWorld(), createdLocation.getBlockX() - length, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - width); + break; + } + case NORTH: { + location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - length); + break; + } + case EAST: { + location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1); + break; + } + } + OldSchematicUtil.paste(ID, location); + VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms (Old Serialization)"); } private void modified() { modified = Instant.now(); } - @SneakyThrows - public void insert() { - String serializedLocation = - Objects.requireNonNull(this.getCreatedWorld()).getName() + ";" + - this.createdLocation.getX() + ";" + - this.createdLocation.getY() + ";" + - this.createdLocation.getZ() + ";" + - this.createdLocation.getYaw() + ";" + - this.createdLocation.getPitch() + ";"; + private String getNonMemberPermissionsString() { StringBuilder permissions = new StringBuilder(); for (RegionPermission permission : this.nonMemberPermissions) { permissions.append(permission.name()).append("¦"); } + return permissions.toString(); + } + + private String getSerializedCreatedLocation() { + return Objects.requireNonNull(this.getCreatedWorld()).getName() + ";" + + this.createdLocation.getX() + ";" + + this.createdLocation.getY() + ";" + + this.createdLocation.getZ() + ";" + + this.createdLocation.getYaw() + ";" + + this.createdLocation.getPitch() + ";"; + } + + @SneakyThrows + public void insert() { try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement( "INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + @@ -626,7 +637,7 @@ public void insert() { )) { ps.setInt(1, this.ID); ps.setString(2, (this.ownedBy == null ? "" : this.ownedBy.toString())); - ps.setString(3, permissions.toString()); + ps.setString(3, getNonMemberPermissionsString()); ps.setString(4, (this.assignedBy == null ? "null" : this.assignedBy)); ps.setTimestamp(5, Timestamp.valueOf(this.ownedUntilDate)); ps.setString(6, this.floorMaterial + ":" + this.floorData); @@ -635,7 +646,7 @@ public void insert() { ps.setInt(9, this.length); ps.setInt(10, this.width); ps.setInt(11, this.height); - ps.setString(12, serializedLocation); + ps.setString(12, getSerializedCreatedLocation()); ps.setTimestamp(13, Timestamp.from(Instant.now())); ps.setTimestamp(14, Timestamp.from(Instant.now())); ps.setString(15, this.selectedGameMode.name()); @@ -647,10 +658,6 @@ public void insert() { @SneakyThrows public void update() { - StringBuilder permissions = new StringBuilder(); - for (RegionPermission permission : this.nonMemberPermissions) { - permissions.append(permission.name()).append("¦"); - } try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement( "UPDATE `" + @@ -670,7 +677,7 @@ public void update() { " WHERE `ID`= ?" )) { ps.setString(1, (this.ownedBy == null ? "" : this.ownedBy.toString())); - ps.setString(2, permissions.toString()); + ps.setString(2, getNonMemberPermissionsString()); ps.setString(3, (this.assignedBy == null ? "null" : this.assignedBy)); ps.setTimestamp(4, Timestamp.valueOf(this.ownedUntilDate)); ps.setString(5, this.floorMaterial + ":" + this.floorData); @@ -697,9 +704,7 @@ public void remove(CommandSender sender) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noRegionFileFound); } } - for (PlotMember member : this.getMembers()) { - removeMember(member); - } + removeAllMembers(); if (VirtualRealty.getDynmapManager() != null) { DynmapManager.removeDynMapMarker(this); } @@ -712,7 +717,7 @@ public void remove(CommandSender sender) { } catch (Exception e) { e.printStackTrace(); } - PlotManager.getInstance().removePlotFromList(this); + PlotManager.getInstance().removePlotFromCollection(this); VirtualRealty.debug("Removed plot #" + this.ID); } diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java b/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java index 0509f6c..a8092e1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java @@ -4,6 +4,7 @@ import com.modnmetl.virtualrealty.enums.ConfirmationType; import com.modnmetl.virtualrealty.managers.ConfirmationManager; import com.modnmetl.virtualrealty.objects.Executable; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.Getter; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -41,7 +42,7 @@ private void runExpiry() { @Override public void run() { if (ConfirmationManager.isConfirmationAvailable(confirmationUUID)) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().confirmationExpired); + ChatMessage.of(VirtualRealty.getMessages().confirmationExpired).sendWithPrefix(sender); expiry(); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java index 3d11ce8..c342d33 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java @@ -10,6 +10,7 @@ import java.lang.reflect.Field; import java.util.Base64; +import java.util.Objects; import java.util.UUID; public class SkullUtil { @@ -17,7 +18,7 @@ public class SkullUtil { public static ItemStack getSkull(String url) { ItemStack skull; if (VirtualRealty.legacyVersion) { - skull = new ItemStack(VMaterial.getMaterial("SKULL_ITEM"), 1, (short) 3); + skull = new ItemStack(Objects.requireNonNull(Material.getMaterial("SKULL_ITEM")), 1, (short) 3); } else { skull = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3); } @@ -47,7 +48,7 @@ public static ItemStack getSkull(String url) { public static ItemStack getSkull(String url, UUID uuid) { ItemStack skull; if (VirtualRealty.legacyVersion) { - skull = new ItemStack(VMaterial.getMaterial("SKULL_ITEM"), 1, (short) 3); + skull = new ItemStack(Objects.requireNonNull(Material.getMaterial("SKULL_ITEM")), 1, (short) 3); } else { skull = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3); } diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java b/src/main/java/com/modnmetl/virtualrealty/utils/loader/Loader.java similarity index 98% rename from src/main/java/com/modnmetl/virtualrealty/utils/Loader.java rename to src/main/java/com/modnmetl/virtualrealty/utils/loader/Loader.java index b2815ec..0af54d7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/loader/Loader.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.utils.loader; import com.google.gson.Gson; import com.google.gson.JsonObject; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java deleted file mode 100644 index 1c711c3..0000000 --- a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.modnmetl.virtualrealty.utils.multiversion; - -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.command.CommandSender; - -public class Chat { - - private final BaseComponent text; - - public Chat(BaseComponent text) { - this.text = text; - } - - public Chat(String text) { - this.text = new TextComponent(text); - } - - public void sendTo(CommandSender sender) { - sender.spigot().sendMessage(text); - } - - -} diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/ChatMessage.java b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/ChatMessage.java new file mode 100644 index 0000000..d76f68b --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/ChatMessage.java @@ -0,0 +1,43 @@ +package com.modnmetl.virtualrealty.utils.multiversion; + +import com.modnmetl.virtualrealty.VirtualRealty; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.CommandSender; + +import java.util.Arrays; +import java.util.TimerTask; + +public class ChatMessage { + + private final BaseComponent message; + + private ChatMessage(BaseComponent message) { + this.message = message; + } + + private ChatMessage(String message) { + this.message = new TextComponent(message); + } + + public static ChatMessage of(String message) { + return new ChatMessage(message); + } + + public static ChatMessage of(BaseComponent... messages) { + return new ChatMessage(new TextComponent(messages)); + } + + public static ChatMessage of(BaseComponent message) { + return new ChatMessage(message); + } + + public void sendWithPrefix(CommandSender player) { + player.spigot().sendMessage(new TextComponent(VirtualRealty.PREFIX), message); + } + + public void send(CommandSender player) { + player.spigot().sendMessage(message); + } + +} From 4f8a7773800de7fb866518d967dad357e7c26457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Thu, 3 Nov 2022 20:51:20 +0100 Subject: [PATCH 06/10] v2.5.0 - pre-release improvements --- .../plot/subcommand/KickSubCommand.java | 19 +++---- .../vrplot/subcommand/DebugSubCommand.java | 36 ++++++------- .../vrplot/subcommand/InfoSubCommand.java | 49 +++++++++-------- .../vrplot/subcommand/ItemSubCommand.java | 19 +++---- .../vrplot/subcommand/ListSubCommand.java | 14 ++--- .../vrplot/subcommand/ReloadSubCommand.java | 3 +- .../vrplot/subcommand/RemoveSubCommand.java | 53 +++++++++---------- .../vrplot/subcommand/TpSubCommand.java | 8 +-- .../vrplot/subcommand/UnassignSubCommand.java | 7 +-- .../vrplot/subcommand/VersionSubCommand.java | 2 +- .../vrplot/subcommand/VisualSubCommand.java | 3 +- .../virtualrealty/utils/Permissions.java | 5 +- 12 files changed, 107 insertions(+), 111 deletions(-) diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java index b3d2a1d..ca3db5b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java @@ -47,43 +47,36 @@ public void exec(CommandSender sender, Command command, String label, String[] a plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return; } OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[2]); if (offlinePlayer.getName() == null) { - ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } if (!plot.hasMembershipAccess(player.getUniqueId())) { - ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot); + ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender); return; } PlotMember plotMember = plot.getMember(player.getUniqueId()); if (plotMember != null) { if (!plotMember.hasManagementPermission(ManagementPermission.KICK_MEMBER)) { - ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); + ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender); return; } } else { if (!plot.getOwnedBy().equals(player.getUniqueId())) { - ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess); + ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender); return; } } if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + ChatMessage.of(VirtualRealty.getMessages().ownershipExpired).sendWithPrefix(sender); return; } if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) { diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java index bd6c847..ed1a11e 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -33,32 +34,32 @@ public void exec(CommandSender sender, Command command, String label, String[] a assertPermission(); VirtualRealty instance = VirtualRealty.getInstance(); if (System.currentTimeMillis() - LAST_REQUEST < 1500) { - sender.sendMessage(VirtualRealty.PREFIX + "§cPlease wait " + Math.abs(System.currentTimeMillis() - LAST_REQUEST - 1500) + "ms. §7(Rate limiting)"); + ChatMessage.of("§cPlease wait " + Math.abs(System.currentTimeMillis() - LAST_REQUEST - 1500) + "ms. §7(Rate limiting)").sendWithPrefix(sender); return; } - sender.sendMessage(" "); - sender.sendMessage(" §8§l«§8§m §8[§aDebug§8]§m §8§l»"); - sender.sendMessage(" §8┏ §7Operating System: §a" + System.getProperty("os.name") + " §7(" + System.getProperty("os.version") + "-" + System.getProperty("os.arch") + ")"); - sender.sendMessage(" §8┣ §7Java Version: §a" + System.getProperty("java.version")); - sender.sendMessage(" §8┣ §7Engine: §a" + instance.getServer().getName() + " §7(" + instance.getServer().getBukkitVersion() + ")"); - sender.sendMessage(" §8┣ §7Core count: §a" + Runtime.getRuntime().availableProcessors()); - sender.sendMessage(" §8┣ §7RAM: §a" + format(Runtime.getRuntime().totalMemory()) + "§7/§a" + format(Runtime.getRuntime().maxMemory()) + " §7MB"); + ChatMessage.of(" ").send(sender); + ChatMessage.of(" §8§l«§8§m §8[§aDebug§8]§m §8§l»").send(sender); + ChatMessage.of(" §8┏ §7Operating System: §a" + System.getProperty("os.name") + " §7(" + System.getProperty("os.version") + "-" + System.getProperty("os.arch") + ")").send(sender); + ChatMessage.of(" §8┣ §7Java Version: §a" + System.getProperty("java.version")).send(sender); + ChatMessage.of(" §8┣ §7Engine: §a" + instance.getServer().getName() + " §7(" + instance.getServer().getBukkitVersion() + ")").send(sender); + ChatMessage.of(" §8┣ §7Core count: §a" + Runtime.getRuntime().availableProcessors()).send(sender); + ChatMessage.of(" §8┣ §7RAM: §a" + format(Runtime.getRuntime().totalMemory()) + "§7/§a" + format(Runtime.getRuntime().maxMemory()) + " §7MB").send(sender); try { // API Rate Limit is 45 requests per minute URL url = new URL("http://ip-api.com/json/?fields=org,isp,country,countryCode"); URLConnection urlConnection = url.openConnection(); JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(urlConnection.getInputStream())).getAsJsonObject(); LAST_REQUEST = System.currentTimeMillis(); - sender.sendMessage(" §8┣ §7Location: §a" + jsonObject.get("country").getAsString() + " §7(" + jsonObject.get("countryCode").getAsString() + ")"); - sender.sendMessage(" §8┣ §7ISP: §a" + jsonObject.get("isp").getAsString()); - sender.sendMessage(" §8┣ §7Host: §a" + jsonObject.get("org").getAsString()); + ChatMessage.of(" §8┣ §7Location: §a" + jsonObject.get("country").getAsString() + " §7(" + jsonObject.get("countryCode").getAsString() + ")").send(sender); + ChatMessage.of(" §8┣ §7ISP: §a" + jsonObject.get("isp").getAsString()).send(sender); + ChatMessage.of(" §8┣ §7Host: §a" + jsonObject.get("org").getAsString()).send(sender); } catch (IOException ignored) { - sender.sendMessage(" §8┣ §7Couldn't connect to the IP-API"); + ChatMessage.of(" §8┣ §7Couldn't connect to the IP-API").send(sender); } - sender.sendMessage(" §8┣ §7Default GM: §a" + instance.getServer().getDefaultGameMode().name().charAt(0) + instance.getServer().getDefaultGameMode().name().substring(1).toLowerCase()); + ChatMessage.of(" §8┣ §7Default GM: §a" + instance.getServer().getDefaultGameMode().name().charAt(0) + instance.getServer().getDefaultGameMode().name().substring(1).toLowerCase()).send(sender); Plugin[] plugins = instance.getServer().getPluginManager().getPlugins(); - sender.sendMessage(" §8┣ §7Version: §a" + VirtualRealty.currentServerVersion.name().substring(0, 1).toUpperCase() + VirtualRealty.currentServerVersion.name().substring(1).toLowerCase()); - sender.sendMessage(" §8┣ §7Plugins (§a" + plugins.length + "§7):"); + ChatMessage.of(" §8┣ §7Version: §a" + VirtualRealty.currentServerVersion.name().substring(0, 1).toUpperCase() + VirtualRealty.currentServerVersion.name().substring(1).toLowerCase()).send(sender); + ChatMessage.of(" §8┣ §7Plugins (§a" + plugins.length + "§7):").send(sender); int limit = sender instanceof Player ? 2 : 3; int lastRow = (plugins.length / limit + (plugins.length % limit == 0 ? 0 : 1)); int pluginIndex = 0; @@ -72,12 +73,11 @@ public void exec(CommandSender sender, Command command, String label, String[] a Object o = Arrays.stream(plugins).skip((long) row * limit).limit(index + 2).toArray()[index + 1]; if (pluginIndex % limit != (limit == 2 ? 1 : 2)) sb.append(" §8| "); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } else break; pluginIndex++; } - sender.sendMessage(sb.toString()); + ChatMessage.of(sb.toString()).send(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java index 6c4750a..61014c5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -31,7 +32,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a assertPlayer(); Plot plot = PlotManager.getInstance().getPlot(((Player) sender).getLocation()); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot); + ChatMessage.of(VirtualRealty.getMessages().notStandingOnPlot).sendWithPrefix(sender); return; } printInfo(sender, plot); @@ -41,24 +42,26 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); return; } if (PlotManager.getInstance().getPlots().isEmpty()) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots); + ChatMessage.of(VirtualRealty.getMessages().noPlots).sendWithPrefix(sender); return; } if (plotID < PlotManager.getInstance().getPlotMinID()) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getInstance().getPlotMinID()))); + String message = VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getInstance().getPlotMinID())); + ChatMessage.of(message).sendWithPrefix(sender); return; } if (plotID > PlotManager.getInstance().getPlotMaxID()) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getInstance().getPlotMaxID()))); + String message = VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getInstance().getPlotMaxID())); + ChatMessage.of(message).sendWithPrefix(sender); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } printInfo(sender, plot); @@ -84,27 +87,27 @@ private void printInfo(CommandSender sender, Plot plot) { } } } - sender.sendMessage(" "); - sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - sender.sendMessage(" §7Plot ID §8§l‣ §f" + plot.getID()); - sender.sendMessage(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable")); + ChatMessage.of(" ").sendWithPrefix(sender); + ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").sendWithPrefix(sender); + ChatMessage.of(" §7Plot ID §8§l‣ §f" + plot.getID()).sendWithPrefix(sender); + ChatMessage.of(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable")).sendWithPrefix(sender); if (plot.getMembers().size() != 0) { - sender.sendMessage(" §7Members §8§l↴"); + ChatMessage.of(" §7Members §8§l↴").send(sender); for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) { - sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()); + ChatMessage.of(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()).send(sender); } } - sender.sendMessage(" §7Assigned By §8§l‣ §a" + assignedBy); - sender.sendMessage(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime)); - sender.sendMessage(" §7Size §8§l‣ §f" + plot.getPlotSize()); - sender.sendMessage(" §7Length §8§l‣ §f" + plot.getLength()); - sender.sendMessage(" §7Height §8§l‣ §f" + plot.getHeight()); - sender.sendMessage(" §7Width §8§l‣ §f" + plot.getWidth()); - sender.sendMessage(" §7Floor Material §8§l‣ §f" + plot.getFloorMaterialName()); - sender.sendMessage(" §7Border Material §8§l‣ §f" + plot.getBorderMaterialName()); - sender.sendMessage(" §7Pos 1 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getBottomLeftCorner().toString()); - sender.sendMessage(" §7Pos 2 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getTopRightCorner().toString()); - sender.sendMessage(" §7Created Direction §8§l‣ §f" + plot.getCreatedDirection().name()); + ChatMessage.of(" §7Assigned By §8§l‣ §a" + assignedBy).send(sender); + ChatMessage.of(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime)).send(sender); + ChatMessage.of(" §7Size §8§l‣ §f" + plot.getPlotSize()).send(sender); + ChatMessage.of(" §7Length §8§l‣ §f" + plot.getLength()).send(sender); + ChatMessage.of(" §7Height §8§l‣ §f" + plot.getHeight()).send(sender); + ChatMessage.of(" §7Width §8§l‣ §f" + plot.getWidth()).send(sender); + ChatMessage.of(" §7Floor Material §8§l‣ §f" + plot.getFloorMaterialName()).send(sender); + ChatMessage.of(" §7Border Material §8§l‣ §f" + plot.getBorderMaterialName()).send(sender); + ChatMessage.of(" §7Pos 1 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getBottomLeftCorner().toString()).send(sender); + ChatMessage.of(" §7Pos 2 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getTopRightCorner().toString()).send(sender); + ChatMessage.of(" §7Created Direction §8§l‣ §f" + plot.getCreatedDirection().name()).send(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java index 1f1eeab..d71301b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java @@ -7,6 +7,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.objects.data.PlotItem; import com.modnmetl.virtualrealty.utils.EnumUtils; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -113,27 +114,27 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { additionalDays = Integer.parseInt(args[7-backwardArgs]); } catch (NumberFormatException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue); + ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender); return; } if (additionalDays < 0) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue); + ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender); return; } int itemsAmount; try { itemsAmount = Integer.parseInt(args[8-backwardArgs]); } catch (NumberFormatException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue); + ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender); return; } if (itemsAmount < 1) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue); + ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender); return; } Player onlinePlayer = Bukkit.getPlayer(args[9-backwardArgs]); if (onlinePlayer == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender); return; } for (int i = 0; i < itemsAmount; i++) { @@ -141,11 +142,11 @@ public void exec(CommandSender sender, Command command, String label, String[] a ItemStack itemStack = plotItem.getItemStack(); onlinePlayer.getInventory().addItem(itemStack); if (onlinePlayer.getInventory().contains(itemStack)) { - sender.sendMessage(VirtualRealty.PREFIX + "§aPlot item has been assigned to " + onlinePlayer.getName() + " by " + (sender.getName()) + "!"); - onlinePlayer.sendMessage(VirtualRealty.PREFIX + "§aYou received a plot item from " + (sender.getName()) + "!"); + ChatMessage.of("§aPlot item has been assigned to " + onlinePlayer.getName() + " by " + (sender.getName()) + "!").sendWithPrefix(sender); + ChatMessage.of("§aYou received a plot item from " + (sender.getName()) + "!").sendWithPrefix(onlinePlayer); } else { - sender.sendMessage(VirtualRealty.PREFIX + "§c" + onlinePlayer.getName() + " has no inventory space to receive plot item!"); - onlinePlayer.sendMessage(VirtualRealty.PREFIX + "§cNo inventory space to receive plot item from " + (sender.getName()) + "!"); + ChatMessage.of("§c" + onlinePlayer.getName() + " has no inventory space to receive plot item!").sendWithPrefix(sender); + ChatMessage.of("§cNo inventory space to receive plot item from " + (sender.getName()) + "!").sendWithPrefix(onlinePlayer); } } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java index ce20039..7d0f991 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java @@ -30,14 +30,14 @@ public ListSubCommand(CommandSender sender, Command command, String label, Strin public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception { assertPermission(); if (PlotManager.getInstance().getPlots().isEmpty()) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots); + ChatMessage.of(VirtualRealty.getMessages().noPlots).sendWithPrefix(sender); return; } - sender.sendMessage(" "); - sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - sender.sendMessage(" "); - sender.sendMessage("§7§m "); - sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |"); + ChatMessage.of(" ").send(sender); + ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").send(sender); + ChatMessage.of(" ").send(sender); + ChatMessage.of("§7§m ").send(sender); + ChatMessage.of("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |").send(sender); for (Plot plot : PlotManager.getInstance().getPlots()) { LocalDateTime localDateTime = plot.getOwnedUntilDate(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); @@ -56,7 +56,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID())); ChatMessage.of(textComponent).send(sender); } - sender.sendMessage("§7§m "); + ChatMessage.of("§7§m ").send(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java index 3a377a7..d2848b1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.DynmapManager; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -45,7 +46,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a } catch (Exception exception) { exception.printStackTrace(); } - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().reloadComplete); + ChatMessage.of(VirtualRealty.getMessages().reloadComplete).sendWithPrefix(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java index 3cfe267..c458f16 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java @@ -47,47 +47,42 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } - if (!(sender instanceof Player)) { + if (this.isBypass() || !(sender instanceof Player)) { plot.remove(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); + ChatMessage.of(VirtualRealty.getMessages().removedPlot).sendWithPrefix(sender); return; } - if (this.isBypass()) { - plot.remove(sender); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); - } else { - for (String s : VirtualRealty.getMessages().removeConfirmation) { - sender.sendMessage(VirtualRealty.PREFIX + s.replaceAll("%plot_id%", String.valueOf(plot.getID()))); + for (String s : VirtualRealty.getMessages().removeConfirmation) { + ChatMessage.of(s.replaceAll("%plot_id%", String.valueOf(plot.getID()))).sendWithPrefix(sender); + } + Confirmation confirmation = new Confirmation(ConfirmationType.REMOVE, (Player) sender, plot.getID(), "YES") { + @Override + public void success() { + plot.remove(((Player) sender).getKiller()); + ChatMessage.of(VirtualRealty.getMessages().removedPlot).sendWithPrefix(sender); + ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); } - Confirmation confirmation = new Confirmation(ConfirmationType.REMOVE, (Player) sender, plot.getID(), "YES") { - @Override - public void success() { - plot.remove(((Player) sender).getKiller()); - ChatMessage.of(VirtualRealty.getMessages().removedPlot).sendWithPrefix(sender); - ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); - } - @Override - public void failed() { - ChatMessage.of(VirtualRealty.getMessages().removalCancelled).sendWithPrefix(sender); - ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); - } + @Override + public void failed() { + ChatMessage.of(VirtualRealty.getMessages().removalCancelled).sendWithPrefix(sender); + ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); + } - @Override - public void expiry() { - ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); - } - }; - ConfirmationManager.addConfirmation(confirmation); - } + @Override + public void expiry() { + ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType()); + } + }; + ConfirmationManager.addConfirmation(confirmation); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java index e68595a..23a51d5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -41,16 +42,15 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } plot.teleportPlayer(player); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot); - } + ChatMessage.of(VirtualRealty.getMessages().teleportedToPlot).sendWithPrefix(sender);} } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java index 4814ef3..5c2b4c6 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -38,17 +39,17 @@ public void exec(CommandSender sender, Command command, String label, String[] a try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender); return; } Plot plot = PlotManager.getInstance().getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender); return; } plot.setAssignedBy(null); plot.setOwnedBy(null); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().unassigned); + ChatMessage.of(VirtualRealty.getMessages().unassigned).sendWithPrefix(sender); plot.update(); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java index 601a561..7aa3945 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java @@ -29,7 +29,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick here to download new version!")})); textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/")); } - ChatMessage.of(new TextComponent("Version: §a" + VirtualRealty.getInstance().getDescription().getVersion()), textComponent).send(sender); + ChatMessage.of(new TextComponent("Version: §a" + VirtualRealty.getInstance().getDescription().getVersion()), textComponent).sendWithPrefix(sender); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java index 52dbeb2..1993dc6 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.region.GridStructure; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -46,7 +47,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a plot.getCreatedLocation() ); previewStructure.preview(player.getLocation(), true, false); - sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed); + ChatMessage.of(VirtualRealty.getMessages().visualBoundaryDisplayed).sendWithPrefix(sender); } diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java b/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java index d1cc936..4a93357 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java @@ -1,6 +1,7 @@ package com.modnmetl.virtualrealty.utils; import com.modnmetl.virtualrealty.VirtualRealty; +import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; @@ -9,7 +10,7 @@ public class Permissions { public static boolean hasPermission(CommandSender sender, Permission basePermission, String permission) { Permission finalPermission = new Permission(basePermission.getName() + "." + permission); if (!sender.hasPermission(finalPermission)) { - sender.sendMessage(VirtualRealty.PREFIX + "§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)"); + ChatMessage.of("§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)").sendWithPrefix(sender); return false; } return true; @@ -18,7 +19,7 @@ public static boolean hasPermission(CommandSender sender, Permission basePermiss public static boolean hasPermission(CommandSender sender, String permission) { Permission finalPermission = new Permission(permission); if (!sender.hasPermission(finalPermission)) { - sender.sendMessage(VirtualRealty.PREFIX + "§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)"); + ChatMessage.of("§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)").sendWithPrefix(sender); return false; } return true; From c240b8f6d6504780708a07597387cd8c5e309f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Thu, 3 Nov 2022 22:08:04 +0100 Subject: [PATCH 07/10] v2.5.0 - pre-release --- .../modnmetl/virtualrealty/VirtualRealty.java | 1 - .../virtualrealty/commands/SubCommand.java | 3 +- .../commands/plot/PlotCommand.java | 9 ++-- .../commands/vrplot/VirtualRealtyCommand.java | 7 +-- .../configs/CommandsConfiguration.java | 50 ++++++++++++++----- .../C0001_Remove_Old_Plot_Sub_Commands.java | 16 ++++++ .../configuration/ConfigurationFactory.java | 20 ++++++++ 7 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/modnmetl/virtualrealty/configs/migrations/C0001_Remove_Old_Plot_Sub_Commands.java diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index f69fac0..a9468da 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -281,7 +281,6 @@ public void configureMessages() { public void loadCommandsConfiguration() { commandsConfiguration = configFactory.loadCommandsConfiguration(commandsConfigurationFile); - commandsConfiguration.refreshHelpMessages(); commandsConfiguration.assignAliases(); CommandRegistry.setupPlaceholders(); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java index cd77dc5..a33658b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java @@ -122,8 +122,7 @@ public boolean isBypass() { public void printHelp() throws FailedCommandException { for (String s : HELP_LIST) { String message = s.replaceAll("%command%", getSubCommandName()); - if (message.contains("%command%")) - ChatMessage.of(message).send(commandSender); + ChatMessage.of(message).send(commandSender); } throw new FailedCommandException(); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java index 3b9c5f4..16a19f1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java @@ -84,13 +84,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St private static void printHelp(CommandSender sender) { for (String message : HELP_LIST) { - final String[] finalMessage = {message}; + final String[] finalMessage = { message }; CommandRegistry.PLOT_PLACEHOLDERS.forEach((s, s2) -> { finalMessage[0] = finalMessage[0].replaceAll(s, s2); }); - sender.sendMessage( - finalMessage[0] - ); + if (!finalMessage[0].contains("_command%")) + sender.sendMessage( + finalMessage[0] + ); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java index c8dde22..426c9e4 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java @@ -88,9 +88,10 @@ private static void printHelp(CommandSender sender) { CommandRegistry.VRPLOT_PLACEHOLDERS.forEach((s, s2) -> { finalMessage[0] = finalMessage[0].replaceAll(s, s2); }); - sender.sendMessage( - finalMessage[0] - ); + if (!finalMessage[0].contains("_command%")) + sender.sendMessage( + finalMessage[0] + ); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java index 67e7fe8..ed79713 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java @@ -8,6 +8,9 @@ import com.modnmetl.virtualrealty.enums.commands.CommandType; import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.annotation.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.SneakyThrows; import java.lang.reflect.Field; import java.util.*; @@ -20,24 +23,45 @@ @Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE) public class CommandsConfiguration extends OkaeriConfig { - public LinkedHashMap plotAliases = getPlotAliasesHashMap(); - public LinkedHashMap vrplotAliases = getVRPlotAliasesHashMap(); + public PlotAliases plotAliases = new PlotAliases(); + public Map vrplotAliases = getVRPlotAliasesHashMap(); - public LinkedHashMap> plotCommandsHelp = getCommandsHelp(CommandType.PLOT); - public LinkedHashMap> vrplotCommandsHelp = getCommandsHelp(CommandType.VRPLOT); + public Map> plotCommandsHelp = getCommandsHelp(CommandType.PLOT); + public Map> vrplotCommandsHelp = getCommandsHelp(CommandType.VRPLOT); - public static LinkedHashMap getVRPlotAliasesHashMap() { - LinkedHashMap aliasesHashMap = new LinkedHashMap<>(); - for (String s : CommandManager.SUBCOMMANDS.get(VirtualRealtyCommand.class)) { - if (s == null || s.isEmpty()) continue; - aliasesHashMap.put(s, s); + + + @Names(strategy = NameStrategy.HYPHEN_CASE) + public static class PlotAliases extends OkaeriConfig { + + public String panel = "panel"; + public String add = "add"; + public String gm = "gm"; + public String info = "info"; + public String kick = "kick"; + public String list = "list"; + public String tp = "tp"; + + public PlotAliases() { + super.setRemoveOrphans(true); } - return aliasesHashMap; + + @SneakyThrows + public Map getAliasesMap() { + Map aliasesMap = new HashMap<>(); + for (Field field : this.getClass().getDeclaredFields()) { + String name = field.getName(); + String alias = (String) field.get(this); + aliasesMap.put(name, alias); + } + return aliasesMap; + } + } - public static LinkedHashMap getPlotAliasesHashMap() { + public static LinkedHashMap getVRPlotAliasesHashMap() { LinkedHashMap aliasesHashMap = new LinkedHashMap<>(); - for (String s : CommandManager.SUBCOMMANDS.get(PlotCommand.class)) { + for (String s : CommandManager.SUBCOMMANDS.get(VirtualRealtyCommand.class)) { if (s == null || s.isEmpty()) continue; aliasesHashMap.put(s, s); } @@ -126,7 +150,7 @@ public void assignAliases() { Optional any = CommandRegistry.VRPLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> subCommand.getSubCommandClassName().equalsIgnoreCase(original)).findAny(); any.ifPresent(subCommand -> subCommand.setAlias(alias)); }); - plotAliases.forEach((original, alias) -> { + plotAliases.getAliasesMap().forEach((original, alias) -> { Optional any = CommandRegistry.PLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> subCommand.getSubCommandClassName().equalsIgnoreCase(original)).findAny(); any.ifPresent(subCommand -> subCommand.setAlias(alias)); }); diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/migrations/C0001_Remove_Old_Plot_Sub_Commands.java b/src/main/java/com/modnmetl/virtualrealty/configs/migrations/C0001_Remove_Old_Plot_Sub_Commands.java new file mode 100644 index 0000000..f69cc25 --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/configs/migrations/C0001_Remove_Old_Plot_Sub_Commands.java @@ -0,0 +1,16 @@ +package com.modnmetl.virtualrealty.configs.migrations; + +import eu.okaeri.configs.migrate.builtin.NamedMigration; + +import static eu.okaeri.configs.migrate.ConfigMigrationDsl.delete; + +public class C0001_Remove_Old_Plot_Sub_Commands extends NamedMigration { + + public C0001_Remove_Old_Plot_Sub_Commands() { + super( + "Removing unused subcommands for plot command", + delete("plot-aliases.stake"), + delete("plot-aliases.draft") + ); + } +} \ No newline at end of file diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java b/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java index 8fa76f8..0a3cadd 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java @@ -1,6 +1,8 @@ package com.modnmetl.virtualrealty.utils.configuration; +import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.configs.*; +import com.modnmetl.virtualrealty.configs.migrations.C0001_Remove_Old_Plot_Sub_Commands; import eu.okaeri.configs.ConfigManager; import eu.okaeri.configs.postprocessor.SectionSeparator; import eu.okaeri.configs.validator.okaeri.OkaeriValidator; @@ -17,6 +19,7 @@ public PluginConfiguration loadPluginConfiguration(File pluginConfigurationFile) return ConfigManager.create(PluginConfiguration.class, (it) -> { it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit()); it.withBindFile(pluginConfigurationFile); + it.withRemoveOrphans(true); it.saveDefaults(); it.load(true); }); @@ -26,6 +29,7 @@ public SizesConfiguration loadSizesConfiguration(File sizesConfigurationFile) { return ConfigManager.create(SizesConfiguration.class, (it) -> { it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit()); it.withBindFile(sizesConfigurationFile); + it.withRemoveOrphans(true); it.saveDefaults(); it.load(true); }); @@ -35,6 +39,7 @@ public MessagesConfiguration loadMessagesConfiguration(File messagesConfiguratio return ConfigManager.create(MessagesConfiguration.class, (it) -> { it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit()); it.withBindFile(messagesConfigurationFile); + it.withRemoveOrphans(true); it.saveDefaults(); it.load(true); }); @@ -53,8 +58,13 @@ public CommandsConfiguration loadCommandsConfiguration(File commandsConfiguratio return ConfigManager.create(CommandsConfiguration.class, (it) -> { it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit()); it.withBindFile(commandsConfigurationFile); + it.withLogger(VirtualRealty.getInstance().getLogger()); + it.withRemoveOrphans(true); it.saveDefaults(); it.load(true); + it.migrate( + new C0001_Remove_Old_Plot_Sub_Commands() + ); }); } @@ -62,6 +72,7 @@ public PermissionsConfiguration updatePluginConfiguration(File pluginConfigurati return ConfigManager.create(PermissionsConfiguration.class, (it) -> { it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit()); it.withBindFile(pluginConfigurationFile); + it.withRemoveOrphans(true); it.saveDefaults(); it.update(); }); @@ -94,4 +105,13 @@ public PermissionsConfiguration updatePermissionsConfiguration(File permissionsC }); } + public CommandsConfiguration updateCommandsConfiguration(File commandsConfigurationFile) { + return ConfigManager.create(CommandsConfiguration.class, (it) -> { + it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit()); + it.withBindFile(commandsConfigurationFile); + it.withRemoveOrphans(true); + it.update(); + }); + } + } From f4e3e008b17076ff66a341387dd8f850df485c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Thu, 3 Nov 2022 23:23:27 +0100 Subject: [PATCH 08/10] v2.5.0 - release --- .../commands/CommandManager.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java index ab50b35..ff11cf9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java @@ -5,12 +5,14 @@ import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand; import com.modnmetl.virtualrealty.enums.PlotSize; import com.modnmetl.virtualrealty.enums.commands.CommandType; +import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.EnumUtils; import lombok.SneakyThrows; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -369,13 +371,13 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman @NotNull String[] finalArgs = args; @NotNull String[] finalArgs1 = args; switch (args[0].toUpperCase(Locale.ROOT)) { - case "KICK": case "ADD": { if (args.length == 2) { PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> { + if (plot.getMember(player.getUniqueId()) != null && !plot.getMember(player.getUniqueId()).hasManagementPermission(ManagementPermission.ADD_MEMBER)) return; if (finalArgs[1].isEmpty()) { tabCompleter.add(String.valueOf(plot.getID())); - } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[0].toLowerCase())) { + } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[1].toLowerCase())) { tabCompleter.add(String.valueOf(plot.getID())); } }); @@ -386,24 +388,53 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman if (onlinePlayer.getName().equals(player.getName())) continue; if (args[2].isEmpty()) { tabCompleter.add(onlinePlayer.getName()); - } else if (onlinePlayer.getName().toLowerCase().startsWith(args[1].toLowerCase())) { + } else if (onlinePlayer.getName().toLowerCase().startsWith(args[2].toLowerCase())) { tabCompleter.add(onlinePlayer.getName()); } } return tabCompleter; } + break; + } + case "KICK": { + if (args.length == 2) { + PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> { + if (plot.getMember(player.getUniqueId()) != null && !plot.getMember(player.getUniqueId()).hasManagementPermission(ManagementPermission.KICK_MEMBER)) return; + if (finalArgs[1].isEmpty()) { + tabCompleter.add(String.valueOf(plot.getID())); + } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[1].toLowerCase())) { + tabCompleter.add(String.valueOf(plot.getID())); + } + }); + return tabCompleter; + } + if (args.length == 3) { + Plot plot = PlotManager.getInstance().getPlot(Integer.parseInt(args[1])); + if (plot == null) return null; + for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) { + if (Objects.equals(offlinePlayer.getName(), player.getName())) continue; + if (args[2].isEmpty()) { + tabCompleter.add(offlinePlayer.getName()); + } else if (offlinePlayer.getName().toLowerCase().startsWith(args[2].toLowerCase())) { + tabCompleter.add(offlinePlayer.getName()); + } + } + return tabCompleter; + } + break; } case "TP": { if (args.length == 2) { PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> { if (finalArgs1[1].isEmpty()) { tabCompleter.add(String.valueOf(plot.getID())); - } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs1[0].toLowerCase())) { + } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs1[1].toLowerCase())) { tabCompleter.add(String.valueOf(plot.getID())); } }); return tabCompleter; } + break; } } return tabCompleter; From e838c0c047b25ef248fea8e6595b9936374f1b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Sat, 3 Dec 2022 16:02:16 +0100 Subject: [PATCH 09/10] v2.5.0 - definitely the release --- .../modnmetl/virtualrealty/VirtualRealty.java | 36 ++-- .../commands/CommandManager.java | 12 +- .../commands/CommandRegistry.java | 2 +- .../virtualrealty/commands/SubCommand.java | 8 +- .../commands/plot/PlotCommand.java | 9 +- .../plot/subcommand/AddSubCommand.java | 14 +- .../plot/subcommand/GmSubCommand.java | 11 +- .../plot/subcommand/InfoSubCommand.java | 9 +- .../plot/subcommand/KickSubCommand.java | 13 +- .../plot/subcommand/ListSubCommand.java | 9 +- .../plot/subcommand/TpSubCommand.java | 9 +- .../commands/vrplot/VirtualRealtyCommand.java | 7 +- .../vrplot/subcommand/AssignSubCommand.java | 11 +- .../vrplot/subcommand/CreateSubCommand.java | 41 ++-- .../vrplot/subcommand/DebugSubCommand.java | 5 +- .../vrplot/subcommand/InfoSubCommand.java | 8 +- .../vrplot/subcommand/ItemSubCommand.java | 13 +- .../vrplot/subcommand/ListSubCommand.java | 8 +- .../vrplot/subcommand/ReloadSubCommand.java | 11 +- .../vrplot/subcommand/RemoveSubCommand.java | 15 +- .../vrplot/subcommand/SetSubCommand.java | 11 +- .../vrplot/subcommand/TpSubCommand.java | 9 +- .../vrplot/subcommand/UnassignSubCommand.java | 9 +- .../vrplot/subcommand/VersionSubCommand.java | 5 +- .../vrplot/subcommand/VisualSubCommand.java | 11 +- .../configs/CommandsConfiguration.java | 4 +- .../configs/PermissionsConfiguration.java | 4 +- .../configs/PluginConfiguration.java | 6 +- .../configs/SizesConfiguration.java | 3 +- .../C0001_Remove_Old_Plot_Sub_Commands.java | 2 +- .../enums/dynmap/HighlightType.java | 9 - .../virtualrealty/enums/items/VItem.java | 8 - .../FailedCommandException.java | 2 +- .../InsufficientPermissionsException.java | 2 +- .../MaterialMatchException.java | 2 +- .../PlotEntranceListener.java | 12 +- .../VirtualListener.java | 2 +- .../player/PlayerActionListener.java | 43 +++-- .../protection/BorderProtectionListener.java | 15 +- .../protection/PlotProtectionListener.java | 82 ++++---- .../protection/WorldProtectionListener.java | 16 +- .../stake/ConfirmationListener.java | 8 +- .../stake/DraftListener.java | 8 +- .../ConfirmationManager.java | 6 +- .../{managers => manager}/DynmapManager.java | 6 +- .../{managers => manager}/MetricsManager.java | 4 +- .../{managers => manager}/PlotManager.java | 176 +++++++++++++----- .../material}/DoorMaterial.java | 2 +- .../material}/InteractMaterial.java | 2 +- .../material}/StorageMaterial.java | 2 +- .../material}/SwitchMaterial.java | 2 +- .../{objects => model}/math/BlockVector2.java | 2 +- .../{objects => model}/math/BlockVector3.java | 2 +- .../{enums => model/math}/Direction.java | 2 +- .../other}/ChatMessage.java | 5 +- .../commands => model/other}/CommandType.java | 2 +- .../data => model/other}/Confirmation.java | 7 +- .../other}/ConfirmationType.java | 2 +- .../{objects => model/other}/Executable.java | 2 +- .../{enums => model/other}/HighlightType.java | 2 +- .../{enums => model/other}/ServerVersion.java | 2 +- .../virtualrealty/model/other/VItem.java | 8 + .../{enums => model/other}/WorldSetting.java | 2 +- .../permission}/ManagementPermission.java | 4 +- .../permission}/Permission.java | 2 +- .../permission}/RegionPermission.java | 4 +- .../{objects => model/plot}/Plot.java | 73 ++++---- .../data => model/plot}/PlotItem.java | 9 +- .../data => model/plot}/PlotMember.java | 38 ++-- .../{enums => model/plot}/PlotSize.java | 2 +- .../{objects => model}/region/Cuboid.java | 9 +- .../region/GridStructure.java | 79 ++++---- .../data => model/region}/VirtualBlock.java | 8 +- .../region}/VirtualLocation.java | 2 +- .../registry/VirtualPlaceholders.java | 6 +- .../{utils => util}/EnumUtils.java | 4 +- .../PermissionsUtil.java} | 7 +- .../{utils => util}/RegionUtil.java | 16 +- .../{utils => util}/UUIDUtils.java | 4 +- .../{utils => util}/UpdateChecker.java | 4 +- .../{utils => util}/VectorUtils.java | 6 +- .../{utils => util}/WorldUtil.java | 6 +- .../configuration/ConfigurationFactory.java | 5 +- .../{utils => util}/data/DataCompressor.java | 2 +- .../{utils => util}/data/ItemBuilder.java | 2 +- .../data/OldSchematicUtil.java | 10 +- .../{utils => util}/data/SchematicUtil.java | 15 +- .../{utils => util}/data/SkullUtil.java | 3 +- .../loader/CustomClassLoader.java | 2 +- .../{utils => util}/loader/Loader.java | 5 +- .../multiversion/VMaterial.java | 6 +- 91 files changed, 563 insertions(+), 532 deletions(-) rename src/main/java/com/modnmetl/virtualrealty/configs/{migrations => migration}/C0001_Remove_Old_Plot_Sub_Commands.java (89%) delete mode 100644 src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java delete mode 100644 src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java rename src/main/java/com/modnmetl/virtualrealty/{exceptions => exception}/FailedCommandException.java (72%) rename src/main/java/com/modnmetl/virtualrealty/{exceptions => exception}/InsufficientPermissionsException.java (75%) rename src/main/java/com/modnmetl/virtualrealty/{exceptions => exception}/MaterialMatchException.java (75%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/PlotEntranceListener.java (94%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/VirtualListener.java (90%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/player/PlayerActionListener.java (95%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/protection/BorderProtectionListener.java (68%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/protection/PlotProtectionListener.java (93%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/protection/WorldProtectionListener.java (94%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/stake/ConfirmationListener.java (83%) rename src/main/java/com/modnmetl/virtualrealty/{listeners => listener}/stake/DraftListener.java (93%) rename src/main/java/com/modnmetl/virtualrealty/{managers => manager}/ConfirmationManager.java (88%) rename src/main/java/com/modnmetl/virtualrealty/{managers => manager}/DynmapManager.java (97%) rename src/main/java/com/modnmetl/virtualrealty/{managers => manager}/MetricsManager.java (96%) rename src/main/java/com/modnmetl/virtualrealty/{managers => manager}/PlotManager.java (51%) rename src/main/java/com/modnmetl/virtualrealty/{enums/materials => model/material}/DoorMaterial.java (80%) rename src/main/java/com/modnmetl/virtualrealty/{enums/materials => model/material}/InteractMaterial.java (97%) rename src/main/java/com/modnmetl/virtualrealty/{enums/materials => model/material}/StorageMaterial.java (91%) rename src/main/java/com/modnmetl/virtualrealty/{enums/materials => model/material}/SwitchMaterial.java (90%) rename src/main/java/com/modnmetl/virtualrealty/{objects => model}/math/BlockVector2.java (95%) rename src/main/java/com/modnmetl/virtualrealty/{objects => model}/math/BlockVector3.java (96%) rename src/main/java/com/modnmetl/virtualrealty/{enums => model/math}/Direction.java (95%) rename src/main/java/com/modnmetl/virtualrealty/{utils/multiversion => model/other}/ChatMessage.java (90%) rename src/main/java/com/modnmetl/virtualrealty/{enums/commands => model/other}/CommandType.java (50%) rename src/main/java/com/modnmetl/virtualrealty/{objects/data => model/other}/Confirmation.java (83%) rename src/main/java/com/modnmetl/virtualrealty/{enums => model/other}/ConfirmationType.java (62%) rename src/main/java/com/modnmetl/virtualrealty/{objects => model/other}/Executable.java (65%) rename src/main/java/com/modnmetl/virtualrealty/{enums => model/other}/HighlightType.java (58%) rename src/main/java/com/modnmetl/virtualrealty/{enums => model/other}/ServerVersion.java (53%) create mode 100644 src/main/java/com/modnmetl/virtualrealty/model/other/VItem.java rename src/main/java/com/modnmetl/virtualrealty/{enums => model/other}/WorldSetting.java (59%) rename src/main/java/com/modnmetl/virtualrealty/{enums/permissions => model/permission}/ManagementPermission.java (90%) rename src/main/java/com/modnmetl/virtualrealty/{enums => model/permission}/Permission.java (89%) rename src/main/java/com/modnmetl/virtualrealty/{enums/permissions => model/permission}/RegionPermission.java (93%) rename src/main/java/com/modnmetl/virtualrealty/{objects => model/plot}/Plot.java (96%) rename src/main/java/com/modnmetl/virtualrealty/{objects/data => model/plot}/PlotItem.java (95%) rename src/main/java/com/modnmetl/virtualrealty/{objects/data => model/plot}/PlotMember.java (88%) rename src/main/java/com/modnmetl/virtualrealty/{enums => model/plot}/PlotSize.java (98%) rename src/main/java/com/modnmetl/virtualrealty/{objects => model}/region/Cuboid.java (96%) rename src/main/java/com/modnmetl/virtualrealty/{objects => model}/region/GridStructure.java (79%) rename src/main/java/com/modnmetl/virtualrealty/{utils/data => model/region}/VirtualBlock.java (75%) rename src/main/java/com/modnmetl/virtualrealty/{utils/data => model/region}/VirtualLocation.java (89%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/EnumUtils.java (84%) rename src/main/java/com/modnmetl/virtualrealty/{utils/Permissions.java => util/PermissionsUtil.java} (83%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/RegionUtil.java (88%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/UUIDUtils.java (77%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/UpdateChecker.java (95%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/VectorUtils.java (77%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/WorldUtil.java (87%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/configuration/ConfigurationFactory.java (96%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/data/DataCompressor.java (95%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/data/ItemBuilder.java (99%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/data/OldSchematicUtil.java (92%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/data/SchematicUtil.java (96%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/data/SkullUtil.java (96%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/loader/CustomClassLoader.java (81%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/loader/Loader.java (95%) rename src/main/java/com/modnmetl/virtualrealty/{utils => util}/multiversion/VMaterial.java (93%) diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index a9468da..ccb05b3 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -6,26 +6,26 @@ import com.modnmetl.virtualrealty.commands.plot.PlotCommand; import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand; import com.modnmetl.virtualrealty.configs.*; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.enums.ServerVersion; -import com.modnmetl.virtualrealty.exceptions.MaterialMatchException; -import com.modnmetl.virtualrealty.listeners.player.PlayerActionListener; -import com.modnmetl.virtualrealty.listeners.protection.BorderProtectionListener; -import com.modnmetl.virtualrealty.listeners.PlotEntranceListener; -import com.modnmetl.virtualrealty.listeners.protection.PlotProtectionListener; -import com.modnmetl.virtualrealty.listeners.protection.WorldProtectionListener; -import com.modnmetl.virtualrealty.listeners.stake.DraftListener; -import com.modnmetl.virtualrealty.listeners.stake.ConfirmationListener; -import com.modnmetl.virtualrealty.managers.DynmapManager; -import com.modnmetl.virtualrealty.managers.MetricsManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.model.plot.PlotSize; +import com.modnmetl.virtualrealty.model.other.ServerVersion; +import com.modnmetl.virtualrealty.exception.MaterialMatchException; +import com.modnmetl.virtualrealty.listener.player.PlayerActionListener; +import com.modnmetl.virtualrealty.listener.protection.BorderProtectionListener; +import com.modnmetl.virtualrealty.listener.PlotEntranceListener; +import com.modnmetl.virtualrealty.listener.protection.PlotProtectionListener; +import com.modnmetl.virtualrealty.listener.protection.WorldProtectionListener; +import com.modnmetl.virtualrealty.listener.stake.DraftListener; +import com.modnmetl.virtualrealty.listener.stake.ConfirmationListener; +import com.modnmetl.virtualrealty.manager.DynmapManager; +import com.modnmetl.virtualrealty.manager.MetricsManager; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; import com.modnmetl.virtualrealty.registry.VirtualPlaceholders; import com.modnmetl.virtualrealty.sql.Database; -import com.modnmetl.virtualrealty.utils.loader.Loader; -import com.modnmetl.virtualrealty.utils.configuration.ConfigurationFactory; -import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; -import com.modnmetl.virtualrealty.utils.UpdateChecker; +import com.modnmetl.virtualrealty.util.loader.Loader; +import com.modnmetl.virtualrealty.util.configuration.ConfigurationFactory; +import com.modnmetl.virtualrealty.util.multiversion.VMaterial; +import com.modnmetl.virtualrealty.util.UpdateChecker; import com.zaxxer.hikari.HikariDataSource; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java index ff11cf9..929166a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java @@ -3,12 +3,12 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.plot.PlotCommand; import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.enums.commands.CommandType; -import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.EnumUtils; +import com.modnmetl.virtualrealty.model.plot.PlotSize; +import com.modnmetl.virtualrealty.model.other.CommandType; +import com.modnmetl.virtualrealty.model.permission.ManagementPermission; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.util.EnumUtils; import lombok.SneakyThrows; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java index 184fd10..c222ea1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java @@ -1,7 +1,7 @@ package com.modnmetl.virtualrealty.commands; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.commands.CommandType; +import com.modnmetl.virtualrealty.model.other.CommandType; import lombok.SneakyThrows; import java.util.ArrayList; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java index a33658b..5485ff9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java @@ -1,10 +1,10 @@ package com.modnmetl.virtualrealty.commands; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.commands.CommandType; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; +import com.modnmetl.virtualrealty.model.other.CommandType; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.exception.InsufficientPermissionsException; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import lombok.Getter; import lombok.Setter; import lombok.SneakyThrows; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java index 16a19f1..0bee5db 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java @@ -3,22 +3,19 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.CommandRegistry; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.commands.CommandType; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; +import com.modnmetl.virtualrealty.model.other.CommandType; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.logging.Level; -import static com.modnmetl.virtualrealty.commands.CommandRegistry.PLOT_SUB_COMMAND_LIST; - public class PlotCommand implements CommandExecutor { public static final LinkedList HELP_LIST = new LinkedList<>(); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java index 39fc46b..46a9263 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java @@ -2,13 +2,12 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.PlotMember; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.model.permission.ManagementPermission; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.plot.PlotMember; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -16,7 +15,6 @@ import org.bukkit.entity.Player; import java.time.LocalDateTime; -import java.util.Arrays; import java.util.LinkedList; public class AddSubCommand extends SubCommand { diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java index b1e5444..9b515f9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java @@ -2,11 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.PlotMember; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.plot.PlotMember; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -64,7 +63,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeDisabled); return; } - Plot plot = PlotManager.getInstance().getBorderedPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (plot == null) { sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode); return; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java index 466ab97..00d4312 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java @@ -2,11 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java index ca3db5b..12e1e2c 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java @@ -2,13 +2,12 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.PlotMember; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.model.permission.ManagementPermission; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.plot.PlotMember; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java index 2b248e9..d4d0611 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java @@ -2,11 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java index e9b391b..153199b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java @@ -2,11 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java index 426c9e4..278f460 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java @@ -2,12 +2,11 @@ import com.modnmetl.virtualrealty.commands.CommandRegistry; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.commands.CommandType; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; +import com.modnmetl.virtualrealty.model.other.CommandType; +import com.modnmetl.virtualrealty.exception.FailedCommandException; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException; +import com.modnmetl.virtualrealty.exception.InsufficientPermissionsException; import org.bukkit.command.*; -import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java index ef29c16..ddf3fed 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java @@ -2,12 +2,11 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.UUIDUtils; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.util.UUIDUtils; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java index 0896a02..a1aa93c 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java @@ -2,16 +2,16 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.Direction; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.region.Cuboid; -import com.modnmetl.virtualrealty.objects.region.GridStructure; -import com.modnmetl.virtualrealty.utils.RegionUtil; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; +import com.modnmetl.virtualrealty.model.math.Direction; +import com.modnmetl.virtualrealty.model.plot.PlotSize; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.region.Cuboid; +import com.modnmetl.virtualrealty.model.region.GridStructure; +import com.modnmetl.virtualrealty.util.RegionUtil; +import com.modnmetl.virtualrealty.model.other.ChatMessage; +import com.modnmetl.virtualrealty.util.multiversion.VMaterial; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; @@ -88,7 +88,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a } ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.AREA, length, height, width, true); + Plot plot = PlotManager.getInstance().createArea(location, length, height, width); long timeEnd = System.currentTimeMillis(); BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID()))); @@ -135,9 +135,8 @@ public void run() { ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender); return; } - if (args[2].split(":").length == 2) { + if (args[2].split(":").length == 2) floorData = Byte.parseByte(args[2].split(":")[1]); - } } if (args.length >= 4) { try { @@ -150,13 +149,12 @@ public void run() { ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender); return; } - if (args[3].split(":").length == 2) { + if (args[3].split(":").length == 2) borderData = Byte.parseByte(args[3].split(":")[1]); - } } ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.getInstance().createPlot(location, plotSize, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), natural); + Plot plot = PlotManager.getInstance().createPlot(location, plotSize, natural); if (!natural) { if (floorMaterial != null) { plot.setFloorMaterial(floorMaterial, floorData); @@ -252,14 +250,12 @@ public void run() { } ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.getInstance().createPlot(location, PlotSize.CUSTOM, length, height, width, natural); + Plot plot = PlotManager.getInstance().createCustomPlot(location, length, height, width, natural); if (!natural) { - if (floorMaterial != null) { + if (floorMaterial != null) plot.setFloorMaterial(floorMaterial, floorData); - } - if (borderMaterial != null) { + if (borderMaterial != null) plot.setBorderMaterial(borderMaterial, borderData); - } } long timeEnd = System.currentTimeMillis(); BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1); @@ -288,5 +284,4 @@ public void run() { } } - -} +} \ No newline at end of file diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java index ed1a11e..a35fa4d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java @@ -4,9 +4,8 @@ import com.google.gson.JsonParser; import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java index 61014c5..0c0bfff 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java @@ -2,10 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java index d71301b..ebbb550 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java @@ -2,13 +2,12 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.enums.items.VItem; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.objects.data.PlotItem; -import com.modnmetl.virtualrealty.utils.EnumUtils; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.model.plot.PlotSize; +import com.modnmetl.virtualrealty.model.other.VItem; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.model.plot.PlotItem; +import com.modnmetl.virtualrealty.util.EnumUtils; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.Command; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java index 7d0f991..cbbe7c7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java @@ -2,10 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java index d2848b1..0cfa47b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java @@ -2,12 +2,11 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.DynmapManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.DynmapManager; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java index c458f16..80e7338 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java @@ -2,14 +2,13 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.enums.ConfirmationType; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.ConfirmationManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.Confirmation; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.model.other.ConfirmationType; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.ConfirmationManager; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.Confirmation; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java index 84ce257..83e2878 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java @@ -2,12 +2,11 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.UUIDUtils; -import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.util.UUIDUtils; +import com.modnmetl.virtualrealty.util.multiversion.VMaterial; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java index 23a51d5..a1dd7f8 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java @@ -2,11 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java index 5c2b4c6..15492eb 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java @@ -2,11 +2,10 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java index 7aa3945..ace1fe9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java @@ -2,9 +2,8 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java index 1993dc6..ee64607 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java @@ -2,12 +2,11 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; -import com.modnmetl.virtualrealty.exceptions.FailedCommandException; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.region.GridStructure; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; -import lombok.NoArgsConstructor; +import com.modnmetl.virtualrealty.exception.FailedCommandException; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.region.GridStructure; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java index ed79713..a999411 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java @@ -5,11 +5,9 @@ import com.modnmetl.virtualrealty.commands.SubCommand; import com.modnmetl.virtualrealty.commands.plot.PlotCommand; import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand; -import com.modnmetl.virtualrealty.enums.commands.CommandType; +import com.modnmetl.virtualrealty.model.other.CommandType; import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.annotation.*; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; import lombok.SneakyThrows; import java.lang.reflect.Field; diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java index 58edb82..f3f6e9d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java @@ -1,11 +1,9 @@ package com.modnmetl.virtualrealty.configs; -import com.modnmetl.virtualrealty.enums.permissions.RegionPermission; +import com.modnmetl.virtualrealty.model.permission.RegionPermission; import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.annotation.*; -import javax.swing.plaf.synth.Region; -import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java index 2e8a597..effab4a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java @@ -1,8 +1,8 @@ package com.modnmetl.virtualrealty.configs; -import com.modnmetl.virtualrealty.enums.WorldSetting; -import com.modnmetl.virtualrealty.enums.dynmap.HighlightType; -import com.modnmetl.virtualrealty.enums.ServerVersion; +import com.modnmetl.virtualrealty.model.other.HighlightType; +import com.modnmetl.virtualrealty.model.other.WorldSetting; +import com.modnmetl.virtualrealty.model.other.ServerVersion; import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.annotation.*; import com.modnmetl.virtualrealty.VirtualRealty; diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java index 1df10df..b7189ce 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java @@ -2,8 +2,7 @@ import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.annotation.*; -import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.PlotSize; +import com.modnmetl.virtualrealty.model.plot.PlotSize; import lombok.NoArgsConstructor; @Header("--------------------------------------------------------------#") diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/migrations/C0001_Remove_Old_Plot_Sub_Commands.java b/src/main/java/com/modnmetl/virtualrealty/configs/migration/C0001_Remove_Old_Plot_Sub_Commands.java similarity index 89% rename from src/main/java/com/modnmetl/virtualrealty/configs/migrations/C0001_Remove_Old_Plot_Sub_Commands.java rename to src/main/java/com/modnmetl/virtualrealty/configs/migration/C0001_Remove_Old_Plot_Sub_Commands.java index f69cc25..3b0ccf1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/migrations/C0001_Remove_Old_Plot_Sub_Commands.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/migration/C0001_Remove_Old_Plot_Sub_Commands.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.configs.migrations; +package com.modnmetl.virtualrealty.configs.migration; import eu.okaeri.configs.migrate.builtin.NamedMigration; diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java b/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java deleted file mode 100644 index 31ca896..0000000 --- a/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.modnmetl.virtualrealty.enums.dynmap; - -public enum HighlightType { - - ALL, - AVAILABLE, - OWNED - -} diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java b/src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java deleted file mode 100644 index 5b8a7c9..0000000 --- a/src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.modnmetl.virtualrealty.enums.items; - -public enum VItem { - - CLAIM, - DRAFT - -} diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java b/src/main/java/com/modnmetl/virtualrealty/exception/FailedCommandException.java similarity index 72% rename from src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java rename to src/main/java/com/modnmetl/virtualrealty/exception/FailedCommandException.java index b221512..9300648 100644 --- a/src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java +++ b/src/main/java/com/modnmetl/virtualrealty/exception/FailedCommandException.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.exceptions; +package com.modnmetl.virtualrealty.exception; public class FailedCommandException extends Exception { diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java b/src/main/java/com/modnmetl/virtualrealty/exception/InsufficientPermissionsException.java similarity index 75% rename from src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java rename to src/main/java/com/modnmetl/virtualrealty/exception/InsufficientPermissionsException.java index b56fdac..1c35e04 100644 --- a/src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java +++ b/src/main/java/com/modnmetl/virtualrealty/exception/InsufficientPermissionsException.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.exceptions; +package com.modnmetl.virtualrealty.exception; public class InsufficientPermissionsException extends Exception { diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java b/src/main/java/com/modnmetl/virtualrealty/exception/MaterialMatchException.java similarity index 75% rename from src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java rename to src/main/java/com/modnmetl/virtualrealty/exception/MaterialMatchException.java index a95b1cb..135d0b7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java +++ b/src/main/java/com/modnmetl/virtualrealty/exception/MaterialMatchException.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.exceptions; +package com.modnmetl.virtualrealty.exception; public class MaterialMatchException extends Exception { diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/PlotEntranceListener.java similarity index 94% rename from src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/PlotEntranceListener.java index c1cb6b4..512360a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/PlotEntranceListener.java @@ -1,10 +1,10 @@ -package com.modnmetl.virtualrealty.listeners; +package com.modnmetl.virtualrealty.listener; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.managers.PlotManager; +import com.modnmetl.virtualrealty.model.plot.PlotSize; +import com.modnmetl.virtualrealty.manager.PlotManager; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.PlotMember; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.plot.PlotMember; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -34,7 +34,7 @@ public void onPlotMove(PlayerMoveEvent e) { Player player = e.getPlayer(); Location to = e.getTo(); if (to == null) return; - Plot plot = PlotManager.getInstance().getPlot(to); + Plot plot = PlotManager.getInstance().getPlot(to, true); if (plot != null) { OfflinePlayer offlinePlayer; String enterPlotString = VirtualRealty.getMessages().enteredAvailablePlot; diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/VirtualListener.java similarity index 90% rename from src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/VirtualListener.java index 8a90af1..44a900f 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/VirtualListener.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.listeners; +package com.modnmetl.virtualrealty.listener; import com.modnmetl.virtualrealty.VirtualRealty; import org.bukkit.event.Listener; diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/player/PlayerActionListener.java similarity index 95% rename from src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/player/PlayerActionListener.java index fef2b57..6662a5d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/player/PlayerActionListener.java @@ -1,22 +1,22 @@ -package com.modnmetl.virtualrealty.listeners.player; +package com.modnmetl.virtualrealty.listener.player; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.ConfirmationType; -import com.modnmetl.virtualrealty.enums.Direction; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.enums.WorldSetting; -import com.modnmetl.virtualrealty.enums.items.VItem; -import com.modnmetl.virtualrealty.listeners.VirtualListener; -import com.modnmetl.virtualrealty.listeners.stake.DraftListener; -import com.modnmetl.virtualrealty.managers.ConfirmationManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.Confirmation; -import com.modnmetl.virtualrealty.objects.data.PlotItem; -import com.modnmetl.virtualrealty.objects.region.Cuboid; -import com.modnmetl.virtualrealty.objects.region.GridStructure; -import com.modnmetl.virtualrealty.utils.RegionUtil; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; +import com.modnmetl.virtualrealty.model.other.ConfirmationType; +import com.modnmetl.virtualrealty.model.math.Direction; +import com.modnmetl.virtualrealty.model.plot.PlotSize; +import com.modnmetl.virtualrealty.model.other.WorldSetting; +import com.modnmetl.virtualrealty.model.other.VItem; +import com.modnmetl.virtualrealty.listener.VirtualListener; +import com.modnmetl.virtualrealty.listener.stake.DraftListener; +import com.modnmetl.virtualrealty.manager.ConfirmationManager; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.other.Confirmation; +import com.modnmetl.virtualrealty.model.plot.PlotItem; +import com.modnmetl.virtualrealty.model.region.Cuboid; +import com.modnmetl.virtualrealty.model.region.GridStructure; +import com.modnmetl.virtualrealty.util.RegionUtil; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import de.tr7zw.nbtapi.NBTItem; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; @@ -29,6 +29,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.scheduler.BukkitRunnable; @@ -67,6 +68,7 @@ public void run() { @EventHandler public void onPlotItemStake(PlayerInteractEvent e) { Player player = e.getPlayer(); + if (e.getHand() == EquipmentSlot.OFF_HAND) return; if (!(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) return; if (!DraftListener.DRAFT_MAP.containsKey(player)) return; e.setCancelled(true); @@ -193,7 +195,7 @@ public void success() { gridStructure.removeGrid(); this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); long timeStart = System.currentTimeMillis(); - Plot plot = PlotManager.getInstance().createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.isNatural()); + Plot plot = PlotManager.getInstance().createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.isNatural()); AbstractMap.SimpleEntry floorData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_floor_material"), item.getByte("vrplot_floor_data")); AbstractMap.SimpleEntry borderData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_border_material"), item.getByte("vrplot_border_data")); if (!plotItem.isNatural()) { @@ -255,6 +257,7 @@ public void expiry() { @EventHandler public void onPlotItemDraft(PlayerInteractEvent e) { Player player = e.getPlayer(); + if (e.getHand() == EquipmentSlot.OFF_HAND) return; if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if (DraftListener.DRAFT_MAP.containsKey(player)) { e.setCancelled(true); @@ -277,7 +280,7 @@ public void onPlotItemDraft(PlayerInteractEvent e) { e.setCancelled(true); PlotItem plotItem = PlotItem.fromItemStack(claimItem); Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); - String featureName = null; + String featureName; if (plot == null) { if (!canCreateInWorld(player)) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); @@ -290,7 +293,7 @@ public void onPlotItemDraft(PlayerInteractEvent e) { featureName = VirtualRealty.getMessages().claimFeature; } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { featureName = VirtualRealty.getMessages().extendFeature; - } + } else return; } else { if (!canCreateInWorld(player)) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation); diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/protection/BorderProtectionListener.java similarity index 68% rename from src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/protection/BorderProtectionListener.java index af236e3..64d46f2 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/protection/BorderProtectionListener.java @@ -1,10 +1,9 @@ -package com.modnmetl.virtualrealty.listeners.protection; +package com.modnmetl.virtualrealty.listener.protection; -import com.modnmetl.virtualrealty.listeners.VirtualListener; +import com.modnmetl.virtualrealty.listener.VirtualListener; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import org.bukkit.command.CommandSender; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; @@ -17,8 +16,9 @@ public BorderProtectionListener(VirtualRealty plugin) { @EventHandler public void onBorderBreak(BlockBreakEvent e) { - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation(), true); if (plot == null) return; + if (plot.isBorderLess()) return; if (e.getPlayer().isOp()) return; if (!plot.getBorderBlocks().contains(e.getBlock())) return; e.setCancelled(true); @@ -27,8 +27,9 @@ public void onBorderBreak(BlockBreakEvent e) { @EventHandler public void onBorderPlace(BlockPlaceEvent e) { - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation(), true); if (plot == null) return; + if (plot.isBorderLess()) return; if (e.getPlayer().isOp()) return; if (!plot.getBorderBlocks().contains(e.getBlock())) return; e.setCancelled(true); diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/protection/PlotProtectionListener.java similarity index 93% rename from src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/protection/PlotProtectionListener.java index fc122ff..708b579 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/protection/PlotProtectionListener.java @@ -1,15 +1,15 @@ -package com.modnmetl.virtualrealty.listeners.protection; +package com.modnmetl.virtualrealty.listener.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; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.data.PlotMember; +import com.modnmetl.virtualrealty.model.material.DoorMaterial; +import com.modnmetl.virtualrealty.model.material.InteractMaterial; +import com.modnmetl.virtualrealty.model.material.StorageMaterial; +import com.modnmetl.virtualrealty.model.permission.RegionPermission; +import com.modnmetl.virtualrealty.model.material.SwitchMaterial; +import com.modnmetl.virtualrealty.listener.VirtualListener; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.plot.PlotMember; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -45,27 +45,23 @@ public class PlotProtectionListener extends VirtualListener { static { for (InteractMaterial value : InteractMaterial.values()) { Material material = Material.getMaterial(value.toString()); - if (Objects.nonNull(material)) { + if (Objects.nonNull(material)) INTERACT.add(material); - } } for (SwitchMaterial value : SwitchMaterial.values()) { Material material = Material.getMaterial(value.toString()); - if (Objects.nonNull(material)) { + if (Objects.nonNull(material)) SWITCHES.add(material); - } } for (StorageMaterial value : StorageMaterial.values()) { Material material = Material.getMaterial(value.toString()); - if (Objects.nonNull(material)) { + if (Objects.nonNull(material)) STORAGES.add(material); - } } for (DoorMaterial value : DoorMaterial.values()) { Material material = Material.getMaterial(value.toString()); - if (Objects.nonNull(material)) { + if (Objects.nonNull(material)) DOORS.add(material); - } } } @@ -83,9 +79,8 @@ public void onMobSpawn(CreatureSpawnEvent e) { if (VirtualRealty.getPluginConfiguration().disablePlotMobsSpawn) { e.setCancelled(true); } else if (VirtualRealty.getPluginConfiguration().disablePlotMonsterSpawn) { - if ((e.getEntity() instanceof Monster) || e.getEntityType() == EntityType.SLIME) { + if ((e.getEntity() instanceof Monster) || e.getEntityType() == EntityType.SLIME) e.setCancelled(true); - } } } } @@ -96,11 +91,10 @@ public void onCropInteract(PlayerInteractEvent e) { Player player = e.getPlayer(); if (e.getAction() != Action.PHYSICAL) return; if (e.getClickedBlock() == null) return; - if (VirtualRealty.legacyVersion) { + if (VirtualRealty.legacyVersion) if (e.getClickedBlock().getType() == Material.getMaterial("CROPS")) return; - } else { - if (e.getClickedBlock().getType() != Material.FARMLAND) return; - } + else + if (e.getClickedBlock().getType() != Material.FARMLAND) return; Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation()); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; @@ -278,7 +272,7 @@ public void onPotInteract(PlayerInteractEvent e) { public void onLiquidPlace(PlayerBucketEmptyEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlockClicked().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlockClicked().getLocation(), true); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -306,7 +300,7 @@ public void onVehicleDestroy(VehicleDestroyEvent e) { if (e.isCancelled()) return; if (!(e.getAttacker() instanceof Player)) return; Player player = (Player) e.getAttacker(); - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getVehicle().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getVehicle().getLocation(), true); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -333,7 +327,7 @@ public void onVehicleDestroy(VehicleDestroyEvent e) { public void onLiquidTake(PlayerBucketFillEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlockClicked().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlockClicked().getLocation(), true); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -359,7 +353,7 @@ public void onLiquidTake(PlayerBucketFillEvent e) { @EventHandler(priority = EventPriority.LOW) public void onBlockPlace(BlockPlaceEvent e) { Player player = e.getPlayer(); - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlockPlaced().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlockPlaced().getLocation(), true); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -386,7 +380,7 @@ public void onBlockPlace(BlockPlaceEvent e) { public void onBlockBreak(BlockBreakEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation(), true); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -417,15 +411,13 @@ public void onPistonRetract(BlockPistonRetractEvent e) { e.getBlocks().forEach(block -> { Location toLocation = block.getLocation(); Plot toPlot = PlotManager.getInstance().getPlot(toLocation); - Plot toBorderedPlot = PlotManager.getInstance().getBorderedPlot(toLocation); + Plot toBorderedPlot = PlotManager.getInstance().getPlot(toLocation, true); if (fromPlot != null) { - if (toPlot == null) { + if (toPlot == null) e.setCancelled(true); - } } else { - if (toBorderedPlot != null) { + if (toBorderedPlot != null) e.setCancelled(true); - } } }); } @@ -436,7 +428,7 @@ public void onBlockMove(BlockPistonExtendEvent e) { for (Block block : e.getBlocks()) { Location blockLocation = block.getLocation(); Plot plot = PlotManager.getInstance().getPlot(blockLocation); - Plot borderedPlot = PlotManager.getInstance().getBorderedPlot(blockLocation); + Plot borderedPlot = PlotManager.getInstance().getPlot(blockLocation, true); if (borderedPlot != null) { if (plot == null) { e.setCancelled(true); @@ -453,7 +445,7 @@ public void onIgniteEvent(BlockIgniteEvent e) { Player player = e.getPlayer(); if (player == null) return; if (e.getIgnitingBlock() == null) return; - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getIgnitingBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation(), true); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -757,7 +749,7 @@ public void onStaticEntityDamage(EntityDamageByEntityEvent e) { @EventHandler(priority = EventPriority.LOW) public void onEntityExplode(EntityExplodeEvent e) { for (Block block : new ArrayList<>(e.blockList())) { - Plot plot = PlotManager.getInstance().getBorderedPlot(block.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(block.getLocation(), true); if (plot != null) e.blockList().remove(block); } @@ -766,7 +758,7 @@ public void onEntityExplode(EntityExplodeEvent e) { @EventHandler(priority = EventPriority.LOW) public void onBlockExplode(BlockExplodeEvent e) { for (Block block : new ArrayList<>(e.blockList())) { - Plot plot = PlotManager.getInstance().getBorderedPlot(block.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(block.getLocation(), true); if (plot != null) e.blockList().remove(block); } @@ -774,10 +766,14 @@ public void onBlockExplode(BlockExplodeEvent e) { @EventHandler public void onFireSpread(BlockSpreadEvent e) { - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getNewState().getLocation()); - if (!(plot != null && (e.getSource().getType() == Material.FIRE && (e.getSource().getType() == e.getNewState().getType() || e.getNewState().getType() == Material.AIR)))) return; + Plot plot = PlotManager.getInstance().getPlot(e.getNewState().getLocation(), true); + if ( + !(plot != null && + (e.getSource().getType() == Material.FIRE && + (e.getSource().getType() == e.getNewState().getType() || + e.getNewState().getType() == Material.AIR))) + ) return; e.setCancelled(true); - VirtualRealty.debug("Cancelled " + e.getClass().getSimpleName() + " [Fire Spread]: " + e.getSource().getLocation()); } @EventHandler @@ -801,7 +797,7 @@ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) { if (!((e.getDamager() instanceof Projectile) && ((Projectile) e.getDamager()).getShooter() instanceof Player)) return; Player player = ((Player) ((Projectile) e.getDamager()).getShooter()); - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getDamager().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getDamager().getLocation(), true); if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { @@ -828,4 +824,4 @@ public boolean hasPermission(CommandSender sender, Permission permission) { return sender.hasPermission(permission); } -} +} \ No newline at end of file diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/protection/WorldProtectionListener.java similarity index 94% rename from src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/protection/WorldProtectionListener.java index 469854c..68592ca 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/protection/WorldProtectionListener.java @@ -1,11 +1,11 @@ -package com.modnmetl.virtualrealty.listeners.protection; +package com.modnmetl.virtualrealty.listener.protection; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.permissions.RegionPermission; -import com.modnmetl.virtualrealty.listeners.VirtualListener; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.WorldUtil; +import com.modnmetl.virtualrealty.model.permission.RegionPermission; +import com.modnmetl.virtualrealty.listener.VirtualListener; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.util.WorldUtil; import org.bukkit.Material; import org.bukkit.block.data.type.Switch; import org.bukkit.command.CommandSender; @@ -113,7 +113,7 @@ public void onIgniteEvent(BlockIgniteEvent e) { Player player = e.getPlayer(); if (player == null) return; if (e.getIgnitingBlock() == null) return; - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getIgnitingBlock().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation()); if (plot != null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.ITEM_USE)) return; @@ -179,7 +179,7 @@ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) { if (!((e.getDamager() instanceof Projectile) && ((Projectile) e.getDamager()).getShooter() instanceof Player)) return; Player player = ((Player) ((Projectile) e.getDamager()).getShooter()); - Plot plot = PlotManager.getInstance().getBorderedPlot(e.getDamager().getLocation()); + Plot plot = PlotManager.getInstance().getPlot(e.getDamager().getLocation()); if (plot == null) return; if (hasPermission(player, WORLD_BUILD)) return; if (WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) return; diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/stake/ConfirmationListener.java similarity index 83% rename from src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/stake/ConfirmationListener.java index af26182..ec5efda 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/stake/ConfirmationListener.java @@ -1,9 +1,9 @@ -package com.modnmetl.virtualrealty.listeners.stake; +package com.modnmetl.virtualrealty.listener.stake; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.listeners.VirtualListener; -import com.modnmetl.virtualrealty.managers.ConfirmationManager; -import com.modnmetl.virtualrealty.objects.data.Confirmation; +import com.modnmetl.virtualrealty.listener.VirtualListener; +import com.modnmetl.virtualrealty.manager.ConfirmationManager; +import com.modnmetl.virtualrealty.model.other.Confirmation; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/stake/DraftListener.java similarity index 93% rename from src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java rename to src/main/java/com/modnmetl/virtualrealty/listener/stake/DraftListener.java index 0b02b11..38c9f70 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listener/stake/DraftListener.java @@ -1,9 +1,9 @@ -package com.modnmetl.virtualrealty.listeners.stake; +package com.modnmetl.virtualrealty.listener.stake; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.listeners.VirtualListener; -import com.modnmetl.virtualrealty.objects.data.PlotItem; -import com.modnmetl.virtualrealty.objects.region.GridStructure; +import com.modnmetl.virtualrealty.listener.VirtualListener; +import com.modnmetl.virtualrealty.model.plot.PlotItem; +import com.modnmetl.virtualrealty.model.region.GridStructure; import de.tr7zw.nbtapi.NBTItem; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/ConfirmationManager.java similarity index 88% rename from src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java rename to src/main/java/com/modnmetl/virtualrealty/manager/ConfirmationManager.java index e52db8a..eb17958 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/manager/ConfirmationManager.java @@ -1,7 +1,7 @@ -package com.modnmetl.virtualrealty.managers; +package com.modnmetl.virtualrealty.manager; -import com.modnmetl.virtualrealty.enums.ConfirmationType; -import com.modnmetl.virtualrealty.objects.data.Confirmation; +import com.modnmetl.virtualrealty.model.other.ConfirmationType; +import com.modnmetl.virtualrealty.model.other.Confirmation; import lombok.Getter; import java.util.ArrayList; diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/DynmapManager.java similarity index 97% rename from src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java rename to src/main/java/com/modnmetl/virtualrealty/manager/DynmapManager.java index 89a4aca..6e8d41d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/manager/DynmapManager.java @@ -1,8 +1,8 @@ -package com.modnmetl.virtualrealty.managers; +package com.modnmetl.virtualrealty.manager; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.dynmap.HighlightType; -import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.model.other.HighlightType; +import com.modnmetl.virtualrealty.model.plot.Plot; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/MetricsManager.java similarity index 96% rename from src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java rename to src/main/java/com/modnmetl/virtualrealty/manager/MetricsManager.java index 480196f..f3da919 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/manager/MetricsManager.java @@ -1,7 +1,7 @@ -package com.modnmetl.virtualrealty.managers; +package com.modnmetl.virtualrealty.manager; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.model.plot.Plot; import lombok.Getter; import org.bstats.bukkit.Metrics; import org.bstats.charts.AdvancedPie; diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/PlotManager.java similarity index 51% rename from src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java rename to src/main/java/com/modnmetl/virtualrealty/manager/PlotManager.java index 2305af2..e42faa5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/manager/PlotManager.java @@ -1,11 +1,11 @@ -package com.modnmetl.virtualrealty.managers; +package com.modnmetl.virtualrealty.manager; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.objects.data.PlotMember; +import com.modnmetl.virtualrealty.model.plot.PlotSize; +import com.modnmetl.virtualrealty.model.plot.PlotMember; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.objects.region.Cuboid; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.math.BlockVector3; +import com.modnmetl.virtualrealty.model.region.Cuboid; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.math.BlockVector3; import com.modnmetl.virtualrealty.sql.Database; import lombok.Data; import org.bukkit.Location; @@ -15,9 +15,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.*; +import java.util.logging.Level; @Data -public class PlotManager { +public final class PlotManager { private final VirtualRealty plugin; @@ -31,13 +32,11 @@ public PlotManager(VirtualRealty plugin) { this.plotMembers = new ArrayList<>(); } - public void loadPlots() { try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`"); ResultSet rs = ps.executeQuery()) { plots.clear(); - while (rs.next()) { + while (rs.next()) plots.add(new Plot(rs)); - } } catch (Exception e) { e.printStackTrace(); } @@ -45,9 +44,8 @@ public void loadPlots() { public void loadMembers() { try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`"); ResultSet rs = ps.executeQuery()) { - while (rs.next()) { + while (rs.next()) plotMembers.add(new PlotMember(rs)); - } checkDupes(); } catch (Exception e) { e.printStackTrace(); @@ -57,8 +55,16 @@ public void loadMembers() { public void checkDupes() { HashMap dupes = new HashMap<>(); for (PlotMember plotMember : plotMembers) { - if (dupes.containsKey(plotMember.getUuid()) && dupes.get(plotMember.getUuid()) == plotMember.getPlot().getID()) { - VirtualRealty.debug("Found duped plot member: " + plotMember.getUuid() + " | " + plotMember.getPlot().getID() + " - Removing.."); + int plotId; + try { + plotId = plotMember.getPlot().getID(); + } catch (Exception e) { + VirtualRealty.getInstance().getLogger().log(Level.WARNING, "Removal of plot member for lack of allocated plot | UUID: " + plotMember.getUuid()); + plotMember.delete(); + continue; + } + if (dupes.containsKey(plotMember.getUuid()) && dupes.get(plotMember.getUuid()) == plotId) { + VirtualRealty.debug("Found duped plot member: " + plotMember.getUuid() + " | " + plotId + " - Removing from database.."); plotMember.getPlot().removeMember(plotMember); } else { dupes.put(plotMember.getUuid(), plotMember.getPlot().getID()); @@ -66,8 +72,73 @@ public void checkDupes() { } } - public Plot createPlot(Location creationLocation, PlotSize plotSize, int length, int height, int width, boolean natural) { - Plot plot = new Plot(creationLocation, Material.matchMaterial(VirtualRealty.legacyVersion ? "GRASS" : "GRASS_BLOCK"), Material.matchMaterial(VirtualRealty.legacyVersion ? "STEP" : "STONE_BRICK_SLAB"), plotSize, length, width, height, natural); + public Plot createPlot(Location creationLocation, PlotSize plotSize, boolean natural) { + return createPlot( + creationLocation, + plotSize, + plotSize.getLength(), + plotSize.getHeight(), + plotSize.getWidth(), + plotSize.getFloorMaterial(), + plotSize.getFloorMaterial(), + natural + ); + } + + public Plot createPlot(Location creationLocation, PlotSize plotSize, boolean natural, Material floorMaterial, Material borderMaterial) { + return createPlot( + creationLocation, + plotSize, + plotSize.getLength(), + plotSize.getHeight(), + plotSize.getWidth(), + floorMaterial, + borderMaterial, + natural + ); + } + + public Plot createCustomPlot(Location creationLocation, int length, int height, int width, boolean natural) { + return createPlot( + creationLocation, + PlotSize.CUSTOM, + length, + height, + width, + PlotSize.CUSTOM.getFloorMaterial(), + PlotSize.CUSTOM.getBorderMaterial(), + natural + ); + } + + public Plot createCustomPlot(Location creationLocation, int length, int height, int width, boolean natural, Material floorMaterial, Material borderMaterial) { + return createPlot( + creationLocation, + PlotSize.CUSTOM, + length, + height, + width, + floorMaterial, + borderMaterial, + natural + ); + } + + public Plot createArea(Location creationLocation, int length, int height, int width) { + return createPlot( + creationLocation, + PlotSize.AREA, + length, + height, + width, + Material.AIR, + Material.AIR, + true + ); + } + + private Plot createPlot(Location creationLocation, PlotSize plotSize, int length, int height, int width, Material floorMaterial, Material borderMaterial, boolean natural) { + Plot plot = new Plot(creationLocation, floorMaterial, borderMaterial, plotSize, length, width, height, natural); plots.add(plot); long time = System.currentTimeMillis(); plot.insert(); @@ -77,27 +148,24 @@ public Plot createPlot(Location creationLocation, PlotSize plotSize, int length, public Plot getPlot(int ID) { for (Plot plot : plots) { - if (plot.getID() == ID) { + if (plot.getID() == ID) return plot; - } } return null; } public List getPlots(String world) { List newPlots = new LinkedList<>(); - for (Plot plot : plots) { + for (Plot plot : plots) if (plot.getCreatedWorldString().equals(world)) newPlots.add(plot); - } return newPlots; } public HashMap getPlots(UUID owner) { HashMap plotHashMap = new HashMap<>(); for (Plot plot : plots) { - if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(owner)) { + if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(owner)) plotHashMap.put(plot.getID(), plot); - } } return plotHashMap; } @@ -105,9 +173,8 @@ public HashMap getPlots(UUID owner) { public HashMap getAccessPlots(UUID player) { HashMap plotHashMap = new HashMap<>(); for (Plot plot : plots) { - if (plot.getMember(player) != null || (plot.getOwnedBy() != null && plot.getPlotOwner().getUniqueId() == player)) { + if (plot.getMember(player) != null || (plot.getOwnedBy() != null && plot.getPlotOwner().getUniqueId() == player)) plotHashMap.put(plot.getID(), plot); - } } return plotHashMap; } @@ -125,43 +192,68 @@ public int getPlotMaxID() { public List getPlayerPlots(UUID owner) { LinkedList playerPlots = new LinkedList<>(); for (Plot plot : plots) { - if (plot.getOwnedBy() != null) { - if (plot.getOwnedBy().equals(owner)) { - playerPlots.add(plot); - } - } + if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(owner)) + playerPlots.add(plot); } return playerPlots; } + public void removePlotFromCollection(Plot plot) { + plots.remove(plot); + } + + public boolean isLocationInPlot(Location location, Plot plot) { + BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); + return region.isIn(newVector, location.getWorld()); + } + +// public Plot getPlot(Location location) { +// BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); +// for (Plot plot : plots) { +// Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); +// if (region.isIn(newVector, plot.getCreatedWorld())) { +// return plot; +// } +// } +// return null; +// } +// + public Plot getPlot(Location location) { BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); for (Plot plot : plots) { - Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); - if (region.isIn(newVector, plot.getCreatedWorld())) { - return plot; + if (plot.isBorderLess()) { + return getBorderedPlot(location); + } else { + Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); + if (region.isIn(newVector, plot.getCreatedWorld())) + return plot; } } return null; } - public void removePlotFromCollection(Plot plot) { - plots.remove(plot); - } - - public boolean isLocationInPlot(Location location, Plot plot) { + public Plot getPlot(Location location, boolean withBorder) { BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); - return region.isIn(newVector, location.getWorld()); + for (Plot plot : plots) { + if (withBorder) { + return getBorderedPlot(location); + } else { + Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld()); + if (region.isIn(newVector, plot.getCreatedWorld())) + return plot; + } + } + return null; } - public Plot getBorderedPlot(Location location) { + private Plot getBorderedPlot(Location location) { BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); for (Plot plot : plots) { Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld()); - if (region.isIn(newVector, plot.getCreatedWorld())) { + if (region.isIn(newVector, plot.getCreatedWorld())) return plot; - } } return null; } diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/DoorMaterial.java similarity index 80% rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java rename to src/main/java/com/modnmetl/virtualrealty/model/material/DoorMaterial.java index 1c9e466..4df87a3 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/material/DoorMaterial.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums.materials; +package com.modnmetl.virtualrealty.model.material; public enum DoorMaterial { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/InteractMaterial.java similarity index 97% rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java rename to src/main/java/com/modnmetl/virtualrealty/model/material/InteractMaterial.java index 9850029..0fff730 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/material/InteractMaterial.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums.materials; +package com.modnmetl.virtualrealty.model.material; public enum InteractMaterial { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/StorageMaterial.java similarity index 91% rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java rename to src/main/java/com/modnmetl/virtualrealty/model/material/StorageMaterial.java index 882855a..833f16c 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/material/StorageMaterial.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums.materials; +package com.modnmetl.virtualrealty.model.material; public enum StorageMaterial { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/SwitchMaterial.java similarity index 90% rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java rename to src/main/java/com/modnmetl/virtualrealty/model/material/SwitchMaterial.java index c0bd071..be536b1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/material/SwitchMaterial.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums.materials; +package com.modnmetl.virtualrealty.model.material; public enum SwitchMaterial { diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector2.java similarity index 95% rename from src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java rename to src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector2.java index 2d3ff64..35f895d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector2.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.objects.math; +package com.modnmetl.virtualrealty.model.math; import org.bukkit.Location; import org.bukkit.World; diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector3.java similarity index 96% rename from src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java rename to src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector3.java index d8acf26..4a073ea 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector3.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.objects.math; +package com.modnmetl.virtualrealty.model.math; import org.bukkit.Location; import org.bukkit.World; diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java b/src/main/java/com/modnmetl/virtualrealty/model/math/Direction.java similarity index 95% rename from src/main/java/com/modnmetl/virtualrealty/enums/Direction.java rename to src/main/java/com/modnmetl/virtualrealty/model/math/Direction.java index d03e5b1..07b3d02 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/math/Direction.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums; +package com.modnmetl.virtualrealty.model.math; public enum Direction { diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/ChatMessage.java b/src/main/java/com/modnmetl/virtualrealty/model/other/ChatMessage.java similarity index 90% rename from src/main/java/com/modnmetl/virtualrealty/utils/multiversion/ChatMessage.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/ChatMessage.java index d76f68b..db3381f 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/ChatMessage.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/ChatMessage.java @@ -1,13 +1,10 @@ -package com.modnmetl.virtualrealty.utils.multiversion; +package com.modnmetl.virtualrealty.model.other; import com.modnmetl.virtualrealty.VirtualRealty; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.CommandSender; -import java.util.Arrays; -import java.util.TimerTask; - public class ChatMessage { private final BaseComponent message; diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java b/src/main/java/com/modnmetl/virtualrealty/model/other/CommandType.java similarity index 50% rename from src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/CommandType.java index 5a85ab2..1a2f63f 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/CommandType.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums.commands; +package com.modnmetl.virtualrealty.model.other; public enum CommandType { diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java b/src/main/java/com/modnmetl/virtualrealty/model/other/Confirmation.java similarity index 83% rename from src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/Confirmation.java index a8092e1..015e8bc 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/Confirmation.java @@ -1,10 +1,7 @@ -package com.modnmetl.virtualrealty.objects.data; +package com.modnmetl.virtualrealty.model.other; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.ConfirmationType; -import com.modnmetl.virtualrealty.managers.ConfirmationManager; -import com.modnmetl.virtualrealty.objects.Executable; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; +import com.modnmetl.virtualrealty.manager.ConfirmationManager; import lombok.Getter; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java b/src/main/java/com/modnmetl/virtualrealty/model/other/ConfirmationType.java similarity index 62% rename from src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/ConfirmationType.java index bd1e14a..a623dd2 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/ConfirmationType.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums; +package com.modnmetl.virtualrealty.model.other; public enum ConfirmationType { diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java b/src/main/java/com/modnmetl/virtualrealty/model/other/Executable.java similarity index 65% rename from src/main/java/com/modnmetl/virtualrealty/objects/Executable.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/Executable.java index 03f4762..2311b04 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/Executable.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.objects; +package com.modnmetl.virtualrealty.model.other; public interface Executable { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java b/src/main/java/com/modnmetl/virtualrealty/model/other/HighlightType.java similarity index 58% rename from src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/HighlightType.java index d9e3bb9..65af39b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/HighlightType.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums; +package com.modnmetl.virtualrealty.model.other; public enum HighlightType { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java b/src/main/java/com/modnmetl/virtualrealty/model/other/ServerVersion.java similarity index 53% rename from src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/ServerVersion.java index 951ab5a..6586173 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/ServerVersion.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums; +package com.modnmetl.virtualrealty.model.other; public enum ServerVersion { diff --git a/src/main/java/com/modnmetl/virtualrealty/model/other/VItem.java b/src/main/java/com/modnmetl/virtualrealty/model/other/VItem.java new file mode 100644 index 0000000..6a412c7 --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/VItem.java @@ -0,0 +1,8 @@ +package com.modnmetl.virtualrealty.model.other; + +public enum VItem { + + CLAIM, + DRAFT + +} diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/WorldSetting.java b/src/main/java/com/modnmetl/virtualrealty/model/other/WorldSetting.java similarity index 59% rename from src/main/java/com/modnmetl/virtualrealty/enums/WorldSetting.java rename to src/main/java/com/modnmetl/virtualrealty/model/other/WorldSetting.java index 9cfc903..fa9c755 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/WorldSetting.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/other/WorldSetting.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums; +package com.modnmetl.virtualrealty.model.other; public enum WorldSetting { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java b/src/main/java/com/modnmetl/virtualrealty/model/permission/ManagementPermission.java similarity index 90% rename from src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java rename to src/main/java/com/modnmetl/virtualrealty/model/permission/ManagementPermission.java index 2267a22..81c51c1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/permission/ManagementPermission.java @@ -1,7 +1,7 @@ -package com.modnmetl.virtualrealty.enums.permissions; +package com.modnmetl.virtualrealty.model.permission; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.utils.data.ItemBuilder; +import com.modnmetl.virtualrealty.util.data.ItemBuilder; import lombok.Getter; import org.bukkit.Material; import org.bukkit.inventory.ItemFlag; diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/Permission.java b/src/main/java/com/modnmetl/virtualrealty/model/permission/Permission.java similarity index 89% rename from src/main/java/com/modnmetl/virtualrealty/enums/Permission.java rename to src/main/java/com/modnmetl/virtualrealty/model/permission/Permission.java index e84f66c..85f74ca 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/Permission.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/permission/Permission.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums; +package com.modnmetl.virtualrealty.model.permission; public enum Permission { diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java b/src/main/java/com/modnmetl/virtualrealty/model/permission/RegionPermission.java similarity index 93% rename from src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java rename to src/main/java/com/modnmetl/virtualrealty/model/permission/RegionPermission.java index fa33974..48db04a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/permission/RegionPermission.java @@ -1,7 +1,7 @@ -package com.modnmetl.virtualrealty.enums.permissions; +package com.modnmetl.virtualrealty.model.permission; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.utils.data.ItemBuilder; +import com.modnmetl.virtualrealty.util.data.ItemBuilder; import lombok.Getter; import org.bukkit.Material; import org.bukkit.inventory.ItemFlag; diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/Plot.java similarity index 96% rename from src/main/java/com/modnmetl/virtualrealty/objects/Plot.java rename to src/main/java/com/modnmetl/virtualrealty/model/plot/Plot.java index c166f44..6298791 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/Plot.java @@ -1,20 +1,17 @@ -package com.modnmetl.virtualrealty.objects; +package com.modnmetl.virtualrealty.model.plot; import com.modnmetl.virtualrealty.configs.PluginConfiguration; -import com.modnmetl.virtualrealty.enums.Direction; -import com.modnmetl.virtualrealty.enums.permissions.RegionPermission; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.managers.DynmapManager; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.data.PlotMember; -import com.modnmetl.virtualrealty.objects.region.Cuboid; -import com.modnmetl.virtualrealty.objects.region.GridStructure; +import com.modnmetl.virtualrealty.model.math.Direction; +import com.modnmetl.virtualrealty.model.permission.RegionPermission; +import com.modnmetl.virtualrealty.manager.DynmapManager; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.region.Cuboid; import com.modnmetl.virtualrealty.sql.Database; -import com.modnmetl.virtualrealty.utils.EnumUtils; -import com.modnmetl.virtualrealty.utils.data.OldSchematicUtil; -import com.modnmetl.virtualrealty.utils.data.SchematicUtil; +import com.modnmetl.virtualrealty.util.EnumUtils; +import com.modnmetl.virtualrealty.util.data.OldSchematicUtil; +import com.modnmetl.virtualrealty.util.data.SchematicUtil; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.objects.math.BlockVector3; +import com.modnmetl.virtualrealty.model.math.BlockVector3; import lombok.Getter; import lombok.Setter; import lombok.SneakyThrows; @@ -33,7 +30,7 @@ @Getter @Setter -public class Plot { +public final class Plot { public static final LocalDateTime MAX_DATE = LocalDateTime.of(2999, 12, 31, 0, 0); public static final DateTimeFormatter PLOT_DATE_FORMAT = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); @@ -84,9 +81,8 @@ public Plot(Location location, Material floorMaterial, Material borderMaterial, this.width = width; this.height = height; initialize(natural); - if (VirtualRealty.getDynmapManager() != null && VirtualRealty.getDynmapManager().markerset != null) { + if (VirtualRealty.getDynmapManager() != null && VirtualRealty.getDynmapManager().markerset != null) DynmapManager.resetPlotMarker(this); - } } @SneakyThrows @@ -203,9 +199,9 @@ public PlotMember getMember(UUID uuid) { } public void addMember(UUID uuid) { - PlotMember plotMember = new PlotMember(uuid, this); - members.add(plotMember); + PlotMember plotMember = new PlotMember(uuid, this.getID()); plotMember.insert(); + members.add(plotMember); } public void removeMember(PlotMember plotMember) { @@ -259,21 +255,6 @@ public void setFloorMaterial(Material floorMaterial, byte data) { initializeFloor(); } - private void initializeFloor() { - for (Block floorBlock : getFloorBlocks()) { - floorBlock.setType(this.floorMaterial); - if (VirtualRealty.legacyVersion) { - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, this.floorData); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - } - } - public void setBorderMaterial(Material borderMaterial, byte data) { modified(); this.borderMaterial = borderMaterial; @@ -310,6 +291,10 @@ public String getCreatedWorldString() { return createdWorld; } + public boolean isBorderLess() { + return this.borderMaterial == Material.AIR || this.plotSize == PlotSize.AREA; + } + public OfflinePlayer getPlotOwner() { return ownedBy == null ? null : Bukkit.getOfflinePlayer(ownedBy); } @@ -371,7 +356,8 @@ public void prepareCorners() { public void initialize(boolean natural) { long time = System.currentTimeMillis(); prepareCorners(); - if (plotSize != PlotSize.AREA) prepareBlocks(createdLocation, natural); + if (plotSize != PlotSize.AREA) + prepareRegion(createdLocation, natural); VirtualRealty.debug("Plot initialization time: " + (System.currentTimeMillis() - time) + " ms"); } @@ -473,7 +459,7 @@ public Set getFloorBlocks() { return blocks; } - public void prepareBlocks(Location location, boolean natural) { + public void prepareRegion(Location location, boolean natural) { Direction direction = Direction.byYaw(location.getYaw()); Location location1; Location location2; @@ -601,13 +587,28 @@ public void unloadPlot() { } } OldSchematicUtil.paste(ID, location); - VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms (Old Serialization)"); + VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms [old-serialization]"); } private void modified() { modified = Instant.now(); } + private void initializeFloor() { + for (Block floorBlock : getFloorBlocks()) { + floorBlock.setType(this.floorMaterial); + if (VirtualRealty.legacyVersion) { + try { + Method m2 = Block.class.getDeclaredMethod("setData", byte.class); + m2.setAccessible(true); + m2.invoke(floorBlock, this.floorData); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + } + } + private String getNonMemberPermissionsString() { StringBuilder permissions = new StringBuilder(); for (RegionPermission permission : this.nonMemberPermissions) { diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotItem.java similarity index 95% rename from src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java rename to src/main/java/com/modnmetl/virtualrealty/model/plot/PlotItem.java index 94cd20b..5a5704f 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotItem.java @@ -1,10 +1,9 @@ -package com.modnmetl.virtualrealty.objects.data; +package com.modnmetl.virtualrealty.model.plot; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.PlotSize; -import com.modnmetl.virtualrealty.enums.items.VItem; -import com.modnmetl.virtualrealty.utils.data.ItemBuilder; -import com.modnmetl.virtualrealty.utils.data.SkullUtil; +import com.modnmetl.virtualrealty.model.other.VItem; +import com.modnmetl.virtualrealty.util.data.ItemBuilder; +import com.modnmetl.virtualrealty.util.data.SkullUtil; import de.tr7zw.nbtapi.NBTItem; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotMember.java similarity index 88% rename from src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java rename to src/main/java/com/modnmetl/virtualrealty/model/plot/PlotMember.java index 2331247..24f3b21 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotMember.java @@ -1,21 +1,17 @@ -package com.modnmetl.virtualrealty.objects.data; +package com.modnmetl.virtualrealty.model.plot; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission; -import com.modnmetl.virtualrealty.enums.permissions.RegionPermission; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.model.permission.ManagementPermission; +import com.modnmetl.virtualrealty.model.permission.RegionPermission; +import com.modnmetl.virtualrealty.manager.PlotManager; import com.modnmetl.virtualrealty.sql.Database; import lombok.Data; -import lombok.Setter; import lombok.SneakyThrows; import org.bukkit.GameMode; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.Timestamp; -import java.time.Instant; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -24,15 +20,16 @@ public class PlotMember { private final UUID uuid; - private final Plot plot; + + private final int plotId; private GameMode selectedGameMode; private final Set permissions; private final Set managementPermissions; - public PlotMember(UUID uuid, Plot plot) { + public PlotMember(UUID uuid, int plotId) { this.uuid = uuid; - this.plot = plot; - this.selectedGameMode = plot.getSelectedGameMode(); + this.plotId = plotId; + this.selectedGameMode = getPlot().getSelectedGameMode(); this.permissions = new HashSet<>(VirtualRealty.getPermissions().getDefaultMemberPerms()); this.managementPermissions = new HashSet<>(); } @@ -40,8 +37,7 @@ public PlotMember(UUID uuid, Plot plot) { @SneakyThrows public PlotMember(ResultSet rs) { this.uuid = UUID.fromString(rs.getString("uuid")); - Plot plot = PlotManager.getInstance().getPlot(rs.getInt("plot")); - this.plot = plot; + this.plotId = rs.getInt("plot"); this.selectedGameMode = GameMode.valueOf(rs.getString("selectedGameMode")); Set plotPermissions = new HashSet<>(); if (!rs.getString("permissions").isEmpty()) { @@ -57,8 +53,12 @@ public PlotMember(ResultSet rs) { } } this.managementPermissions = managementPermissions; - if (plot != null) - plot.members.add(this); + if (getPlot() != null) + getPlot().members.add(this); + } + + public Plot getPlot() { + return PlotManager.getInstance().getPlot(this.plotId); } public void togglePermission(RegionPermission plotPermission) { @@ -120,7 +120,7 @@ public void insert() { "VALUES (?, ?, ?, ?, ?)" )) { ps.setString(1, this.uuid.toString()); - ps.setInt(2, this.plot.getID()); + ps.setInt(2, this.plotId); ps.setString(3, this.getSelectedGameMode().name()); ps.setString(4, permissions.toString()); ps.setString(5, managementPermissions.toString()); @@ -153,7 +153,7 @@ public void update() { ps.setString(2, managementPermissions.toString()); ps.setString(3, selectedGameMode.name()); ps.setString(4, this.uuid.toString()); - ps.setInt(5, this.plot.getID()); + ps.setInt(5, this.plotId); ps.execute(); } catch (Exception e) { e.printStackTrace(); @@ -168,7 +168,7 @@ public void delete() { " WHERE `uuid` = ? AND `plot` = ?" )) { ps.setString(1, this.uuid.toString()); - ps.setInt(2, plot.getID()); + ps.setInt(2, this.plotId); ps.execute(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotSize.java similarity index 98% rename from src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java rename to src/main/java/com/modnmetl/virtualrealty/model/plot/PlotSize.java index d35eadf..fa9e28e 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotSize.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.enums; +package com.modnmetl.virtualrealty.model.plot; import com.modnmetl.virtualrealty.VirtualRealty; import lombok.Data; diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java b/src/main/java/com/modnmetl/virtualrealty/model/region/Cuboid.java similarity index 96% rename from src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java rename to src/main/java/com/modnmetl/virtualrealty/model/region/Cuboid.java index f5d6b6b..a923e03 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/region/Cuboid.java @@ -1,13 +1,10 @@ -package com.modnmetl.virtualrealty.objects.region; +package com.modnmetl.virtualrealty.model.region; -import com.modnmetl.virtualrealty.objects.math.BlockVector2; -import com.modnmetl.virtualrealty.objects.math.BlockVector3; -import org.bukkit.Bukkit; +import com.modnmetl.virtualrealty.model.math.BlockVector2; +import com.modnmetl.virtualrealty.model.math.BlockVector3; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.Player; import java.util.*; diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java b/src/main/java/com/modnmetl/virtualrealty/model/region/GridStructure.java similarity index 79% rename from src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java rename to src/main/java/com/modnmetl/virtualrealty/model/region/GridStructure.java index f02d0d9..58e6e9a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/region/GridStructure.java @@ -1,12 +1,11 @@ -package com.modnmetl.virtualrealty.objects.region; +package com.modnmetl.virtualrealty.model.region; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.Direction; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.math.BlockVector2; -import com.modnmetl.virtualrealty.utils.VectorUtils; -import com.modnmetl.virtualrealty.utils.data.VirtualBlock; +import com.modnmetl.virtualrealty.model.math.Direction; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.math.BlockVector2; +import com.modnmetl.virtualrealty.util.VectorUtils; import lombok.Data; import lombok.SneakyThrows; import org.bukkit.Bukkit; @@ -33,7 +32,7 @@ public class GridStructure { private int height; private int width; private int cuboidId; - private final Set changedBlocks; + private final List changedBlocks; private final String world; private boolean displayingBlocks; private long displayTicks; @@ -48,7 +47,7 @@ public GridStructure(Player viewer, int length, int height, int width, int cuboi this.height = height; this.width = width; this.cuboidId = cuboidId; - this.changedBlocks = new HashSet<>(); + this.changedBlocks = new ArrayList<>(); this.world = world.getName(); this.displayTicks = displayTicks; this.previewLocation = previewLocation; @@ -209,41 +208,47 @@ public void run() { @SneakyThrows public void removeGrid() { + List newBlocks = new ArrayList<>(); for (VirtualBlock changedBlock : changedBlocks) { - Block changedBukkitBlock = changedBlock.getBlock(getCreatedWorld()); - if (VirtualRealty.legacyVersion) { - Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { - viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getType(), changedBukkitBlock.getData()); - }); - } else { - Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { - viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getBlockData()); - }); - } + newBlocks.add(changedBlock.getBlock(getCreatedWorld())); } + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + for (Block block : newBlocks) { + if (VirtualRealty.legacyVersion) { + viewer.sendBlockChange(block.getLocation(), block.getType(), block.getData()); + } else { + viewer.sendBlockChange(block.getLocation(), block.getBlockData()); + } + } + }); } private void swapBlocks(LinkedList blocks, boolean collidingArea) { Plot plot = PlotManager.getInstance().getPlot(previewLocation); - for (Block block : blocks) { - Location blockLocation = block.getLocation(); - VirtualBlock convertedBlock; - if (VirtualRealty.legacyVersion) { - convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getType().getId(), block.getData()); - Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { - viewer.sendBlockChange(blockLocation, Objects.requireNonNull(Material.matchMaterial("STAINED_GLASS")), ((plot != null && plot.getID() == cuboidId) ? (byte) 1 : collidingArea ? (byte) 14 : (byte) 5)); - }); - } else { - convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getBlockData().getAsString()); - BlockData greenBlockData = Material.LIME_STAINED_GLASS.createBlockData(); - BlockData redBlockData = Material.RED_STAINED_GLASS.createBlockData(); - BlockData orangeBlockData = Material.ORANGE_STAINED_GLASS.createBlockData(); - Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { - viewer.sendBlockChange(blockLocation, ((plot != null && plot.getID() == cuboidId) ? orangeBlockData : collidingArea ? redBlockData : greenBlockData)); - }); + Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> { + for (Block block : blocks) { + Location blockLocation = block.getLocation(); + VirtualBlock convertedBlock; + if (VirtualRealty.legacyVersion) { + convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getType().getId(), block.getData()); + viewer.sendBlockChange( + blockLocation, + Objects.requireNonNull(Material.matchMaterial("STAINED_GLASS")), + ((plot != null && plot.getID() == cuboidId) ? (byte) 1 : collidingArea ? (byte) 14 : (byte) 5) + ); + } else { + convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getBlockData().getAsString()); + BlockData greenBlockData = Material.LIME_STAINED_GLASS.createBlockData(); + BlockData redBlockData = Material.RED_STAINED_GLASS.createBlockData(); + BlockData orangeBlockData = Material.ORANGE_STAINED_GLASS.createBlockData(); + viewer.sendBlockChange( + blockLocation, + ((plot != null && plot.getID() == cuboidId) ? orangeBlockData : collidingArea ? redBlockData : greenBlockData) + ); + } + changedBlocks.add(convertedBlock); } - changedBlocks.add(convertedBlock); - } + }); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualBlock.java similarity index 75% rename from src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java rename to src/main/java/com/modnmetl/virtualrealty/model/region/VirtualBlock.java index 782f893..e976a3a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualBlock.java @@ -1,16 +1,10 @@ -package com.modnmetl.virtualrealty.utils.data; +package com.modnmetl.virtualrealty.model.region; import lombok.Data; -import lombok.Getter; -import lombok.Setter; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.zip.DeflaterOutputStream; -import java.util.zip.InflaterInputStream; @Data public class VirtualBlock implements Serializable { diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualLocation.java b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualLocation.java similarity index 89% rename from src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualLocation.java rename to src/main/java/com/modnmetl/virtualrealty/model/region/VirtualLocation.java index be66d50..ba41fbd 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualLocation.java +++ b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualLocation.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.utils.data; +package com.modnmetl.virtualrealty.model.region; import lombok.Data; import org.bukkit.World; diff --git a/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java index 1073fb5..86f5246 100644 --- a/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java +++ b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java @@ -1,9 +1,9 @@ package com.modnmetl.virtualrealty.registry; -import com.modnmetl.virtualrealty.managers.PlotManager; +import com.modnmetl.virtualrealty.manager.PlotManager; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.objects.Plot; +import com.modnmetl.virtualrealty.model.plot.Plot; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -101,7 +101,7 @@ public boolean canRegister(){ public String onPlaceholderRequest(Player player, @NotNull String identifier){ if(player == null) return ""; - Plot plot = PlotManager.getInstance().getBorderedPlot(player.getLocation()); + Plot plot = PlotManager.getInstance().getPlot(player.getLocation()); if (identifier.equals("plot_id")) { if (plot == null) return ""; return String.valueOf(plot.getID()); diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java b/src/main/java/com/modnmetl/virtualrealty/util/EnumUtils.java similarity index 84% rename from src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java rename to src/main/java/com/modnmetl/virtualrealty/util/EnumUtils.java index 03f2181..e244f66 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/EnumUtils.java @@ -1,6 +1,6 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.util; -public class EnumUtils { +public final class EnumUtils { public static > boolean isValidEnum(Class enumClass, String enumName) { if (enumName == null) { diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java b/src/main/java/com/modnmetl/virtualrealty/util/PermissionsUtil.java similarity index 83% rename from src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java rename to src/main/java/com/modnmetl/virtualrealty/util/PermissionsUtil.java index 4a93357..c33633c 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/PermissionsUtil.java @@ -1,11 +1,10 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.util; -import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.utils.multiversion.ChatMessage; +import com.modnmetl.virtualrealty.model.other.ChatMessage; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; -public class Permissions { +public final class PermissionsUtil { public static boolean hasPermission(CommandSender sender, Permission basePermission, String permission) { Permission finalPermission = new Permission(basePermission.getName() + "." + permission); diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/RegionUtil.java similarity index 88% rename from src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java rename to src/main/java/com/modnmetl/virtualrealty/util/RegionUtil.java index 8fa21c7..696a2e4 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/RegionUtil.java @@ -1,17 +1,17 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.util; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.Direction; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.objects.math.BlockVector2; -import com.modnmetl.virtualrealty.objects.region.Cuboid; -import com.modnmetl.virtualrealty.objects.math.BlockVector3; +import com.modnmetl.virtualrealty.model.math.Direction; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.math.BlockVector2; +import com.modnmetl.virtualrealty.model.region.Cuboid; +import com.modnmetl.virtualrealty.model.math.BlockVector3; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -public class RegionUtil { +public final class RegionUtil { public static Cuboid getRegion(Location location, Direction direction, int length, int height, int width) { Location location1; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java b/src/main/java/com/modnmetl/virtualrealty/util/UUIDUtils.java similarity index 77% rename from src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java rename to src/main/java/com/modnmetl/virtualrealty/util/UUIDUtils.java index f39d2a8..410afee 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/UUIDUtils.java @@ -1,8 +1,8 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.util; import java.util.UUID; -public class UUIDUtils { +public final class UUIDUtils { public static boolean isValidUUID(String uuidString) { try { diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java b/src/main/java/com/modnmetl/virtualrealty/util/UpdateChecker.java similarity index 95% rename from src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java rename to src/main/java/com/modnmetl/virtualrealty/util/UpdateChecker.java index 052b0f4..5895ce0 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/UpdateChecker.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.util; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -9,7 +9,7 @@ import java.net.HttpURLConnection; import java.net.URL; -public class UpdateChecker { +public final class UpdateChecker { private static final String VERSION_URL = "https://api.spiget.org/v2/resources/95599/versions/latest"; private static final String DESCRIPTION_URL = "https://api.spiget.org/v2/resources/95599/updates/latest"; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java b/src/main/java/com/modnmetl/virtualrealty/util/VectorUtils.java similarity index 77% rename from src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java rename to src/main/java/com/modnmetl/virtualrealty/util/VectorUtils.java index bf5643a..71d1f4d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/VectorUtils.java @@ -1,9 +1,9 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.util; -import com.modnmetl.virtualrealty.objects.math.BlockVector2; +import com.modnmetl.virtualrealty.model.math.BlockVector2; import org.bukkit.util.NumberConversions; -public class VectorUtils { +public final class VectorUtils { public static double distance(BlockVector2 vector, BlockVector2 vector2) { return Math.sqrt(distanceSquared(vector, vector2)); diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/WorldUtil.java similarity index 87% rename from src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java rename to src/main/java/com/modnmetl/virtualrealty/util/WorldUtil.java index 98a6ca8..bdc51a5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/WorldUtil.java @@ -1,11 +1,11 @@ -package com.modnmetl.virtualrealty.utils; +package com.modnmetl.virtualrealty.util; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.enums.permissions.RegionPermission; +import com.modnmetl.virtualrealty.model.permission.RegionPermission; import java.util.List; -public class WorldUtil { +public final class WorldUtil { public static List getWorldPermissions() { return VirtualRealty.getPermissions().getWorldProtection(); diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java b/src/main/java/com/modnmetl/virtualrealty/util/configuration/ConfigurationFactory.java similarity index 96% rename from src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java rename to src/main/java/com/modnmetl/virtualrealty/util/configuration/ConfigurationFactory.java index 0a3cadd..976f9c7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/configuration/ConfigurationFactory.java @@ -1,10 +1,9 @@ -package com.modnmetl.virtualrealty.utils.configuration; +package com.modnmetl.virtualrealty.util.configuration; import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.configs.*; -import com.modnmetl.virtualrealty.configs.migrations.C0001_Remove_Old_Plot_Sub_Commands; +import com.modnmetl.virtualrealty.configs.migration.C0001_Remove_Old_Plot_Sub_Commands; import eu.okaeri.configs.ConfigManager; -import eu.okaeri.configs.postprocessor.SectionSeparator; import eu.okaeri.configs.validator.okaeri.OkaeriValidator; import eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer; import eu.okaeri.configs.yaml.bukkit.serdes.SerdesBukkit; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java b/src/main/java/com/modnmetl/virtualrealty/util/data/DataCompressor.java similarity index 95% rename from src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java rename to src/main/java/com/modnmetl/virtualrealty/util/data/DataCompressor.java index 4f4ed5e..62d4fe1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/data/DataCompressor.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.utils.data; +package com.modnmetl.virtualrealty.util.data; import java.io.*; import java.util.zip.*; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java b/src/main/java/com/modnmetl/virtualrealty/util/data/ItemBuilder.java similarity index 99% rename from src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java rename to src/main/java/com/modnmetl/virtualrealty/util/data/ItemBuilder.java index 3c28086..dc7b4b7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/data/ItemBuilder.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.utils.data; +package com.modnmetl.virtualrealty.util.data; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/data/OldSchematicUtil.java similarity index 92% rename from src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java rename to src/main/java/com/modnmetl/virtualrealty/util/data/OldSchematicUtil.java index f349c82..27db04a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/data/OldSchematicUtil.java @@ -1,12 +1,10 @@ -package com.modnmetl.virtualrealty.utils.data; +package com.modnmetl.virtualrealty.util.data; -import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; +import com.modnmetl.virtualrealty.util.multiversion.VMaterial; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.data.DataCompressor; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; import lombok.SneakyThrows; -import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/data/SchematicUtil.java similarity index 96% rename from src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java rename to src/main/java/com/modnmetl/virtualrealty/util/data/SchematicUtil.java index 590398a..8c92cf0 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/data/SchematicUtil.java @@ -1,10 +1,11 @@ -package com.modnmetl.virtualrealty.utils.data; +package com.modnmetl.virtualrealty.util.data; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.managers.PlotManager; -import com.modnmetl.virtualrealty.objects.Plot; -import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; -import lombok.Getter; +import com.modnmetl.virtualrealty.manager.PlotManager; +import com.modnmetl.virtualrealty.model.plot.Plot; +import com.modnmetl.virtualrealty.model.region.VirtualBlock; +import com.modnmetl.virtualrealty.model.region.VirtualLocation; +import com.modnmetl.virtualrealty.util.multiversion.VMaterial; import lombok.SneakyThrows; import org.apache.commons.lang.SerializationUtils; import org.bukkit.Bukkit; @@ -12,15 +13,11 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; import org.bukkit.scheduler.BukkitRunnable; -import javax.swing.*; import java.io.*; import java.lang.reflect.Method; import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.IntStream; public class SchematicUtil { diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/data/SkullUtil.java similarity index 96% rename from src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java rename to src/main/java/com/modnmetl/virtualrealty/util/data/SkullUtil.java index c342d33..d8daf09 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/data/SkullUtil.java @@ -1,7 +1,6 @@ -package com.modnmetl.virtualrealty.utils.data; +package com.modnmetl.virtualrealty.util.data; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import org.bukkit.Material; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java b/src/main/java/com/modnmetl/virtualrealty/util/loader/CustomClassLoader.java similarity index 81% rename from src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java rename to src/main/java/com/modnmetl/virtualrealty/util/loader/CustomClassLoader.java index 98f6e71..a19807b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/loader/CustomClassLoader.java @@ -1,4 +1,4 @@ -package com.modnmetl.virtualrealty.utils.loader; +package com.modnmetl.virtualrealty.util.loader; import java.net.URL; import java.net.URLClassLoader; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/loader/Loader.java b/src/main/java/com/modnmetl/virtualrealty/util/loader/Loader.java similarity index 95% rename from src/main/java/com/modnmetl/virtualrealty/utils/loader/Loader.java rename to src/main/java/com/modnmetl/virtualrealty/util/loader/Loader.java index 0af54d7..b7801c6 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/loader/Loader.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/loader/Loader.java @@ -1,12 +1,9 @@ -package com.modnmetl.virtualrealty.utils.loader; +package com.modnmetl.virtualrealty.util.loader; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.modnmetl.virtualrealty.VirtualRealty; -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.*; import java.net.*; diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java b/src/main/java/com/modnmetl/virtualrealty/util/multiversion/VMaterial.java similarity index 93% rename from src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java rename to src/main/java/com/modnmetl/virtualrealty/util/multiversion/VMaterial.java index d39b011..c9d48c9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java +++ b/src/main/java/com/modnmetl/virtualrealty/util/multiversion/VMaterial.java @@ -1,13 +1,13 @@ -package com.modnmetl.virtualrealty.utils.multiversion; +package com.modnmetl.virtualrealty.util.multiversion; import com.modnmetl.virtualrealty.VirtualRealty; -import com.modnmetl.virtualrealty.exceptions.MaterialMatchException; +import com.modnmetl.virtualrealty.exception.MaterialMatchException; import org.bukkit.Material; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -public class VMaterial { +public final class VMaterial { public static Material getMaterial(int materialID) throws MaterialMatchException { if (VirtualRealty.legacyVersion) { From e58c2324d01ea78b495b64b7decd8004a5cd60a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cichocki?= Date: Sun, 4 Dec 2022 23:21:27 +0100 Subject: [PATCH 10/10] listener init adjustment --- src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index ccb05b3..8b58d2b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -340,7 +340,7 @@ private void registerListeners() { new ConfirmationListener(this); try { List> classes = new ArrayList<>(); - classes.add(Class.forName("com.modnmetl.virtualrealty.listeners.premium.PanelListener", true, getLoader())); + classes.add(Class.forName("com.modnmetl.virtualrealty.listener.premium.PanelListener", true, getLoader())); for (Class aClass : classes) { aClass.getConstructors()[0].newInstance(this); }