diff --git a/pom.xml b/pom.xml index 47e602e..ce7bb77 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.plytki VirtualRealty - 1.5.0 + 1.6.0 jar VirtualRealty diff --git a/src/main/java/me/plytki/virtualrealty/VirtualRealty.java b/src/main/java/me/plytki/virtualrealty/VirtualRealty.java index c61925e..86fcbd9 100644 --- a/src/main/java/me/plytki/virtualrealty/VirtualRealty.java +++ b/src/main/java/me/plytki/virtualrealty/VirtualRealty.java @@ -2,13 +2,15 @@ import me.plytki.virtualrealty.commands.PlotCommand; import me.plytki.virtualrealty.commands.VirtualRealtyCommand; +import me.plytki.virtualrealty.configs.MessagesConfiguration; import me.plytki.virtualrealty.configs.PluginConfiguration; import me.plytki.virtualrealty.configs.SizesConfiguration; import me.plytki.virtualrealty.enums.PlotSize; import me.plytki.virtualrealty.exceptions.MaterialMatchException; -import me.plytki.virtualrealty.listeners.PlotListener; -import me.plytki.virtualrealty.listeners.PlotProtectionListener; -import me.plytki.virtualrealty.listeners.WorldListener; +import me.plytki.virtualrealty.listeners.plot.BorderListener; +import me.plytki.virtualrealty.listeners.plot.PlotListener; +import me.plytki.virtualrealty.listeners.plot.ProtectionListener; +import me.plytki.virtualrealty.listeners.world.WorldListener; import me.plytki.virtualrealty.managers.PlotManager; import me.plytki.virtualrealty.objects.Plot; import me.plytki.virtualrealty.sql.SQL; @@ -38,6 +40,9 @@ public final class VirtualRealty extends JavaPlugin { + public final Locale locale = Locale.getDefault(); + public final List availableLocales = new ArrayList<>(Arrays.asList(new Locale("en", "GB"), new Locale("es", "ES"), new Locale("pl", "PL"))); + //CORE private static VirtualRealty instance; public static final String PREFIX = "§a§lVR §8§l» §7"; @@ -50,10 +55,13 @@ public final class VirtualRealty extends JavaPlugin { public static File plotsSchemaFolder; public PluginConfiguration pluginConfiguration; public SizesConfiguration sizesConfiguration; + public MessagesConfiguration messagesConfiguration; private final File pluginConfigurationFile = new File(this.getDataFolder(), "config.yml"); private final File sizesConfigurationFile = new File(this.getDataFolder(), "sizes.yml"); + private final File languagesDirectory = new File(this.getDataFolder(), "messages"); //DYNMAP API + public static boolean isDynmapPresent = false; public static DynmapAPI dapi = null; public static MarkerSet markerset = null; public static MarkerIcon markerIcon = null; @@ -85,14 +93,8 @@ public void onEnable() { plotsFolder.mkdirs(); plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain"); plotsSchemaFolder.mkdirs(); - try { - ConfigurationFactory configFactory = new ConfigurationFactory(); - pluginConfiguration = configFactory.createPluginConfiguration(pluginConfigurationFile); - sizesConfiguration = configFactory.createSizesConfiguration(sizesConfigurationFile); - } catch (Exception exception) { - exception.printStackTrace(); - return; - } + spawnLocales(); + reloadConfigs(); registerMetrics(); loadSizesConfiguration(); connectToDatabase(); @@ -104,7 +106,7 @@ public void onEnable() { registerListeners(); registerTasks(); checkForOldSchemas(); - debug("Server Version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion()); + debug("Server version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion()); } @Override @@ -119,6 +121,39 @@ public static void debug(String debugMessage) { VirtualRealty.getInstance().getLogger().warning("DEBUG-MODE > " + debugMessage); } + public void spawnLocales() { + for (Locale availableLocale : availableLocales) { + if (availableLocale.toString().equalsIgnoreCase("en_GB")) { + File messagesConfigurationFile = new File(languagesDirectory, "messages_en_GB.yml"); + ConfigurationFactory configFactory = new ConfigurationFactory(); + configFactory.createMessagesConfiguration(messagesConfigurationFile); + } else { + File languageConfigurationFile = new File(languagesDirectory, "messages_" + availableLocale + ".yml"); + if (!languageConfigurationFile.exists()) { + saveResource("messages_" + availableLocale + ".yml", true); + File file = new File(this.getDataFolder(), "messages_" + availableLocale + ".yml"); + try { + FileUtils.moveFile(file, languageConfigurationFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + } + + public void reloadConfigs() { + try { + ConfigurationFactory configFactory = new ConfigurationFactory(); + pluginConfiguration = configFactory.createPluginConfiguration(pluginConfigurationFile); + File messagesConfigurationFile = new File(languagesDirectory, "messages_" + pluginConfiguration.locale + ".yml"); + sizesConfiguration = configFactory.createSizesConfiguration(sizesConfigurationFile); + messagesConfiguration = configFactory.createMessagesConfiguration(messagesConfigurationFile); + } catch (Exception exception) { + exception.printStackTrace(); + } + } + public static void checkForOldSchemas() { for (Plot plot : PlotManager.plots) { File f = new File(VirtualRealty.plotsSchemaFolder, "plot" + plot.getID() + ".schem"); @@ -136,6 +171,9 @@ public void registerDynmap() { @Override public void run() { Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("dynmap"); + if (plugin != null) { + isDynmapPresent = true; + } if (plugin != null && plugin.isEnabled()) { dapi = (DynmapAPI) plugin; if (dapi.markerAPIInitialized()) { @@ -178,9 +216,10 @@ private void registerCommands() { } private void registerListeners() { - getServer().getPluginManager().registerEvents(new PlotListener(), this); - getServer().getPluginManager().registerEvents(new PlotProtectionListener(), this); - getServer().getPluginManager().registerEvents(new WorldListener(), this); + new BorderListener(this).registerEvents(); + new PlotListener(this).registerEvents(); + new ProtectionListener(this).registerEvents(); + new WorldListener(this).registerEvents(); debug("Registered listeners"); } @@ -191,7 +230,7 @@ private void registerTasks() { private void registerMetrics() { Metrics metrics = new Metrics(this, 12578); - metrics.addCustomChart(new SimplePie("used_database", () -> this.getConfig().getString("data-storage"))); + metrics.addCustomChart(new SimplePie("used_database", () -> pluginConfiguration.dataModel.name())); metrics.addCustomChart(new AdvancedPie("created_plots", new Callable>() { @Override public Map call() throws Exception { @@ -303,6 +342,10 @@ public static File getSizesConfigurationFile() { return VirtualRealty.getInstance().sizesConfigurationFile; } + public static MessagesConfiguration getMessages() { + return getInstance().messagesConfiguration; + } + public boolean checkLegacyVersions() { setPostVersions(); for (String postVersion : postVersions) { @@ -313,6 +356,10 @@ public boolean checkLegacyVersions() { return false; } + public static Locale getLocale() { + return getInstance().locale; + } + public void setPostVersions() { postVersions.add("1.17"); postVersions.add("1.16"); diff --git a/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java b/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java index b6c724f..f6a15e6 100644 --- a/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java +++ b/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java @@ -8,6 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -16,6 +17,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.UUID; public class PlotCommand implements CommandExecutor { @@ -31,6 +33,18 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } if (args.length == 1) { switch (args[0].toUpperCase()) { + case "ADD": { + sender.sendMessage(" "); + sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); + sender.sendMessage(" §a/plot add §8<§7player§8> §8<§7plot§8>"); + break; + } + case "KICK": { + sender.sendMessage(" "); + sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); + sender.sendMessage(" §a/plot kick §8<§7player§8> §8<§7plot§8>"); + break; + } case "TP": { sender.sendMessage(" "); sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); @@ -43,6 +57,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command sender.sendMessage(" §a/plot gm §8<§7gamemode§8>"); break; } + case "INFO": { + Plot plot = PlotManager.getPlot(p.getLocation()); + if (plot == null) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot); + return false; + } + printInfo(sender, plot); + break; + } case "LIST": { boolean hasPlot = false; for (Plot plot : PlotManager.plots) { @@ -51,34 +74,67 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command break; } } - if (!hasPlot) { + boolean isMember = false; + for (Plot plot : PlotManager.plots) { + if (plot.getMembers().contains(p.getUniqueId())) { + isMember = true; + break; + } + } + if (!hasPlot && !isMember) { sender.sendMessage(VirtualRealty.PREFIX + "§cYou don't have any plots!"); return false; } 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 Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |"); - for (Plot plot : PlotManager.plots) { - if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(p.getUniqueId()) && plot.getOwnedUntilDate().isAfter(LocalDateTime.now())) { - 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() : "§cAvailable")); - boolean isOwned = !ownedBy.toString().equals("§cAvailable"); - for (int i = ownedBy.length(); i < 16; i++) { - ownedBy.append(" "); + 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.plots) { + if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(p.getUniqueId())) { + 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)); + boolean isOwned = !ownedBy.toString().equals(VirtualRealty.getMessages().available); + for (int i = ownedBy.length(); i < 16; i++) { + ownedBy.append(" "); + } + StringBuilder size = new StringBuilder(plot.getPlotSize().name()); + for (int i = size.length(); i < 6; i++) { + 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()); } - StringBuilder size = new StringBuilder(plot.getPlotSize().name()); - for (int i = size.length(); i < 6; i++) { - size.append(" "); + } + sender.sendMessage("§7§m "); + } + 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 |"); + for (Plot plot : PlotManager.plots) { + if (plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(p.getUniqueId()) && plot.getMembers().contains(p.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)); + boolean isOwned = !ownedBy.toString().equals(VirtualRealty.getMessages().available); + for (int i = ownedBy.length(); i < 16; i++) { + ownedBy.append(" "); + } + StringBuilder size = new StringBuilder(plot.getPlotSize().name()); + for (int i = size.length(); i < 6; i++) { + 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()); } - 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()); } + sender.sendMessage("§7§m "); } - sender.sendMessage("§7§m "); break; } default: { @@ -88,38 +144,120 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } if (args.length >= 2) { switch (args[0].toUpperCase()) { + case "ADD": { + if (args.length == 3) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[1]); + if (offlinePlayer.getName() == null) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + return false; + } + int plotID; + try { + plotID = Integer.parseInt(args[2]); + } catch (IllegalArgumentException e) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + return false; + } + Plot plot = PlotManager.getPlot(plotID); + if (plot == null) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + return false; + } + if (!(plot.getOwnedBy() != null && plot.getOwnedBy().equals(p.getUniqueId()))) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot); + return false; + } + if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + return false; + } + if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantAddYourself); + return false; + } + if (plot.getMembers().contains(offlinePlayer.getUniqueId())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().alreadyInMembers); + return false; + } + plot.addMember(offlinePlayer.getUniqueId()); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerAdd.replaceAll("%player%", offlinePlayer.getName())); + return false; + } + break; + } + case "KICK": { + if (args.length == 3) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[1]); + if (offlinePlayer.getName() == null) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + return false; + } + int plotID; + try { + plotID = Integer.parseInt(args[2]); + } catch (IllegalArgumentException e) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); + return false; + } + Plot plot = PlotManager.getPlot(plotID); + if (plot == null) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); + return false; + } + if (!(plot.getOwnedBy() != null && plot.getOwnedBy().equals(p.getUniqueId()))) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot); + return false; + } + if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + return false; + } + if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickYourself); + return false; + } + if (!plot.getMembers().contains(offlinePlayer.getUniqueId())) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notInMembers); + return false; + } + plot.removeMember(offlinePlayer.getUniqueId()); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerKick.replaceAll("%player%", offlinePlayer.getName())); + return false; + } + break; + } case "TP": { if (args.length == 2) { int plotID; try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } if (!(plot.getOwnedBy() != null && plot.getOwnedBy().equals(p.getUniqueId()))) { - sender.sendMessage(VirtualRealty.PREFIX + "§cIt's not your plot!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot); return false; } if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - sender.sendMessage(VirtualRealty.PREFIX + "§cYour ownership has expired!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); return false; } Location loc = new Location(plot.getCreatedLocation().getWorld(), plot.getCenter().getBlockX(), plot.getCenter().getBlockY() + 1, plot.getCenter().getBlockZ()); loc.setY(loc.getWorld().getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY() + 1); p.teleport(loc); - sender.sendMessage(VirtualRealty.PREFIX + "§aYou have been teleported to the plot!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot); } break; } case "GM": { if (!VirtualRealty.getPluginConfiguration().enablePlotGameMode || VirtualRealty.getPluginConfiguration().forcePlotGameMode) { - sender.sendMessage(VirtualRealty.PREFIX + "§cGamemode feature is disabled!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeFeatureDisabled); return false; } GameMode gameMode; @@ -131,14 +269,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { gameModeID = Integer.parseInt(args[1]); } catch (IllegalArgumentException ex) { - sender.sendMessage(VirtualRealty.PREFIX + "§cIncorrect gamemode vaule!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectGamemode); return false; } } if (!(gameModeID != 1 && gameModeID != 2)) { gameMode = GameMode.getByValue(Integer.parseInt(args[1])); } else { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only numbers from 1 to 2!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeDisabled); return false; } @@ -146,34 +284,34 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command if (plot != null) { if (plot.getOwnedBy() == null || (plot.getOwnedBy() != null && !plot.getOwnedBy().equals(p.getUniqueId()))) { if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - sender.sendMessage(VirtualRealty.PREFIX + "§cYour ownership has expired!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); return false; } - sender.sendMessage(VirtualRealty.PREFIX + "§cYou can't switch gamemode here!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode); } else { if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - sender.sendMessage(VirtualRealty.PREFIX + "§cYour ownership has expired!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); } else { if (plot.getSelectedGameMode().equals(gameMode)) { if (plot.getSelectedGameMode().equals(GameMode.CREATIVE)) { - sender.sendMessage(VirtualRealty.PREFIX + "§cPlot Creative-Mode is already enabled!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeIsEnabled); } else { - sender.sendMessage(VirtualRealty.PREFIX + "§cPlot Creative-Mode is already disabled!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeIsDisabled); } return false; } plot.setSelectedGameMode(gameMode); p.setGameMode(plot.getSelectedGameMode()); if (plot.getSelectedGameMode().equals(GameMode.CREATIVE)) { - sender.sendMessage(VirtualRealty.PREFIX + "§aPlot Creative-Mode has been enabled!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeEnabled); } else { - sender.sendMessage(VirtualRealty.PREFIX + "§ePlot Creative-Mode has been disabled!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeDisabled); } } } } else { - sender.sendMessage(VirtualRealty.PREFIX + "§cYou can't switch gamemode here!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode); } break; } @@ -188,8 +326,54 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command private static void printHelp(CommandSender sender) { sender.sendMessage(" "); sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); + sender.sendMessage(" §a/plot add §8- §7Adds a member"); + sender.sendMessage(" §a/plot kick §8- §7Kicks a member"); sender.sendMessage(" §a/plot list §8- §7Shows your plots"); + sender.sendMessage(" §a/plot info §8- §7Shows plot info"); sender.sendMessage(" §a/plot gm §8- §7Changes gamemode"); } + private static void printInfo(CommandSender sender, Plot plot) { + LocalDateTime localDateTime = plot.getOwnedUntilDate(); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); +// String assignedBy = VirtualRealty.getMessages().notAssigned; +// if (plot.getAssignedBy() != null) { +// switch (plot.getAssignedBy().toUpperCase()) { +// case "CONSOLE": { +// assignedBy = VirtualRealty.getMessages().assignedByConsole; +// break; +// } +// case "SHOP_PURCHASE": { +// assignedBy = VirtualRealty.getMessages().assignedByShopPurchase; +// break; +// } +// default: { +// OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(plot.getAssignedBy())); +// assignedBy = (offlinePlayer.isOnline() ? "§a" : "§c") + offlinePlayer.getName(); +// } +// } +// } + 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")); + if (plot.getMembers().size() != 0) { + sender.sendMessage(" §7Members §8§l↴"); + for (OfflinePlayer offlinePlayer : plot.getMembersPlayer()) { + sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()); + } + } + //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(" §7Width §8§l‣ §f" + plot.getWidth()); + sender.sendMessage(" §7Height §8§l‣ §f" + plot.getHeight()); + //sender.sendMessage(" §7Floor Material §8§l‣ §f" + plot.getFloorMaterial().name()); + //sender.sendMessage(" §7Border Material §8§l‣ §f" + plot.getBorderMaterial().name()); + //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()); + } + } \ No newline at end of file diff --git a/src/main/java/me/plytki/virtualrealty/commands/VirtualRealtyCommand.java b/src/main/java/me/plytki/virtualrealty/commands/VirtualRealtyCommand.java index ffb175b..573db07 100644 --- a/src/main/java/me/plytki/virtualrealty/commands/VirtualRealtyCommand.java +++ b/src/main/java/me/plytki/virtualrealty/commands/VirtualRealtyCommand.java @@ -8,6 +8,7 @@ import me.plytki.virtualrealty.utils.ConfigurationFactory; import me.plytki.virtualrealty.utils.Permissions; import me.plytki.virtualrealty.utils.PlotUtil; +import me.plytki.virtualrealty.utils.UUIDUtils; import me.plytki.virtualrealty.utils.multiversion.Chat; import me.plytki.virtualrealty.utils.multiversion.VMaterial; import net.md_5.bungee.api.chat.BaseComponent; @@ -18,10 +19,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.jetbrains.annotations.NotNull; @@ -92,39 +90,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command if (!Permissions.hasPermission(sender, tempPermission, "info")) return false; Plot plot = PlotManager.getPlot(p.getLocation()); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cYou aren't standing on any plot!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot); return false; } - LocalDateTime localDateTime = plot.getOwnedUntilDate(); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); - 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")); - String assignedBy = "§cNot assigned"; - if (plot.getAssignedBy() != null) { - switch (plot.getAssignedBy().toUpperCase()) { - case "CONSOLE": { - assignedBy = "§eConsole"; - break; - } - case "SHOP_PURCHASE": { - assignedBy = "§eShop Purchase"; - break; - } - default: { - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(plot.getAssignedBy())); - assignedBy = (offlinePlayer.isOnline() ? "§a" : "§c") + offlinePlayer.getName(); - } - } - } - printInfo(sender, assignedBy, dateTimeFormatter.format(localDateTime), plot); + printInfo(sender, plot); break; } case "LIST": { if (!Permissions.hasPermission(sender, tempPermission, "list")) return false; if (PlotManager.plots.isEmpty()) { - sender.sendMessage(VirtualRealty.PREFIX + "§cThere are no plots!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots); return false; } sender.sendMessage(" "); @@ -136,8 +111,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command 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() : "§cAvailable")); - boolean isOwned = !ownedBy.toString().equals("§cAvailable"); + 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(" "); } @@ -146,7 +121,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command size.append(" "); } 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("§a§oClick to show detailed information about the plot! §8(§7ID: §f" + plot.getID() + "§8)")})); + 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); } @@ -163,9 +138,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command case "RELOAD": { if (!Permissions.hasPermission(sender, tempPermission, "reload")) return false; try { - ConfigurationFactory configFactory = new ConfigurationFactory(); - VirtualRealty.getInstance().pluginConfiguration = configFactory.createPluginConfiguration(VirtualRealty.getPluginConfigurationFile()); - VirtualRealty.getInstance().sizesConfiguration = configFactory.createSizesConfiguration(VirtualRealty.getSizesConfigurationFile()); + VirtualRealty.getInstance().reloadConfigs(); if (VirtualRealty.getPluginConfiguration().dynmapMarkers) { if (VirtualRealty.markerset != null) { VirtualRealty.markerset.deleteMarkerSet(); @@ -184,7 +157,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } catch (Exception exception) { exception.printStackTrace(); } - sender.sendMessage(VirtualRealty.PREFIX + "§aReload completed!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().reloadCompleted); break; } default: { @@ -206,7 +179,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } if (plotSize != null) { if (PlotManager.isColliding(PlotUtil.getPlotRegion(location, Direction.byYaw(location.getYaw()), plotSize.getLength(), plotSize.getWidth(), plotSize.getHeight()))) { - sender.sendMessage(VirtualRealty.PREFIX + "§cYou cant create new plot on the existing plot!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting); return false; } else { Material floorMaterial = null; @@ -215,11 +188,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { floorMaterial = VMaterial.getMaterial(args[2].split(":")[0].toUpperCase()); if (floorMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get floor material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); return false; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get floor material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); return false; } if (args[2].split(":").length == 2) { @@ -232,38 +205,38 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { borderMaterial = VMaterial.getMaterial(args[3].split(":")[0].toUpperCase()); if (borderMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get border material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); return false; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get border material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); return false; } if (args[3].split(":").length == 2) { borderData = Byte.parseByte(args[3].split(":")[1]); } } - sender.sendMessage(VirtualRealty.PREFIX + "§aNot colliding. Creating plot.."); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); long timeStart = System.currentTimeMillis(); Plot plot = PlotManager.createPlot(location, plotSize); if (floorMaterial != null) { - plot.setFloor(floorMaterial, floorData); + plot.setFloorMaterial(floorMaterial, floorData); } if (borderMaterial != null) { plot.setBorder(borderMaterial, borderData); } long timeEnd = System.currentTimeMillis(); - BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aPlot "); - BaseComponent textComponent2 = new TextComponent("§8#§7" + plot.getID()); - BaseComponent textComponent3 = new TextComponent(" §acreated! §8(§7" + (timeEnd - timeStart) + " ms§8)"); - textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick to show detailed information about the plot! §8(§7ID: §f" + plot.getID() + "§8)")})); + 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(p); } } else { - sender.sendMessage(VirtualRealty.PREFIX + "§cSize not recognized!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().sizeNotRecognised); return false; } } else { @@ -275,15 +248,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command width = Integer.parseInt(args[2]); height = Integer.parseInt(args[3]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } if (length > 500 || width > 500 || height > 500) { - sender.sendMessage(VirtualRealty.PREFIX + "§cL, W and H hard-limit is 500!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().LWHHardLimit); return false; } if (PlotManager.isColliding(PlotUtil.getPlotRegion(location, Direction.byYaw(location.getYaw()), length, width, height))) { - sender.sendMessage(VirtualRealty.PREFIX + "§cYou cant create new plot on the existing plot!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting); return false; } else { Material floorMaterial = null; @@ -292,11 +265,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { floorMaterial = VMaterial.getMaterial(args[4].split(":")[0].toUpperCase()); if (floorMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get floor material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); return false; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get floor material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial); return false; } if (args[4].split(":").length == 2) { @@ -309,31 +282,31 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { borderMaterial = VMaterial.getMaterial(args[5].split(":")[0].toUpperCase()); if (borderMaterial == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get border material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); return false; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get border material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial); return false; } if (args[5].split(":").length == 2) { borderData = Byte.parseByte(args[5].split(":")[1]); } } - sender.sendMessage(VirtualRealty.PREFIX + "§aNot colliding. Creating plot.."); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating); long timeStart = System.currentTimeMillis(); Plot plot = PlotManager.createPlot(location, length, width, height); if (floorMaterial != null) { - plot.setFloor(floorMaterial, floorData); + plot.setFloorMaterial(floorMaterial, floorData); } if (borderMaterial != null) { plot.setBorder(borderMaterial, borderData); } long timeEnd = System.currentTimeMillis(); - BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aPlot "); - BaseComponent textComponent2 = new TextComponent("§8#§7" + plot.getID()); - BaseComponent textComponent3 = new TextComponent(" §acreated! §8(§7" + (timeEnd - timeStart) + " ms§8)"); - textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick to show detailed information about the plot! §8(§7ID: §f" + plot.getID() + "§8)")})); + 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); @@ -349,16 +322,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } plot.remove(); - sender.sendMessage(VirtualRealty.PREFIX + "§aSuccessfully removed plot!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot); break; } case "SET": { @@ -368,7 +341,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command case "OWNEDBY": { if (!Permissions.hasPermission(sender, commandPermission, "set.ownedby")) return false; if (args.length < 4) { - sender.sendMessage(VirtualRealty.PREFIX + "§cSpecify username!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyUsername); return false; } int plotID; @@ -376,66 +349,96 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } try { - offlinePlayer = Bukkit.getOfflinePlayer(args[3]); + if (UUIDUtils.isValidUUID(args[3])) { + offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(args[3])); + } else { + offlinePlayer = Bukkit.getOfflinePlayer(args[3]); + } + if (offlinePlayer.getName() == null) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + return false; + } } catch (NullPointerException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get player with specified username!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } + if (args.length >= 5) { + String dateFormat = args[4]; + String timeFormat; + int year; + int month; + int dayOfMonth; + int hour = 0; + int minute = 0; + LocalDateTime localDateTime; + try { + year = Integer.parseInt(dateFormat.split("/")[2]); + month = Integer.parseInt(dateFormat.split("/")[1]); + dayOfMonth = Integer.parseInt(dateFormat.split("/")[0]); + if (args.length >= 6) { + timeFormat = args[5]; + hour = Integer.parseInt(timeFormat.split(":")[0]); + minute = Integer.parseInt(timeFormat.split(":")[1]); + } + localDateTime = LocalDateTime.of(year, month, dayOfMonth, hour, minute); + } catch (IllegalArgumentException e) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().invalidDateProvided); + return false; + } + plot.setOwnedUntilDate(localDateTime); + } + if (sender instanceof RemoteConsoleCommandSender && args.length >= 7 && args[6].equalsIgnoreCase("assign")) { + plot.setAssignedBy("SHOP_PURCHASE"); + } plot.setOwnedBy(offlinePlayer.getUniqueId()); - sender.sendMessage(VirtualRealty.PREFIX + "§aPlot has been assigned to §f" + offlinePlayer.getName() + "!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().assignedTo.replaceAll("%assigned_to%", offlinePlayer.getName())); plot.update(); break; } case "FLOORMATERIAL": { if (!Permissions.hasPermission(sender, commandPermission, "set.floormaterial")) return false; if (args.length < 4) { - sender.sendMessage(VirtualRealty.PREFIX + "§cSpecify material name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyMaterialName); return false; } int plotID; try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } Material material; try { material = Material.matchMaterial(args[3].split(":")[0].toUpperCase()); if (material == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial); return false; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } byte data = 0; if (args[3].split(":").length == 2) { data = Byte.parseByte(args[3].split(":")[1]); } - plot.setFloor(material, data); -// if (args.length == 5 && (args[4].toLowerCase().startsWith("t"))) { -// plot.initializeFloor(); -// sender.sendMessage(VirtualRealty.PREFIX + "§aNew floor material has been set and initialized!"); -// plot.update(); -// return false; -// } - sender.sendMessage(VirtualRealty.PREFIX + "§aNew floor material has been set!"); + plot.setFloorMaterial(material, data); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().newFloorMaterialSet); plot.update(); break; } @@ -443,30 +446,30 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command if (!Permissions.hasPermission(sender, commandPermission, "set.bordermaterial")) return false; if (args.length < 4) { - sender.sendMessage(VirtualRealty.PREFIX + "§cSpecify material name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyMaterialName); return false; } int plotID; try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } Material material; try { material = VMaterial.getMaterial(args[3].split(":")[0].toUpperCase()); if (material == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial); return false; } } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get material with specified name!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } byte data = 0; @@ -474,21 +477,21 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command data = Byte.parseByte(args[3].split(":")[1]); } plot.setBorder(material, data); - sender.sendMessage(VirtualRealty.PREFIX + "§aNew border material has been set!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().newBorderMaterialSet); plot.update(); return false; } case "OWNERSHIPEXPIRES": { if (!Permissions.hasPermission(sender, commandPermission, "set.ownerexpires")) return false; if (args.length < 4) { - sender.sendMessage(VirtualRealty.PREFIX + "§cSpecify expiry date!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyExpiryDate); return false; } int plotID; try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } String dateFormat = args[3]; @@ -510,16 +513,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } localDateTime = LocalDateTime.of(year, month, dayOfMonth, hour, minute); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cInvalid date format provided!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().invalidDateProvided); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } plot.setOwnedUntilDate(localDateTime); - sender.sendMessage(VirtualRealty.PREFIX + "§aOwned until date has been updated!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownedUntilUpdated); plot.update(); break; } @@ -541,18 +544,26 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } try { - offlinePlayer = Bukkit.getOfflinePlayer(args[2]); + if (UUIDUtils.isValidUUID(args[2])) { + offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(args[2])); + } else { + offlinePlayer = Bukkit.getOfflinePlayer(args[2]); + } + if (offlinePlayer.getName() == null) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); + return false; + } } catch (NullPointerException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get player with specified username!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } if (sender instanceof Player) { @@ -563,7 +574,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command plot.setAssignedBy("SHOP_PURCHASE"); } plot.setOwnedBy(offlinePlayer.getUniqueId()); - sender.sendMessage(VirtualRealty.PREFIX + "§aPlot has been assigned to §f" + offlinePlayer.getName() + " §aby §f" + sender.getName() + "!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().assignedToBy.replaceAll("%assigned_to%", offlinePlayer.getName()).replaceAll("%assigned_by%", sender.getName())); plot.update(); } break; @@ -575,17 +586,17 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } plot.setAssignedBy(null); plot.setOwnedBy(null); - sender.sendMessage(VirtualRealty.PREFIX + "§aPlot has been unassigned!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().unassigned); plot.update(); } break; @@ -596,56 +607,33 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } if (PlotManager.plots.isEmpty()) { - sender.sendMessage(VirtualRealty.PREFIX + "§cThere are no plots!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots); return false; } - if (plotID < PlotManager.plots.get(0).getID()) { - sender.sendMessage(VirtualRealty.PREFIX + "§cMinimum plot ID is " + PlotManager.plots.get(0).getID() + "!"); + if (plotID < PlotManager.getPlotMinID()) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getPlotMinID()))); return false; } - if (plotID > PlotManager.plots.get(PlotManager.plots.size() - 1).getID()) { - sender.sendMessage(VirtualRealty.PREFIX + "§cMaximum plot ID is " + PlotManager.plots.get(PlotManager.plots.size() - 1).getID() + "!"); + if (plotID > PlotManager.getPlotMaxID()) { + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getPlotMaxID()))); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } - LocalDateTime localDateTime = plot.getOwnedUntilDate(); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); - 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")); - String assignedBy = "§cNot assigned"; - if (plot.getAssignedBy() != null) { - switch (plot.getAssignedBy().toUpperCase()) { - case "CONSOLE": { - assignedBy = "§eConsole"; - break; - } - case "SHOP_PURCHASE": { - assignedBy = "§eShop Purchase"; - break; - } - default: { - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(plot.getAssignedBy())); - assignedBy = (offlinePlayer.isOnline() ? "§a" : "§c") + offlinePlayer.getName(); - } - } - } - printInfo(sender, assignedBy, dateTimeFormatter.format(localDateTime), plot); + printInfo(sender, plot); break; } case "TP": { if (!Permissions.hasPermission(sender, commandPermission, "tp")) return false; if (!(sender instanceof Player)) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCommand only for players!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cmdOnlyPlayers); return false; } if (args.length == 2) { @@ -653,18 +641,18 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command try { plotID = Integer.parseInt(args[1]); } catch (IllegalArgumentException e) { - sender.sendMessage(VirtualRealty.PREFIX + "§cUse only natural numbers!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly); return false; } Plot plot = PlotManager.getPlot(plotID); if (plot == null) { - sender.sendMessage(VirtualRealty.PREFIX + "§cCouldn't get plot with specified ID!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound); return false; } Location loc = new Location(plot.getCreatedLocation().getWorld(), plot.getCenter().getBlockX(), plot.getCenter().getBlockY() + 1, plot.getCenter().getBlockZ()); loc.setY(loc.getWorld().getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY() + 1); p.teleport(loc); - sender.sendMessage(VirtualRealty.PREFIX + "§aYou have been teleported to the plot!"); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot); } break; } @@ -677,9 +665,38 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return false; } - private static void printInfo(CommandSender sender, String assignedBy, String dateTime, Plot plot) { + private static void printInfo(CommandSender sender, Plot plot) { + LocalDateTime localDateTime = plot.getOwnedUntilDate(); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); + String assignedBy = VirtualRealty.getMessages().notAssigned; + if (plot.getAssignedBy() != null) { + switch (plot.getAssignedBy().toUpperCase()) { + case "CONSOLE": { + assignedBy = VirtualRealty.getMessages().assignedByConsole; + break; + } + case "SHOP_PURCHASE": { + assignedBy = VirtualRealty.getMessages().assignedByShopPurchase; + break; + } + default: { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(plot.getAssignedBy())); + assignedBy = (offlinePlayer.isOnline() ? "§a" : "§c") + offlinePlayer.getName(); + } + } + } + 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")); + if (plot.getMembers().size() != 0) { + sender.sendMessage(" §7Members §8§l↴"); + for (OfflinePlayer offlinePlayer : plot.getMembersPlayer()) { + sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()); + } + } sender.sendMessage(" §7Assigned By §8§l‣ §a" + assignedBy); - sender.sendMessage(" §7Owned Until §8§l‣ §f" + dateTime); + 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(" §7Width §8§l‣ §f" + plot.getWidth()); diff --git a/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java new file mode 100644 index 0000000..1b1d881 --- /dev/null +++ b/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java @@ -0,0 +1,71 @@ +package me.plytki.virtualrealty.configs; + +import eu.okaeri.configs.OkaeriConfig; + +public class MessagesConfiguration extends OkaeriConfig { + + public String useNaturalNumbersOnly = "§cUse only natural numbers!"; + public String noPlotFound = "§cCouldn't get plot with specified ID!"; + public String notYourPlot = "§cIt's not your plot!"; + public String ownershipExpired = "§cYour ownership has expired!"; + public String teleportedToPlot = "§aYou have been teleported to the plot!"; + public String gamemodeFeatureDisabled = "§cGamemode feature is disabled!"; + public String incorrectGamemode = "§cIncorrect gamemode value!"; + public String gamemodeDisabled = "§cThis gamemode is disabled!"; + public String cantSwitchGamemode = "§cYou can't switch gamemode here!"; + public String creativeIsEnabled = "§cPlot Creative-Mode is already enabled!"; + public String creativeIsDisabled = "§cPlot Creative-Mode is already disabled!"; + public String creativeEnabled = "§aPlot Creative-Mode has been enabled!"; + public String creativeDisabled = "§ePlot Creative-Mode has been disabled!"; + public String notStandingOnPlot = "§cYou aren't standing on any plot!"; + public String assignedByConsole = "§eConsole"; + public String assignedByShopPurchase = "§eShop Purchase"; + public String noPlots = "§cThere are no plots!"; + public String available = "§cAvailable"; + public String reloadCompleted = "§aReload completed!"; + public String cantCreateOnExisting = "§cYou can't create new plot over an existing plot!"; + public String cantGetFloorMaterial = "§cCouldn't get floor material with specified name!"; + public String cantGetBorderMaterial = "§cCouldn't get border material with specified name!"; + public String cantGetMaterial = "§cCouldn't get material with specified name!"; + public String notCollidingCreating = "§aNot colliding. Creating plot.."; + public String clickToShowDetailedInfo = "§a§oClick to show detailed information about the plot! §8(§7ID: §f%plot_id%§8)"; + public String sizeNotRecognised = "§cSize not recognized!"; + public String LWHHardLimit = "§cL, W and H hard-limit is 500!"; + public String removedPlot = "§aSuccessfully removed plot!"; + public String specifyUsername = "§cSpecify username!"; + public String playerNotFoundWithUsername = "§cCouldn't find player with specified username!"; + public String invalidDateProvided = "§cInvalid date format provided!"; + public String assignedTo = "§aPlot has been assigned to §f%assigned_to%!"; + public String specifyMaterialName = "§cSpecify material name!"; + public String specifyExpiryDate = "§cSpecify expiry date!"; + public String newFloorMaterialSet = "§aNew floor material has been set!"; + public String newBorderMaterialSet = "§aNew border material has been set!"; + public String ownedUntilUpdated = "§aOwned until date has been updated!"; + public String assignedToBy = "§aPlot has been assigned to §f%assigned_to% §aby §f%assigned_by%!"; + public String notAssigned = "§cNot assigned"; + public String unassigned = "§aPlot has been unassigned!"; + public String minPlotID = "§cMinimum plot ID is %min_id%!"; + public String maxPlotID = "§cMaximum plot ID is %max_id%!"; + public String cmdOnlyPlayers = "§cCommand only for players!"; + + public String enteredAvailablePlot = "§2You have entered an available plot!"; + public String enteredOwnedPlot = "§7You have entered §2%owner%'s §7plot!"; + public String leftAvailablePlot = "§cYou have left an available plot!"; + public String leftOwnedPlot = "§7You have left §2%owner%'s §7plot!"; + public String cantInteract = "§cYou can't interact here!"; + public String cantBuildHere = "§cYou can't build here!"; + public String cantRideOnPlot = "§cYou can't ride on someones plot!"; + + public String creationPlotComponent1 = "§aPlot "; + public String creationPlotComponent2 = "§8#§7%plot_id%"; + public String creationPlotComponent3 = " §acreated! §8(§7%creation_time% ms§8)"; + + public String cantAddYourself = "§cYou can't add yourself to the plot!"; + public String cantKickYourself = "§cYou can't kick yourself from the plot!"; + public String alreadyInMembers = "§cThis player is already one of the plot members!"; + public String notInMembers = "§cThis player is not one of the plot members!"; + public String cantDoAnyDMG = "§cYou can't do any damage here!"; + public String playerKick = "§aPlayer §7%player% §ahas been kicked out of your plot!"; + public String playerAdd = "§aPlayer §7%player% §ahas been added to your plot!"; + +} diff --git a/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java b/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java index 9de9039..96ca40d 100644 --- a/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java +++ b/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java @@ -6,14 +6,6 @@ import me.plytki.virtualrealty.enums.HighlightType; import org.bukkit.GameMode; -import java.awt.*; -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - - @Header("################################################################") @Header("# #") @Header("# Virtual Realty #") @@ -37,6 +29,9 @@ public class PluginConfiguration extends OkaeriConfig { @CustomKey("enable-plot-gamemode") public boolean enablePlotGameMode = false; + @Comment("Set your wanted language (locale)") + public String locale = VirtualRealty.getInstance().availableLocales.contains(VirtualRealty.getLocale()) ? VirtualRealty.getLocale().toString() : "en_GB"; + @Comment("Set which gamemode players change to when they enter their plot") @CustomKey("default-plot-gamemode") public String plotGameMode = "SURVIVAL"; diff --git a/src/main/java/me/plytki/virtualrealty/enums/Permission.java b/src/main/java/me/plytki/virtualrealty/enums/Permission.java new file mode 100644 index 0000000..3f0c433 --- /dev/null +++ b/src/main/java/me/plytki/virtualrealty/enums/Permission.java @@ -0,0 +1,24 @@ +package me.plytki.virtualrealty.enums; + +public enum Permission { + + WORLD_BUILD("virtualrealty.build.world"), + PLOT_BUILD("virtualrealty.build.plot"), + BORDER_BUILD("virtualrealty.build.border"); + + private final String permission; + + Permission(String permission) { + this.permission = permission; + } + + public String getPermission() { + return permission; + } + + @Override + public String toString() { + return permission; + } + +} diff --git a/src/main/java/me/plytki/virtualrealty/listeners/PlotProtectionListener.java b/src/main/java/me/plytki/virtualrealty/listeners/PlotProtectionListener.java deleted file mode 100644 index ab596d0..0000000 --- a/src/main/java/me/plytki/virtualrealty/listeners/PlotProtectionListener.java +++ /dev/null @@ -1,252 +0,0 @@ -package me.plytki.virtualrealty.listeners; - -import me.plytki.virtualrealty.VirtualRealty; -import me.plytki.virtualrealty.managers.PlotManager; -import me.plytki.virtualrealty.objects.Plot; -import me.plytki.virtualrealty.utils.PlotUtil; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.*; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.ProjectileHitEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.world.StructureGrowEvent; -import org.bukkit.util.Vector; - -import java.time.LocalDateTime; - -public class PlotProtectionListener implements Listener { - - @EventHandler - public void onInteract(PlayerInteractEvent e) { - Player player = e.getPlayer(); - if (e.getClickedBlock() != null && (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.LEFT_CLICK_BLOCK))) { - Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); - if (plot != null) { - if (plot.getOwnedBy() != null) { - boolean hasAccess = player.hasPermission("virtualrealty.plot.build"); - if (!hasAccess) { - hasAccess = plot.getOwnedBy().equals(player.getUniqueId()); - } - if (!hasAccess) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't interact here!"); - } else { - if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYour ownership has expired!"); - } - } - } - } - } - } - - @EventHandler - public void onBlockPlaceOutside(BlockPlaceEvent e) { - if (e.isCancelled()) { - return; - } - Player player = e.getPlayer(); - Plot plot = PlotManager.getBorderedPlot(player.getLocation()); - if (plot != null) { - if (plot.getOwnedBy() != null) { - if (plot.getOwnedBy().equals(player.getUniqueId())) { - Plot locationPlot = PlotManager.getBorderedPlot(player.getLocation()); - if (locationPlot != null && !PlotManager.isLocationInPlot(e.getBlockPlaced().getLocation(), plot)) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build there!"); - } - } - } - } - } - - @EventHandler - public void onBlockBreakOutside(BlockBreakEvent e) { - if (e.isCancelled()) { - return; - } - Player player = e.getPlayer(); - Plot plot = PlotManager.getBorderedPlot(player.getLocation()); - if (plot != null) { - if (plot.getOwnedBy() != null) { - boolean hasAccess = player.hasPermission("virtualrealty.plot.build"); - if (!hasAccess) { - hasAccess = plot.getOwnedBy().equals(player.getUniqueId()); - } - if (!hasAccess) { - Plot locationPlot = PlotManager.getBorderedPlot(player.getLocation()); - if (locationPlot != null && !PlotManager.isLocationInPlot(e.getBlock().getLocation(), plot)) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build there!"); - } - } - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onBlockPlace(BlockPlaceEvent e) { - Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(e.getBlockPlaced().getLocation()); - if (plot != null) { - if (plot.getOwnedBy() != null) { - boolean hasAccess = player.hasPermission("virtualrealty.plot.build"); - if (!hasAccess) { - hasAccess = plot.getOwnedBy().equals(player.getUniqueId()); - } - if (!hasAccess) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } else { - if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYour ownership has expired!"); - } - } - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onBlockBreak(BlockBreakEvent e) { - Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(e.getBlock().getLocation()); - if (plot != null) { - if (plot.getOwnedBy() != null) { - boolean hasAccess = player.hasPermission("virtualrealty.plot.build"); - if (!hasAccess) { - hasAccess = plot.getOwnedBy().equals(player.getUniqueId()); - } - if (!hasAccess) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } else { - if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { - e.setCancelled(true); - player.sendMessage(VirtualRealty.PREFIX + "§cYour ownership has expired!"); - } - } - } - } - } - - @EventHandler - public void onBlockMove(BlockPistonExtendEvent e) { - for (Block block : e.getBlocks()) { - Location fromLocation = block.getLocation(); - Location toLocation = block.getLocation(); - toLocation.add(e.getDirection().getDirection()); - Plot fromPlot = PlotManager.getPlot(fromLocation); - Plot toPlot = PlotManager.getPlot(toLocation); - if (toPlot != null) { - if (fromPlot != null && fromPlot.getID() != toPlot.getID()) { - e.setCancelled(true); - } - if (fromPlot == null) { - e.setCancelled(true); - } - } - } - } - - @EventHandler - public void onEntityExplode(EntityExplodeEvent e) { - if (PlotManager.getPlot(e.getLocation()) != null) { - e.setCancelled(true); - } - } - - @EventHandler - public void onPlotEnter(PlayerMoveEvent e) { - Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(e.getTo()); - if (plot != null && e.getPlayer().isInsideVehicle() && plot.getOwnedBy() != null && !plot.getOwnedBy().equals(e.getPlayer().getUniqueId())) { - e.getPlayer().getVehicle().eject(); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't ride on someones plot!"); - } - } - - @EventHandler - public void onTreeGrow(StructureGrowEvent e) { - for (BlockState block : e.getBlocks()) { - Location fromLocation = e.getLocation(); - Location toLocation = block.getLocation(); - Plot fromPlot = PlotManager.getPlot(fromLocation); - Plot toPlot = PlotManager.getPlot(toLocation); - if (toPlot != null) { - if (fromPlot != null && fromPlot.getID() != toPlot.getID()) { - block.setType(Material.AIR); - } - if (fromPlot == null) { - block.setType(Material.AIR); - } - } - } - } - - @EventHandler - public void onDragonEggMove(BlockFromToEvent e) { - Material block = e.getBlock().getType(); - 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); - if (toPlot != null) { - if (fromPlot != null && fromPlot.getID() != toPlot.getID()) { - e.setCancelled(true); - } - if (fromPlot == null) { - e.setCancelled(true); - } - } - } - } - - @EventHandler - public void onProjectileLaunch(ProjectileLaunchEvent e) { - Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); - if (plot != null) { - if (!(e.getEntity().getShooter() instanceof Player && plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player)e.getEntity().getShooter()).getUniqueId()))) { - e.getEntity().remove(); - } - } - } - - @EventHandler - public void onProjectileHit(ProjectileHitEvent e) { - Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); - if (plot != null) { - if (!(e.getEntity().getShooter() instanceof Player && plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player)e.getEntity().getShooter()).getUniqueId()))) { - e.getEntity().remove(); - } - } - } - - @EventHandler - public void onFireSpread(BlockSpreadEvent e) { - Location fromLocation = e.getSource().getLocation(); - Location toLocation = e.getBlock().getLocation(); - Plot fromPlot = PlotManager.getPlot(fromLocation); - Plot toPlot = PlotManager.getPlot(toLocation); - if (toPlot != null) { - if (fromPlot != null && fromPlot.getID() != toPlot.getID()) { - e.setCancelled(true); - } - if (fromPlot == null) { - e.setCancelled(true); - } - } - } - -} diff --git a/src/main/java/me/plytki/virtualrealty/listeners/VirtualListener.java b/src/main/java/me/plytki/virtualrealty/listeners/VirtualListener.java new file mode 100644 index 0000000..e612009 --- /dev/null +++ b/src/main/java/me/plytki/virtualrealty/listeners/VirtualListener.java @@ -0,0 +1,22 @@ +package me.plytki.virtualrealty.listeners; + +import me.plytki.virtualrealty.VirtualRealty; +import org.bukkit.event.Listener; + +public class VirtualListener implements Listener { + + private final VirtualRealty plugin; + + public VirtualListener(VirtualRealty plugin) { + this.plugin = plugin; + } + + public void registerEvents() { + this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin); + } + + protected VirtualRealty getPlugin() { + return this.plugin; + } + +} diff --git a/src/main/java/me/plytki/virtualrealty/listeners/WorldListener.java b/src/main/java/me/plytki/virtualrealty/listeners/WorldListener.java deleted file mode 100644 index a22789d..0000000 --- a/src/main/java/me/plytki/virtualrealty/listeners/WorldListener.java +++ /dev/null @@ -1,64 +0,0 @@ -package me.plytki.virtualrealty.listeners; - -import me.plytki.virtualrealty.VirtualRealty; -import me.plytki.virtualrealty.managers.PlotManager; -import me.plytki.virtualrealty.objects.Plot; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; - -public class WorldListener implements Listener { - - @EventHandler - public void onBlockBreak(BlockBreakEvent e) { - if (e.isCancelled()) return; - Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(e.getBlock().getLocation()); - if (!VirtualRealty.getPluginConfiguration().allowOutPlotBuild) { - if (!player.hasPermission("virtualrealty.build")) { - if (plot == null) { - e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } else { - if (plot.getOwnedBy() != null && !plot.getOwnedBy().equals(player.getUniqueId())) { - e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } else { - if (plot.getOwnedBy() == null) { - e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } - } - } - } - } - } - - @EventHandler - public void onBlockPlace(BlockPlaceEvent e) { - if (e.isCancelled()) return; - Player player = e.getPlayer(); - Plot plot = PlotManager.getPlot(e.getBlock().getLocation()); - if (!VirtualRealty.getPluginConfiguration().allowOutPlotBuild) { - if (!player.hasPermission("virtualrealty.build")) { - if (plot == null) { - e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } else { - if (plot.getOwnedBy() != null && !plot.getOwnedBy().equals(player.getUniqueId())) { - e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } else { - if (plot.getOwnedBy() == null) { - e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); - player.sendMessage(VirtualRealty.PREFIX + "§cYou can't build here!"); - } - } - } - } - } - } - -} diff --git a/src/main/java/me/plytki/virtualrealty/listeners/plot/BorderListener.java b/src/main/java/me/plytki/virtualrealty/listeners/plot/BorderListener.java new file mode 100644 index 0000000..4c034b9 --- /dev/null +++ b/src/main/java/me/plytki/virtualrealty/listeners/plot/BorderListener.java @@ -0,0 +1,44 @@ +package me.plytki.virtualrealty.listeners.plot; + +import me.plytki.virtualrealty.VirtualRealty; +import me.plytki.virtualrealty.enums.Permission; +import me.plytki.virtualrealty.listeners.VirtualListener; +import me.plytki.virtualrealty.managers.PlotManager; +import me.plytki.virtualrealty.objects.Plot; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +public class BorderListener extends VirtualListener { + + public BorderListener(VirtualRealty plugin) { + super(plugin); + } + + @EventHandler + public void onBorderBreak(BlockBreakEvent e) { + Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation()); + if (plot != null) { + if (!e.getPlayer().hasPermission(Permission.BORDER_BUILD.getPermission())) { + if (plot.getBorderBlocks().contains(e.getBlock())) { + e.setCancelled(true); + e.getPlayer().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + } + + @EventHandler + public void onBorderPlace(BlockPlaceEvent e) { + Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation()); + if (plot != null) { + if (!e.getPlayer().hasPermission(Permission.BORDER_BUILD.getPermission())) { + if (plot.getBorderBlocks().contains(e.getBlock())) { + e.setCancelled(true); + e.getPlayer().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + } + +} diff --git a/src/main/java/me/plytki/virtualrealty/listeners/PlotListener.java b/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java similarity index 83% rename from src/main/java/me/plytki/virtualrealty/listeners/PlotListener.java rename to src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java index 4c1d703..6d8bdaa 100644 --- a/src/main/java/me/plytki/virtualrealty/listeners/PlotListener.java +++ b/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java @@ -1,94 +1,101 @@ -package me.plytki.virtualrealty.listeners; - -import me.plytki.virtualrealty.VirtualRealty; -import me.plytki.virtualrealty.managers.PlotManager; -import me.plytki.virtualrealty.objects.Plot; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.*; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.util.AbstractMap; -import java.util.HashMap; - -public class PlotListener implements Listener { - - public static HashMap> enteredPlot = new HashMap<>(); - - @EventHandler - public void onPlotMove(PlayerMoveEvent e) { - Player player = e.getPlayer(); - Location to = e.getTo(); - Plot plot = PlotManager.getPlot(to); - if (plot != null) { - OfflinePlayer offlinePlayer; - String enterPlotString = "§2You have entered available plot!"; - if (plot.getOwnedBy() != null) { - offlinePlayer = Bukkit.getOfflinePlayer(plot.getOwnedBy()); - enterPlotString = "§7You have entered §2" + offlinePlayer.getName() + "'s §7plot!"; - } - if (!enteredPlot.containsKey(player)) { - enteredPlot.put(player, new AbstractMap.SimpleEntry<>(plot, true)); - if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) { - if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(player.getUniqueId())) { - if (VirtualRealty.getPluginConfiguration().forcePlotGameMode) { - player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode()); - } else { - player.setGameMode(plot.getSelectedGameMode()); - } - } - } - if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) { - if (VirtualRealty.getPluginConfiguration().plotSound) { - player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_OPEN, 0.4f, 0.8f); - } - } - if (!(VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8") || VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8"))) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(enterPlotString)); - } - } else { - if (!enteredPlot.get(player).getValue()) { - enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(plot, true)); - if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) { - if (VirtualRealty.getPluginConfiguration().forcePlotGameMode) { - player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode()); - } else { - player.setGameMode(plot.getSelectedGameMode()); - } - } - } - } - } else { - if (enteredPlot.containsKey(player)) { - if (enteredPlot.get(player).getValue()) { - OfflinePlayer offlinePlayer; - String leavePlotString = "§cYou have left available plot!"; - if (enteredPlot.get(player).getKey().getOwnedBy() != null) { - offlinePlayer = Bukkit.getOfflinePlayer(enteredPlot.get(player).getKey().getOwnedBy()); - leavePlotString = "§7You have left §2" + offlinePlayer.getName() + "'s §7plot!"; - if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) { - if (enteredPlot.get(player).getKey().getOwnedBy() != null && enteredPlot.get(player).getKey().getOwnedBy().equals(player.getUniqueId())) { - player.setGameMode(Bukkit.getServer().getDefaultGameMode()); - } - } - } - if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) { - if (VirtualRealty.getPluginConfiguration().plotSound) { - player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, 0.3f, 1f); - } - if (!(VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8") || VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8"))) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(leavePlotString)); - } - } - enteredPlot.remove(player); - return; - } - enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(enteredPlot.get(player).getKey(), false)); - } - } - } - -} +package me.plytki.virtualrealty.listeners.plot; + +import me.plytki.virtualrealty.VirtualRealty; +import me.plytki.virtualrealty.listeners.VirtualListener; +import me.plytki.virtualrealty.managers.PlotManager; +import me.plytki.virtualrealty.objects.Plot; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; + +import java.util.AbstractMap; +import java.util.HashMap; + +public class PlotListener extends VirtualListener { + + public HashMap> enteredPlot = new HashMap<>(); + + public PlotListener(VirtualRealty plugin) { + super(plugin); + } + + @EventHandler + public void onPlotMove(PlayerMoveEvent e) { + Player player = e.getPlayer(); + Location to = e.getTo(); + Plot plot = PlotManager.getPlot(to); + if (plot != null) { + OfflinePlayer offlinePlayer; + String enterPlotString = VirtualRealty.getMessages().enteredAvailablePlot; + if (plot.getOwnedBy() != null) { + offlinePlayer = Bukkit.getOfflinePlayer(plot.getOwnedBy()); + enterPlotString = VirtualRealty.getMessages().enteredOwnedPlot.replaceAll("%owner%", offlinePlayer.getName()); + } + if (!enteredPlot.containsKey(player)) { + enteredPlot.put(player, new AbstractMap.SimpleEntry<>(plot, true)); + if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) { + if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(player.getUniqueId())) { + if (VirtualRealty.getPluginConfiguration().forcePlotGameMode) { + player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode()); + } else { + player.setGameMode(plot.getSelectedGameMode()); + } + } + } + if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) { + if (VirtualRealty.getPluginConfiguration().plotSound) { + player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_OPEN, 0.4f, 0.8f); + } + } + if (!(VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8") || VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8"))) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(enterPlotString)); + } + } else { + if (!enteredPlot.get(player).getValue()) { + enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(plot, true)); + if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) { + if (VirtualRealty.getPluginConfiguration().forcePlotGameMode) { + player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode()); + } else { + player.setGameMode(plot.getSelectedGameMode()); + } + } + } + } + } else { + if (enteredPlot.containsKey(player)) { + if (enteredPlot.get(player).getValue()) { + OfflinePlayer offlinePlayer; + String leavePlotString = VirtualRealty.getMessages().leftAvailablePlot; + if (enteredPlot.get(player).getKey().getOwnedBy() != null) { + offlinePlayer = Bukkit.getOfflinePlayer(enteredPlot.get(player).getKey().getOwnedBy()); + leavePlotString = VirtualRealty.getMessages().leftOwnedPlot.replaceAll("%owner%", offlinePlayer.getName()); + if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) { + if (enteredPlot.get(player).getKey().getOwnedBy() != null && enteredPlot.get(player).getKey().getOwnedBy().equals(player.getUniqueId())) { + player.setGameMode(Bukkit.getServer().getDefaultGameMode()); + } + } + } + if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) { + if (VirtualRealty.getPluginConfiguration().plotSound) { + player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, 0.3f, 1f); + } + if (!(VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8") || VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8"))) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(leavePlotString)); + } + } + enteredPlot.remove(player); + return; + } + enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(enteredPlot.get(player).getKey(), false)); + } + } + } + +} diff --git a/src/main/java/me/plytki/virtualrealty/listeners/plot/ProtectionListener.java b/src/main/java/me/plytki/virtualrealty/listeners/plot/ProtectionListener.java new file mode 100644 index 0000000..610497a --- /dev/null +++ b/src/main/java/me/plytki/virtualrealty/listeners/plot/ProtectionListener.java @@ -0,0 +1,330 @@ +package me.plytki.virtualrealty.listeners.plot; + +import me.plytki.virtualrealty.VirtualRealty; +import me.plytki.virtualrealty.listeners.VirtualListener; +import me.plytki.virtualrealty.managers.PlotManager; +import me.plytki.virtualrealty.objects.Plot; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.world.StructureGrowEvent; + +import java.time.LocalDateTime; + +public class ProtectionListener extends VirtualListener { + + public ProtectionListener(VirtualRealty plugin) { + super(plugin); + } + + @EventHandler + public void onBlockInteract(PlayerInteractEvent e) { + Player player = e.getPlayer(); + if (e.getClickedBlock() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType().isInteractable()) { + Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation()); + if (plot != null) { + if (plot.hasPermissionToPlot(player)) { + if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + } + } else { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + } + } + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent e) { + Player player = e.getPlayer(); + Plot plot = PlotManager.getPlot(e.getBlockPlaced().getLocation()); + if (plot != null) { + if (plot.hasPermissionToPlot(player)) { + if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + } + } else { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent e) { + Player player = e.getPlayer(); + Plot plot = PlotManager.getPlot(e.getBlock().getLocation()); + if (plot != null) { + if (plot.hasPermissionToPlot(player)) { + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + } + } else { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + + @EventHandler + public void onBlockMove(BlockPistonExtendEvent e) { + if (e.getBlocks().isEmpty()) { + Location fromLocation = e.getBlock().getLocation(); + Location toLocation = e.getBlock().getLocation(); + toLocation.add(e.getDirection().getDirection()); + Plot fromPlot = PlotManager.getBorderedPlot(fromLocation); + Plot toPlot = PlotManager.getBorderedPlot(toLocation); + if (toPlot != null) { + if (fromPlot == null) { + e.setCancelled(true); + } else if (fromPlot.getID() != toPlot.getID()) { + e.setCancelled(true); + } + } + } else { + for (Block block : e.getBlocks()) { + Location fromLocation = block.getLocation(); + Location toLocation = block.getLocation(); + toLocation.add(e.getDirection().getDirection()); + Plot fromPlot = PlotManager.getBorderedPlot(fromLocation); + Plot toPlot = PlotManager.getBorderedPlot(toLocation); + if (toPlot != null) { + if (fromPlot == null) { + e.setCancelled(true); + } else if (fromPlot.getID() != toPlot.getID()) { + e.setCancelled(true); + } + } + } + } + } + @EventHandler + public void onIgniteEvent(BlockIgniteEvent e) { + Player player = e.getPlayer(); + if (e.getIgnitingBlock() != null) { + Plot plot = PlotManager.getBorderedPlot(e.getIgnitingBlock().getLocation()); + if (plot != null) { + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + return; + } + e.setCancelled(!plot.hasPermissionToPlot(player)); + } + } + } + + @EventHandler + public void onEntityExplode(ExplosionPrimeEvent e) { + Plot plot = PlotManager.getBorderedPlot(e.getEntity().getLocation()); + if (plot != null) { + e.setCancelled(true); + } + } + + @EventHandler + public void onPlotEnter(PlayerMoveEvent e) { + Player player = e.getPlayer(); + Plot plot = PlotManager.getPlot(e.getTo()); + if (plot != null && e.getPlayer().isInsideVehicle()) { + if (!plot.hasPermissionToPlot(player)) { + e.getPlayer().getVehicle().eject(); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantRideOnPlot); + } + } + } + + @EventHandler + public void onTreeGrow(StructureGrowEvent e) { + for (BlockState block : e.getBlocks()) { + Location fromLocation = e.getLocation(); + Location toLocation = block.getLocation(); + Plot fromPlot = PlotManager.getPlot(fromLocation); + Plot toPlot = PlotManager.getPlot(toLocation); + if (toPlot != null) { + if (fromPlot == null) { + e.setCancelled(true); + } else if (fromPlot.getID() != toPlot.getID()) { + e.setCancelled(true); + } + } + } + } + + @EventHandler + public void onDragonEggMove(BlockFromToEvent e) { + Material block = e.getBlock().getType(); + 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); + if (toPlot != null) { + if (fromPlot == null) { + e.setCancelled(true); + } else if (fromPlot.getID() != toPlot.getID()) { + e.setCancelled(true); + } + } + } + } + + @EventHandler + public void onProjectileLaunch(ProjectileLaunchEvent e) { + Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + if (plot != null) { + if (!(e.getEntity().getShooter() instanceof Player && plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player)e.getEntity().getShooter()).getUniqueId()))) { + Player player = (Player) e.getEntity().getShooter(); + if (plot.hasPermissionToPlot(player)) { + if (plot.isOwnershipExpired()) { + e.getEntity().remove(); + } + } else { + e.getEntity().remove(); + } + } + } + } + + @EventHandler + public void onProjectileHit(ProjectileHitEvent e) { + Plot plot = PlotManager.getPlot(e.getEntity().getLocation()); + if (plot != null) { + if (!(e.getEntity().getShooter() instanceof Player && plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player)e.getEntity().getShooter()).getUniqueId()))) { + Player player = (Player) e.getEntity().getShooter(); + if (plot.hasPermissionToPlot(player)) { + if (plot.isOwnershipExpired()) { + e.getEntity().remove(); + } + } else { + e.getEntity().remove(); + } + } + } + } + + @EventHandler + public void onFireSpread(BlockSpreadEvent e) { + Location fromLocation = e.getSource().getLocation(); + Location toLocation = e.getBlock().getLocation(); + Plot fromPlot = PlotManager.getPlot(fromLocation); + Plot toPlot = PlotManager.getPlot(toLocation); + if (toPlot != null) { + if (fromPlot == null) { + e.setCancelled(true); + } else if (fromPlot.getID() != toPlot.getID()) { + e.setCancelled(true); + } + } + } + + @EventHandler + public void onArmorStandChange(PlayerArmorStandManipulateEvent e) { + Plot plot = PlotManager.getPlot(e.getPlayer().getLocation()); + Player player = e.getPlayer(); + if (plot != null) { + if (plot.hasPermissionToPlot(player)) { + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + } + } else { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + } + } + } + + @EventHandler + public void onItemFrameDamage(HangingBreakByEntityEvent e) { + if (e.getRemover() instanceof Player) { + Player player = (Player) e.getRemover(); + Plot plot = PlotManager.getPlot(player.getLocation()); + if (plot != null) { + if (plot.hasPermissionToPlot(player)) { + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + } + } else { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + } + } + } + } + + @EventHandler + public void onItemFrameRotate(PlayerInteractEntityEvent e) { + if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) { + Player player = e.getPlayer(); + Plot plot = PlotManager.getPlot(player.getLocation()); + if (plot != null) { + if (plot.hasPermissionToPlot(player)) { + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + } + } else { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract); + } + } + } + } + + + @EventHandler + public void onEntityDamage(EntityDamageByEntityEvent e) { + if (e.getDamager() instanceof Player) { + Player player = (Player) e.getDamager(); + Plot plot = PlotManager.getPlot(player.getLocation()); + if (plot != null) { + if (plot.hasPermissionToPlot(player)) { + if (plot.isOwnershipExpired()) { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired); + } + } else { + e.setCancelled(true); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG); + } + } + } + } + + @EventHandler + public void onEntityProjectileDamage(EntityDamageByEntityEvent e) { + if (e.getDamager() instanceof Projectile) { + if (((Projectile) e.getDamager()).getShooter() instanceof Player) { + Player player = ((Player) ((Projectile) e.getDamager()).getShooter()); + Plot plot = PlotManager.getBorderedPlot(e.getDamager().getLocation()); + if (plot != null) { + if (!plot.hasPermissionToPlot(player)) { + e.getDamager().remove(); + e.setCancelled(true); + } + } + } + } + } + +} diff --git a/src/main/java/me/plytki/virtualrealty/listeners/world/WorldListener.java b/src/main/java/me/plytki/virtualrealty/listeners/world/WorldListener.java new file mode 100644 index 0000000..4a45a15 --- /dev/null +++ b/src/main/java/me/plytki/virtualrealty/listeners/world/WorldListener.java @@ -0,0 +1,49 @@ +package me.plytki.virtualrealty.listeners.world; + +import me.plytki.virtualrealty.VirtualRealty; +import me.plytki.virtualrealty.enums.Permission; +import me.plytki.virtualrealty.listeners.VirtualListener; +import me.plytki.virtualrealty.managers.PlotManager; +import me.plytki.virtualrealty.objects.Plot; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +public class WorldListener extends VirtualListener { + + public WorldListener(VirtualRealty plugin) { + super(plugin); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent e) { + if (e.isCancelled()) return; + Player player = e.getPlayer(); + Plot plot = PlotManager.getPlot(e.getBlock().getLocation()); + if (!VirtualRealty.getPluginConfiguration().allowOutPlotBuild) { + if (!player.hasPermission(Permission.WORLD_BUILD.getPermission())) { + if (plot == null) { + e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent e) { + if (e.isCancelled()) return; + Player player = e.getPlayer(); + Plot plot = PlotManager.getPlot(e.getBlock().getLocation()); + if (!VirtualRealty.getPluginConfiguration().allowOutPlotBuild) { + if (!player.hasPermission(Permission.WORLD_BUILD.getPermission())) { + if (plot == null) { + e.setCancelled(!VirtualRealty.getPluginConfiguration().allowOutPlotBuild); + player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere); + } + } + } + } + +} \ No newline at end of file diff --git a/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java b/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java index 83e932c..d5f2b8f 100644 --- a/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java +++ b/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java @@ -12,22 +12,21 @@ import org.bukkit.Location; import org.bukkit.Material; import org.dynmap.markers.AreaMarker; +import org.dynmap.markers.Marker; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class PlotManager { private static final String markerString = "

Plot #%s

Owned By: Available"; private static final String markerOwnedString = "

Plot #%s

Owned By: %s
Owned Until: %s"; - public static ArrayList areaMarkers = new ArrayList<>(); - public static ArrayList plots = new ArrayList<>(); + public static Set areaMarkers = new HashSet<>(); + public static Set plots = new LinkedHashSet<>(); public static void loadPlots() { plots.clear(); @@ -64,6 +63,16 @@ public static Plot getPlot(int ID) { return null; } + public static int getPlotMinID() { + return plots.isEmpty() ? null : plots.stream().findFirst().get().getID(); + } + + public static int getPlotMaxID() { + Plot[] plotArray = PlotManager.plots.toArray(new Plot[PlotManager.plots.size()]); + Plot lastPlot = plotArray[plotArray.length - 1]; + return lastPlot.getID(); + } + public static List getPlayerPlots(UUID owner) { List playerPlots = new ArrayList<>(); for (Plot plot : plots) { @@ -122,7 +131,7 @@ public static boolean isColliding(Cuboid newPlot) { return false; } - public static AreaMarker getAreaMarker(String areaMarkerName) { + private static AreaMarker getAreaMarker(String areaMarkerName) { for (AreaMarker areaMarker : VirtualRealty.markerset.getAreaMarkers()) { if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) { return areaMarker; @@ -132,6 +141,7 @@ public static AreaMarker getAreaMarker(String areaMarkerName) { } public static void resetPlotMarker(Plot plot) { + if (!VirtualRealty.isDynmapPresent) return; LocalDateTime localDateTime = plot.getOwnedUntilDate(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); String ownedBy; @@ -166,10 +176,11 @@ public static void resetPlotMarker(Plot plot) { marker.setFillStyle(opacity, color); marker.setLineStyle(2, 0.8, 0x474747); marker.setMarkerSet(VirtualRealty.markerset); + //VirtualRealty.markerset.createMarker(String.valueOf(plot.getID()), ownedBy, plot.getCreatedWorld(), plot.getCenter().getBlockX(), plot.getCenter().getBlockY(), plot.getCenter().getBlockZ(), VirtualRealty.markerIcon, true); } public static void removeDynMapMarker(Plot plot) { - if (VirtualRealty.dapi == null || VirtualRealty.markerset == null) return; + if (!VirtualRealty.isDynmapPresent || VirtualRealty.dapi == null || VirtualRealty.markerset == null) return; AreaMarker marker = VirtualRealty.markerset.findAreaMarker("virtualrealty.plots." + plot.getID()); areaMarkers.remove(marker); marker.deleteMarker(); diff --git a/src/main/java/me/plytki/virtualrealty/objects/Plot.java b/src/main/java/me/plytki/virtualrealty/objects/Plot.java index f274a03..ab1c982 100644 --- a/src/main/java/me/plytki/virtualrealty/objects/Plot.java +++ b/src/main/java/me/plytki/virtualrealty/objects/Plot.java @@ -2,6 +2,7 @@ import me.plytki.virtualrealty.VirtualRealty; import me.plytki.virtualrealty.enums.Direction; +import me.plytki.virtualrealty.enums.Permission; import me.plytki.virtualrealty.enums.PlotSize; import me.plytki.virtualrealty.managers.PlotManager; import me.plytki.virtualrealty.objects.math.BlockVector3; @@ -10,6 +11,7 @@ import org.apache.commons.io.FileUtils; import org.bukkit.*; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -24,6 +26,7 @@ public class Plot { private int ID; private UUID ownedBy; + private Set members; private String assignedBy; private LocalDateTime ownedUntilDate; private PlotSize plotSize; @@ -49,8 +52,9 @@ public String toString() { } public Plot(Location location, Material floorMaterial, Material borderMaterial, PlotSize plotSize) { - this.ID = PlotManager.plots.isEmpty() ? 10000 : PlotManager.plots.get(PlotManager.plots.size() - 1).getID() + 1; + this.ID = PlotManager.plots.isEmpty() ? 10000 : PlotManager.getPlotMaxID() + 1; this.ownedBy = null; + this.members = new HashSet<>(); this.assignedBy = null; this.ownedUntilDate = LocalDateTime.of(2999, 12, 31, 0, 0); this.floorMaterial = floorMaterial; @@ -73,8 +77,9 @@ public Plot(Location location, Material floorMaterial, Material borderMaterial, } public Plot(Location location, Material floorMaterial, Material borderMaterial, int length, int width, int height) { - this.ID = PlotManager.plots.isEmpty() ? 10000 : PlotManager.plots.get(PlotManager.plots.size() - 1).getID() + 1; + this.ID = PlotManager.plots.isEmpty() ? 10000 : PlotManager.getPlotMaxID() + 1; this.ownedBy = null; + this.members = new HashSet<>(); this.assignedBy = null; this.ownedUntilDate = LocalDateTime.of(2999, 12, 31, 0, 0); this.floorMaterial = floorMaterial; @@ -101,6 +106,14 @@ public Plot(ResultSet rs) { try { this.ID = rs.getInt("ID"); this.ownedBy = rs.getString("ownedBy").isEmpty() ? null : UUID.fromString(rs.getString("ownedBy")); + this.members = new HashSet<>(); + String membersString = rs.getString("members"); + if (membersString != null && !membersString.isEmpty()) { + String[] membersArray = membersString.substring(0, membersString.length() - 1).split(";"); + for (String s : membersArray) { + members.add(UUID.fromString(s)); + } + } this.assignedBy = rs.getString("assignedBy").equalsIgnoreCase("null") ? null : rs.getString("assignedBy"); this.ownedUntilDate = rs.getTimestamp("ownedUntilDate").toLocalDateTime(); this.floorMaterial = Material.getMaterial(rs.getString("floorMaterial").split(":")[0]); @@ -133,6 +146,16 @@ public Plot(ResultSet rs) { } } + public boolean hasPermissionToPlot(Player player) { + if (player.hasPermission(Permission.PLOT_BUILD.getPermission())) return true; + if (members.contains(player.getUniqueId())) return true; + return ownedBy != null && ownedBy.equals(player.getUniqueId()); + } + + public boolean isOwnershipExpired() { + return ownedUntilDate.isBefore(LocalDateTime.now()); + } + public int getXMin() { return Math.min(this.getBorderBottomLeftCorner().getBlockX(), this.borderTopRightCorner.getBlockX()); } @@ -163,6 +186,7 @@ public UUID getOwnedBy() { public void setOwnedBy(UUID ownedBy) { this.ownedBy = ownedBy; + members.remove(ownedBy); updateMarker(); } @@ -219,7 +243,7 @@ public Material getFloorMaterial() { return floorMaterial; } - public void setFloor(Material floorMaterial, byte data) { + public void setFloorMaterial(Material floorMaterial, byte data) { this.floorMaterial = floorMaterial; this.floorData = data; initializeFloor(); @@ -298,6 +322,44 @@ public void setSelectedGameMode(GameMode selectedGameMode) { this.selectedGameMode = selectedGameMode; } + public void addMember(UUID uuid) { + members.add(uuid); + } + + public void removeMember(UUID uuid) { + members.remove(uuid); + } + + public Set getMembers() { + return members; + } + + public Set getMembersPlayer() { + Set offlinePlayers = new HashSet<>(); + for (UUID member : members) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(member); + offlinePlayers.add(offlinePlayer); + } + return offlinePlayers; + } + + private void setFloorBlock(Block floorBlock) { + if (VirtualRealty.isLegacy) { + try { + Method m = Block.class.getDeclaredMethod("setType", Material.class); + m.setAccessible(true); + m.invoke(floorBlock, this.floorMaterial); + Method m2 = Block.class.getDeclaredMethod("setData", byte.class); + m2.setAccessible(true); + m2.invoke(floorBlock, this.floorData); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + floorBlock.setType(floorMaterial); + } + } + private void initializeFloor() { Location location = createdLocation; Direction direction = Direction.byYaw(location.getYaw()); @@ -306,20 +368,7 @@ private void initializeFloor() { for (int x = location.getBlockX() - width + 1; x < location.getBlockX() + 1; x++) { for (int z = location.getBlockZ(); z < location.getBlockZ() + length; z++) { Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - if (VirtualRealty.isLegacy) { - try { - Method m = Block.class.getDeclaredMethod("setType", Material.class); - m.setAccessible(true); - m.invoke(floorBlock, this.floorMaterial); - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, this.floorData); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - floorBlock.setType(floorMaterial); - } + setFloorBlock(floorBlock); } } break; @@ -328,20 +377,7 @@ private void initializeFloor() { for (int x = location.getBlockX() - length + 1; x < location.getBlockX() + 1; x++) { for (int z = location.getBlockZ() - width + 1; z < location.getBlockZ() + 1; z++) { Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - if (VirtualRealty.isLegacy) { - try { - Method m = Block.class.getDeclaredMethod("setType", Material.class); - m.setAccessible(true); - m.invoke(floorBlock, this.floorMaterial); - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, this.floorData); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - floorBlock.setType(floorMaterial); - } + setFloorBlock(floorBlock); } } break; @@ -350,20 +386,7 @@ private void initializeFloor() { for (int x = location.getBlockX(); x < location.getBlockX() + width; x++) { for (int z = location.getBlockZ() - length + 1; z < location.getBlockZ() + 1; z++) { Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - if (VirtualRealty.isLegacy) { - try { - Method m = Block.class.getDeclaredMethod("setType", Material.class); - m.setAccessible(true); - m.invoke(floorBlock, this.floorMaterial); - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, this.floorData); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - floorBlock.setType(floorMaterial); - } + setFloorBlock(floorBlock); } } break; @@ -372,20 +395,7 @@ private void initializeFloor() { for (int x = location.getBlockX(); x < location.getBlockX() + length; x++) { for (int z = location.getBlockZ(); z < location.getBlockZ() + width; z++) { Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - if (VirtualRealty.isLegacy) { - try { - Method m = Block.class.getDeclaredMethod("setType", Material.class); - m.setAccessible(true); - m.invoke(floorBlock, this.floorMaterial); - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, this.floorData); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - floorBlock.setType(floorMaterial); - } + setFloorBlock(floorBlock); } } break; @@ -444,119 +454,121 @@ public void initialize() { prepareBlocks(createdLocation); } - public void setBorder(Material material, byte data) { - borderMaterial = material; - borderData = data; + public Set getBorderBlocks() { + Set blocks = new HashSet<>(); Location location = this.getCreatedLocation(); Direction direction = Direction.byYaw(location.getYaw()); + int maxX; + int maxZ; + int minX; + int minZ; switch(direction) { case SOUTH: { - int maxX = location.getBlockX() + 1 + 1; - int maxZ = location.getBlockZ() + length + 1; - int minX = location.getBlockX() - width + 1; - int minZ = location.getBlockZ() - 1; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(material); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, data); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(material); - } - } - } - } + maxX = location.getBlockX() + 1 + 1; + maxZ = location.getBlockZ() + length + 1; + minX = location.getBlockX() - width + 1; + minZ = location.getBlockZ() - 1; break; } case WEST: { - int maxX = location.getBlockX() + 1 + 1; - int maxZ = location.getBlockZ() + 1 + 1; - int minX = location.getBlockX() - length + 1; - int minZ = location.getBlockZ() - width; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(material); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, data); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(material); - } - } - } - } + maxX = location.getBlockX() + 1 + 1; + maxZ = location.getBlockZ() + 1 + 1; + minX = location.getBlockX() - length + 1; + minZ = location.getBlockZ() - width; break; } case NORTH: { - int maxX = location.getBlockX() + width + 1; - int maxZ = location.getBlockZ() + 1 + 1; - int minX = location.getBlockX(); - int minZ = location.getBlockZ() - length; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(material); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, data); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(material); - } - } - } - } + maxX = location.getBlockX() + width + 1; + maxZ = location.getBlockZ() + 1 + 1; + minX = location.getBlockX(); + minZ = location.getBlockZ() - length; break; } case EAST: { - int maxX = location.getBlockX() + length + 1; - int maxZ = location.getBlockZ() + width + 1; - int minX = location.getBlockX(); - int minZ = location.getBlockZ() - 1; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(material); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, data); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(material); - } - } - } + maxX = location.getBlockX() + length + 1; + maxZ = location.getBlockZ() + width + 1; + minX = location.getBlockX(); + minZ = location.getBlockZ() - 1; + break; + } + default: + throw new IllegalStateException("Unexpected value: " + direction); + } + for (int x = minX - 1; x < maxX; x++) { + for (int z = minZ; z < maxZ; z++) { + if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { + blocks.add(location.getWorld().getBlockAt(x, location.getBlockY() + 1, z)); } + } + } + return blocks; + } + + public Set getFloorBlocks() { + Set blocks = new HashSet<>(); + Location location = this.getCreatedLocation(); + Direction direction = Direction.byYaw(location.getYaw()); + int maxX; + int maxZ; + int minX; + int minZ; + switch(direction) { + case SOUTH: { + maxX = location.getBlockX() + 1 + 1; + maxZ = location.getBlockZ() + length + 1; + minX = location.getBlockX() - width + 1; + minZ = location.getBlockZ() - 1; + break; + } + case WEST: { + maxX = location.getBlockX() + 1 + 1; + maxZ = location.getBlockZ() + 1 + 1; + minX = location.getBlockX() - length + 1; + minZ = location.getBlockZ() - width; + break; + } + case NORTH: { + maxX = location.getBlockX() + width + 1; + maxZ = location.getBlockZ() + 1 + 1; + minX = location.getBlockX(); + minZ = location.getBlockZ() - length; + break; + } + case EAST: { + maxX = location.getBlockX() + length + 1; + maxZ = location.getBlockZ() + width + 1; + minX = location.getBlockX(); + minZ = location.getBlockZ() - 1; break; } default: throw new IllegalStateException("Unexpected value: " + direction); } + for (int x = minX - 1; x < maxX; x++) { + for (int z = minZ; z < maxZ; z++) { + blocks.add(location.getWorld().getBlockAt(x, location.getBlockY(), z)); + } + } + return blocks; + } + + public void setBorder(Material material, byte data) { + borderMaterial = material; + borderData = data; + for (Block borderBlock : getBorderBlocks()) { + if (VirtualRealty.isLegacy) { + borderBlock.setType(material); + try { + Method m2 = Block.class.getDeclaredMethod("setData", byte.class); + m2.setAccessible(true); + m2.invoke(borderBlock, data); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } else { + borderBlock.setType(material); + } + } } public void prepareBlocks(Location location) { @@ -568,196 +580,95 @@ public void prepareBlocks(Location location) { 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())); - for (int x = location.getBlockX() - width + 1; x < location.getBlockX() + 1; x++) { - for (int z = location.getBlockZ(); z < location.getBlockZ() + length; z++) { - for (int y = location.getBlockY() + height; y > location.getBlockY() - 1; y--) { - Block airBlock = location.getWorld().getBlockAt(x, y, z); - airBlock.setType(Material.AIR); - } - Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - floorBlock.setType(floorMaterial); - if (VirtualRealty.isLegacy) { - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, plotSize.getFloorData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - } - } - int maxX = location.getBlockX() + 1 + 1; - int maxZ = location.getBlockZ() + length + 1; - int minX = location.getBlockX() - width + 1; - int minZ = location.getBlockZ() - 1; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(plotSize.getBorderMaterial()); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, plotSize.getBorderData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(plotSize.getBorderMaterial()); - } - } - } - } 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())); - for (int x = location.getBlockX() - length + 1; x < location.getBlockX() + 1; x++) { - for (int z = location.getBlockZ() - width + 1; z < location.getBlockZ() + 1; z++) { - for (int y = location.getBlockY() + height; y > location.getBlockY() - 1; y--) { - Block airBlock = location.getWorld().getBlockAt(x, y, z); - airBlock.setType(Material.AIR); - } - Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - floorBlock.setType(floorMaterial); - if (VirtualRealty.isLegacy) { - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, plotSize.getFloorData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - } - } - int maxX = location.getBlockX() + 1 + 1; - int maxZ = location.getBlockZ() + 1 + 1; - int minX = location.getBlockX() - length + 1; - int minZ = location.getBlockZ() - width; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(plotSize.getBorderMaterial()); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, plotSize.getBorderData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(plotSize.getBorderMaterial()); - } - } - } - } 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())); - for (int x = location.getBlockX(); x < location.getBlockX() + width; x++) { - for (int z = location.getBlockZ() - length + 1; z < location.getBlockZ() + 1; z++) { - for (int y = location.getBlockY() + height; y > location.getBlockY() - 1; y--) { - Block airBlock = location.getWorld().getBlockAt(x, y, z); - airBlock.setType(Material.AIR); - } - Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - floorBlock.setType(floorMaterial); - if (VirtualRealty.isLegacy) { - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, plotSize.getFloorData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - } - } - int maxX = location.getBlockX() + width + 1; - int maxZ = location.getBlockZ() + 1 + 1; - int minX = location.getBlockX(); - int minZ = location.getBlockZ() - length; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(plotSize.getBorderMaterial()); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, plotSize.getBorderData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(plotSize.getBorderMaterial()); - } - } - } - } 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())); - for (int x = location.getBlockX(); x < location.getBlockX() + length; x++) { - for (int z = location.getBlockZ(); z < location.getBlockZ() + width; z++) { - for (int y = location.getBlockY() + height; y > location.getBlockY() - 1; y--) { - Block airBlock = location.getWorld().getBlockAt(x, y, z); - airBlock.setType(Material.AIR); - } - Block floorBlock = location.getWorld().getBlockAt(x, location.getBlockY(), z); - floorBlock.setType(floorMaterial); - if (VirtualRealty.isLegacy) { - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(floorBlock, plotSize.getFloorData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - } + break; + } + } + for (Block floorBlock : getFloorBlocks()) { + for (int y = location.getBlockY() + height; y > location.getBlockY() - 1; y--) { + Block airBlock = location.getWorld().getBlockAt(floorBlock.getX(), y, floorBlock.getZ()); + airBlock.setType(Material.AIR); + } + floorBlock.setType(floorMaterial); + if (VirtualRealty.isLegacy) { + try { + Method m2 = Block.class.getDeclaredMethod("setData", byte.class); + m2.setAccessible(true); + m2.invoke(floorBlock, plotSize.getFloorData()); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); } - int maxX = location.getBlockX() + length + 1; - int maxZ = location.getBlockZ() + width + 1; - int minX = location.getBlockX(); - int minZ = location.getBlockZ() - 1; - for (int x = minX - 1; x < maxX; x++) { - for (int z = minZ; z < maxZ; z++) { - if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { - Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); - if (VirtualRealty.isLegacy) { - borderBlock.setType(plotSize.getBorderMaterial()); - try { - Method m2 = Block.class.getDeclaredMethod("setData", byte.class); - m2.setAccessible(true); - m2.invoke(borderBlock, plotSize.getBorderData()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } else { - borderBlock.setType(plotSize.getBorderMaterial()); - } + } + } + int maxX = 0; + int maxZ = 0; + int minX = 0; + int minZ = 0; + switch(direction) { + case SOUTH: { + maxX = location.getBlockX() + 1 + 1; + maxZ = location.getBlockZ() + length + 1; + minX = location.getBlockX() - width + 1; + minZ = location.getBlockZ() - 1; + break; + } + case WEST: { + maxX = location.getBlockX() + 1 + 1; + maxZ = location.getBlockZ() + 1 + 1; + minX = location.getBlockX() - length + 1; + minZ = location.getBlockZ() - width; + break; + } + case NORTH: { + maxX = location.getBlockX() + width + 1; + maxZ = location.getBlockZ() + 1 + 1; + minX = location.getBlockX(); + minZ = location.getBlockZ() - length; + break; + } + case EAST: { + maxX = location.getBlockX() + length + 1; + maxZ = location.getBlockZ() + width + 1; + minX = location.getBlockX(); + minZ = location.getBlockZ() - 1; + break; + } + } + for (int x = minX - 1; x < maxX; x++) { + for (int z = minZ; z < maxZ; z++) { + if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) { + Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z); + if (VirtualRealty.isLegacy) { + borderBlock.setType(plotSize.getBorderMaterial()); + try { + Method m2 = Block.class.getDeclaredMethod("setData", byte.class); + m2.setAccessible(true); + m2.invoke(borderBlock, plotSize.getBorderData()); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); } + } else { + borderBlock.setType(plotSize.getBorderMaterial()); } } - break; } - default: - throw new IllegalStateException("Unexpected value: " + direction); } } @@ -786,6 +697,14 @@ public void unloadPlot() { } } + public String getMembersString() { + StringBuilder stringBuilder = new StringBuilder(); + for (UUID member : members) { + stringBuilder.append(member.toString()).append(";"); + } + return stringBuilder.toString(); + } + public void insert() { StringBuilder builder = new StringBuilder(); builder.append(this.createdLocation.getWorld().getName() + ";"); @@ -795,9 +714,9 @@ public void insert() { builder.append(this.createdLocation.getYaw() + ";"); builder.append(this.createdLocation.getPitch() + ";"); try { - SQL.getStatement().execute("INSERT INTO `vr_plots` (`ID`, `ownedBy`, `assignedBy`, `ownedUntilDate`," + + SQL.getStatement().execute("INSERT INTO `vr_plots` (`ID`, `ownedBy`, `members`, `assignedBy`, `ownedUntilDate`," + " `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`, `createdLocation`) " + - "VALUES ('" + this.ID + "', '" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "', '" + this.assignedBy + "', " + + "VALUES ('" + this.ID + "', '" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "','" + getMembersString() + "', '" + this.assignedBy + "', " + "'" + Timestamp.valueOf(this.ownedUntilDate) + "', '" + this.floorMaterial + ":" + this.floorData + "', '" + this.borderMaterial + ":" + this.borderData + "'," + " '" + this.plotSize + "', '" + this.length + "', '" + this.width + "', '" + this.height + "', '" + builder + "')"); } catch (SQLException e) { @@ -807,7 +726,7 @@ public void insert() { public void update() { try { - SQL.getStatement().execute("UPDATE `vr_plots` SET `ownedBy`='" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "', `assignedBy`='" + this.assignedBy + "'," + + SQL.getStatement().execute("UPDATE `vr_plots` SET `ownedBy`='" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "', `members`='" + getMembersString() + "', `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 + "'" + " WHERE `ID`='" + this.ID + "'"); diff --git a/src/main/java/me/plytki/virtualrealty/sql/SQL.java b/src/main/java/me/plytki/virtualrealty/sql/SQL.java index 42411be..a7731f6 100644 --- a/src/main/java/me/plytki/virtualrealty/sql/SQL.java +++ b/src/main/java/me/plytki/virtualrealty/sql/SQL.java @@ -62,18 +62,22 @@ public static void closeConnection() { public static void createTables() { try { - SQL.getStatement().execute("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID` INT(12) NOT NULL, `ownedBy` VARCHAR(36) 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, PRIMARY KEY(`ID`))"); + SQL.getStatement().execute("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID` INT(12) NOT NULL, `ownedBy` VARCHAR(36) NOT NULL, `members` TEXT, `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, PRIMARY KEY(`ID`))"); updateTables(); } catch (SQLException ex) { ex.printStackTrace(); } } + public static void updateTables() { + try { + SQL.getStatement().execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `borderMaterial` VARCHAR(32) AFTER `floorMaterial`;"); + } catch (SQLException ignored) { - private static void updateTables() { + } try { - SQL.getStatement().execute("ALTER TABLE `vr_plots` ADD `borderMaterial` VARCHAR(32) AFTER `floorMaterial`;"); - } catch (SQLException e) { - //e.printStackTrace(); + SQL.getStatement().execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `members` TEXT AFTER `ownedBy`;"); + } catch (SQLException ignored) { + } } diff --git a/src/main/java/me/plytki/virtualrealty/utils/ConfigurationFactory.java b/src/main/java/me/plytki/virtualrealty/utils/ConfigurationFactory.java index 3239cd9..675de8a 100644 --- a/src/main/java/me/plytki/virtualrealty/utils/ConfigurationFactory.java +++ b/src/main/java/me/plytki/virtualrealty/utils/ConfigurationFactory.java @@ -4,6 +4,7 @@ import eu.okaeri.configs.serdes.commons.SerdesCommons; import eu.okaeri.configs.validator.okaeri.OkaeriValidator; import eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer; +import me.plytki.virtualrealty.configs.MessagesConfiguration; import me.plytki.virtualrealty.configs.PluginConfiguration; import me.plytki.virtualrealty.configs.SizesConfiguration; @@ -33,5 +34,13 @@ public SizesConfiguration createSizesConfiguration(File sizesConfigurationFile) }); } + public MessagesConfiguration createMessagesConfiguration(File messagesConfigurationFile) { + return ConfigManager.create(MessagesConfiguration.class, (it) -> { + it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesCommons()); + it.withBindFile(messagesConfigurationFile); + it.saveDefaults(); + it.load(true); + }); + } } diff --git a/src/main/java/me/plytki/virtualrealty/utils/SchematicUtil.java b/src/main/java/me/plytki/virtualrealty/utils/SchematicUtil.java index 4e521fb..b99ba70 100644 --- a/src/main/java/me/plytki/virtualrealty/utils/SchematicUtil.java +++ b/src/main/java/me/plytki/virtualrealty/utils/SchematicUtil.java @@ -72,6 +72,7 @@ public static void paste(int plotID, Location l) { } } } + if (blocks[0].isEmpty()) return; for (String block : blocks) { String[] cords = block.split(";"); int x = Integer.parseInt(cords[0]); @@ -109,6 +110,8 @@ public static void save(int plotID, String[] blocks) { stringBuilder.append(s).append("|"); } String plotString = stringBuilder.toString(); + if (plotString.isEmpty()) + plotString = "clear|"; try { new Data().compressData(plotString.substring(0, plotString.length() - 1).getBytes(StandardCharsets.UTF_8), f); } catch (IOException e) { @@ -127,6 +130,7 @@ public static String[] load(int plotID) { } catch (IOException e) { e.printStackTrace(); } + if (loaded.equalsIgnoreCase("clear")) return new String[]{""}; VirtualRealty.debug("Loaded in: " + (System.currentTimeMillis() - time) + " ms"); return loaded.split("\\|"); } diff --git a/src/main/java/me/plytki/virtualrealty/utils/UUIDUtils.java b/src/main/java/me/plytki/virtualrealty/utils/UUIDUtils.java new file mode 100644 index 0000000..ce40e3c --- /dev/null +++ b/src/main/java/me/plytki/virtualrealty/utils/UUIDUtils.java @@ -0,0 +1,16 @@ +package me.plytki.virtualrealty.utils; + +import java.util.UUID; + +public class UUIDUtils { + + public static boolean isValidUUID(String uuidString) { + try { + UUID.fromString(uuidString); + return true; + } catch (Exception e) { + return false; + } + } + +} diff --git a/src/main/resources/messages_es_ES.yml b/src/main/resources/messages_es_ES.yml new file mode 100644 index 0000000..b941110 --- /dev/null +++ b/src/main/resources/messages_es_ES.yml @@ -0,0 +1,60 @@ +useNaturalNumbersOnly: §c¡Usa sólo números naturales! +noPlotFound: §cNo se ha podido obtener el gráfico con el ID especificado +notYourPlot: §c¡No es tu parcela! +ownershipExpired: §c¡La propiedad de la parcela ha expirado! +teleportedToPlot: §a¡Has sido teletransportado a la parcela! +gamemodeFeatureDisabled: §c¡La función de modo de juego está desactivada! +incorrectGamemode: §c¡Valor de modo de juego incorrecto! +gamemodeDisabled: §cEste modo de juego está desactivado. +cantSwitchGamemode: §c¡No puedes cambiar de modo de juego aquí! +creativeIsEnabled: §c¡El modo creativo ya está habilitado! +creativeIsDisabled: §c¡El modo creativo ya está desactivado! +creativeEnabled: §aEl modo creativo está habilitado. +creativeDisabled: §e¡El modo creativo ha sido desactivado! +notStandingOnPlot: §c¡No estás parado en ninguna parcela! +assignedByConsole: §eConsola +assignedByShopPurchase: §eCompra en tienda +noPlots: §c¡No hay parcelas! +available: §cDisponible +reloadCompleted: §a¡El plugin ha sido recargado! +cantCreateOnExisting: §c¡No se puede crear una nueva parcela en una parcela existente! +cantGetFloorMaterial: §c¡No se ha podido obtener el material del suelo con el nombre especificado! +cantGetBorderMaterial: §c¡No se ha podido obtener el material del borde con el nombre especificado! +cantGetMaterial: §c¡No se ha podido obtener el material con el nombre especificado! +notCollidingCreating: §aNo colisiona. Creando parcela.. +clickToShowDetailedInfo: '§a§o¡Haz click para mostrar información detallada sobre la parcela! §8(§7ID: §f%plot_id%§8)' +sizeNotRecognised: §c¡Tamaño no reconocido! +LWHHardLimit: §c¡El limite máximo L, W y H es de 500! +removedPlot: §a¡Se ha eliminado la parcela con éxito! +specifyUsername: §c¡Especificar nombre de usuario! +playerNotFoundWithUsername: §c¡No se ha podido encontrar al jugador con el nombre de usuario especificado! +invalidDateProvided: §c¡Formato de fecha inválido proporcionado! +assignedTo: §a¡La parcela ha sido asignada a §f%assigned_to%§a! +specifyMaterialName: §c¡Especifique el nombre del material! +specifyExpiryDate: §c¡Especifique la fecha de expiración! +newFloorMaterialSet: §a¡Se ha establecido un nuevo material para el suelo! +newBorderMaterialSet: §a¡Se ha establecido un nuevo material para los bordes! +ownedUntilUpdated: §a¡La propiedad está actualizada hasta este momento! +assignedToBy: §a¡La parcela ha sido asignada a §f%assigned_to% §apor §f%assigned_by%§a! +notAssigned: §cNo asignado +unassigned: §a¡La parcela ha sido desasignada! +minPlotID: §c¡El ID de parcela mínimo es %min_id%! +maxPlotID: §c¡El ID máximo de la parcela es %max_id%! +cmdOnlyPlayers: §c¡Comando sólo para jugadores! +enteredAvailablePlot: §2¡Has entrado en una parcela disponible! +enteredOwnedPlot: §7¡Has entrado en la parcela de §2%owner%§7! +leftAvailablePlot: §c¡Has salido de una parcela disponible! +leftOwnedPlot: §7¡Has salido de la parcela de §2%owner%§7! +cantInteract: §c¡No puedes interactuar aquí! +cantBuildHere: §c¡No puedes construir aquí! +cantRideOnPlot: §c¡No puedes montar entidades en la parcela de alguien más! +creationPlotComponent1: '§a¡Parcela ' +creationPlotComponent2: §8#§7%plot_id% +creationPlotComponent3: ' §aha sido creada! §8(§7%creation_time% ms§8)' +cantAddYourself: §c¡No puedes añadirte tu mismo a la parecela! +cantKickYourself: §cNo puedes salirte de la parcela. +alreadyInMembers: §c¡Este jugador ya es miembro de la parcela! +notInMembers: §c¡Este jugador no es miembro de la parcela! +cantDoAnyDMG: §c¡No puedes hacer daño aquí! +playerKick: §a¡El jugador §7%player% §aha sido expulsado de tu parcela! +playerAdd: §a¡El jugador §7%player% §aha sido añadido a tu parcela! \ No newline at end of file diff --git a/src/main/resources/messages_pl_PL.yml b/src/main/resources/messages_pl_PL.yml new file mode 100644 index 0000000..a5cc46a --- /dev/null +++ b/src/main/resources/messages_pl_PL.yml @@ -0,0 +1,62 @@ +useNaturalNumbersOnly: §cUżywaj tylko liczb naturalnych! +noPlotFound: §cNie można uzyskać działki o podanym ID! +notYourPlot: §cTo nie jest twoja działka! +ownershipExpired: §cTwoje prawo własności wygasło! +teleportedToPlot: §aZostałeś teleportowany na działkę! +gamemodeFeatureDisabled: §cFunkcja zmiany trybu gry jest wyłączona! +incorrectGamemode: §cNieprawidłowa wartość trybu gry! +gamemodeDisabled: §cTen tryb gry jest wyłączony! +cantSwitchGamemode: §cNie możesz tu zmienić trybu! +creativeIsEnabled: §cTryb kreatywny jest już włączony! +creativeIsDisabled: §cTryb kreatywny jest już wyłączony! +creativeEnabled: §aTryb kreatywny został włączony! +creativeDisabled: §eTryb kreatywny został wyłączony! +notStandingOnPlot: §cNie stoisz na żadnej z działek! +assignedByConsole: §eKonsola +assignedByShopPurchase: §eZakup w Sklepie +noPlots: §cNie ma żadnych działek! +available: §cDostępny +reloadCompleted: §aPomyślnie przeładowano! +cantCreateOnExisting: §cNie można utworzyć nowej działki na istniejącej działce! +cantGetFloorMaterial: §cNie udało się znaleźć materiału podłogowego o podanej nazwie! +cantGetBorderMaterial: §cNie udało się znaleźć materiału granicznego o podanej nazwie! +cantGetMaterial: §cNie udało sie znaleźć materiału z podaną nazwą! +notCollidingCreating: §aTworzenie działki... +clickToShowDetailedInfo: '§a§oClick to show detailed information about the plot! §8(§7ID: + §f%plot_id%§8)' +sizeNotRecognised: §cNie rozpoznano rozmiaru! +LWHHardLimit: §cTwardy limit dla L, W i H to 500! +removedPlot: §aPomyślnie usunięto działkę! +specifyUsername: §cPodaj nazwe użytkownika! +playerNotFoundWithUsername: §cCouldn't find player with specified username! +invalidDateProvided: §cPodano nieprawidłowy format daty! +assignedTo: §aDziałka została przypisana do §f%assigned_to%! +specifyMaterialName: §cOkreśl nazwę materiału! +specifyExpiryDate: §cOkreśl datę ważności! +newFloorMaterialSet: §aUstawiono nowy materiał podłogowy! +newBorderMaterialSet: §aUstawiono nowy materiał graniczny! +ownedUntilUpdated: §aData wygaśnięcia własności została zaktualizowana! +assignedToBy: §aDziałka została przypisana do §f%assigned_to% §aprzez §f%assigned_by%! +notAssigned: §cNieprzypisane +unassigned: §aDziałka została zwolniona! +minPlotID: §cMinimalne ID działki to %min_id%! +maxPlotID: §cMaksymalne ID działki to %max_id%! +cmdOnlyPlayers: §cKomenda tylko dla graczy! +enteredAvailablePlot: §2Wszedłeś na wolną działke! +enteredOwnedPlot: §7Wszedłeś na działke gracza §2%owner%! +leftAvailablePlot: §cOpuściłeś wolną działke! +leftOwnedPlot: §7Opuściłeś działke gracza §2%owner%! +cantInteract: §cNie możesz tutaj tego robić! +cantBuildHere: §cNie możesz tutaj budować! +cantBuildThere: §cNie możesz tam budować! +cantRideOnPlot: §cNie możesz jeździć na czyjejś działce! +creationPlotComponent1: '§aDziałka ' +creationPlotComponent2: §8#§7%plot_id% +creationPlotComponent3: ' §azostała stworzona! §8(§7%creation_time% ms§8)' +cantAddYourself: §cNie możesz dodać siebie do działki! +cantKickYourself: §cNie możesz wyrzucić siebie z działki! +alreadyInMembers: §cTen gracz jest już jednym z członków działki! +notInMembers: §cTen gracz nie jest członkiem twojej działki! +cantDoAnyDMG: §cNie możesz tutaj zdawać żadnych obrażeń! +playerKick: §aGracz §7%player% §azostał wyrzucony z działki! +playerAdd: §aGracz §7%player% §azostał dodany do działki! diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6cdb9b0..e933bd3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: me.plytki.virtualrealty.VirtualRealty prefix: Virtual Realty authors: [ plytki ] api-version: 1.13 -description: Virtual Realty Plugin +description: §7A plot creation and management plugin for Minecraft softdepend: [dynmap] commands: virtualrealty: