diff --git a/pom.xml b/pom.xml
index 3c76670..7af17b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.modnmetl
virtualrealty
- 2.4.0
+ 2.5.0
jar
A plot creation and management plugin for Minecraft
diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
index a282938..8b58d2b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
+++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
@@ -6,36 +6,33 @@
import com.modnmetl.virtualrealty.commands.plot.PlotCommand;
import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand;
import com.modnmetl.virtualrealty.configs.*;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.enums.ServerVersion;
-import com.modnmetl.virtualrealty.exceptions.MaterialMatchException;
-import com.modnmetl.virtualrealty.listeners.player.PlayerActionListener;
-import com.modnmetl.virtualrealty.listeners.protection.BorderProtectionListener;
-import com.modnmetl.virtualrealty.listeners.PlotEntranceListener;
-import com.modnmetl.virtualrealty.listeners.protection.PlotProtectionListener;
-import com.modnmetl.virtualrealty.listeners.protection.WorldProtectionListener;
-import com.modnmetl.virtualrealty.listeners.stake.DraftListener;
-import com.modnmetl.virtualrealty.listeners.stake.ConfirmationListener;
-import com.modnmetl.virtualrealty.managers.DynmapManager;
-import com.modnmetl.virtualrealty.managers.MetricsManager;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.managers.PlotMemberManager;
-import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
+import com.modnmetl.virtualrealty.model.other.ServerVersion;
+import com.modnmetl.virtualrealty.exception.MaterialMatchException;
+import com.modnmetl.virtualrealty.listener.player.PlayerActionListener;
+import com.modnmetl.virtualrealty.listener.protection.BorderProtectionListener;
+import com.modnmetl.virtualrealty.listener.PlotEntranceListener;
+import com.modnmetl.virtualrealty.listener.protection.PlotProtectionListener;
+import com.modnmetl.virtualrealty.listener.protection.WorldProtectionListener;
+import com.modnmetl.virtualrealty.listener.stake.DraftListener;
+import com.modnmetl.virtualrealty.listener.stake.ConfirmationListener;
+import com.modnmetl.virtualrealty.manager.DynmapManager;
+import com.modnmetl.virtualrealty.manager.MetricsManager;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
import com.modnmetl.virtualrealty.registry.VirtualPlaceholders;
import com.modnmetl.virtualrealty.sql.Database;
-import com.modnmetl.virtualrealty.utils.Loader;
-import com.modnmetl.virtualrealty.utils.configuration.ConfigurationFactory;
-import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
-import com.modnmetl.virtualrealty.utils.UpdateChecker;
+import com.modnmetl.virtualrealty.util.loader.Loader;
+import com.modnmetl.virtualrealty.util.configuration.ConfigurationFactory;
+import com.modnmetl.virtualrealty.util.multiversion.VMaterial;
+import com.modnmetl.virtualrealty.util.UpdateChecker;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
import lombok.Setter;
-import net.minecraft.server.v1_13_R2.MinecraftServer;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.PluginCommand;
-import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
@@ -59,7 +56,9 @@ public final class VirtualRealty extends JavaPlugin {
@Getter
private static VirtualRealty instance;
@Getter
- public MetricsManager metricsManager;
+ private MetricsManager metricsManager;
+ @Getter
+ private PlotManager plotManager;
@Getter
public ConfigurationFactory configFactory = new ConfigurationFactory();
@@ -80,6 +79,7 @@ public final class VirtualRealty extends JavaPlugin {
private static Object premium;
public static boolean upToDate;
public static String latestVersion;
+ public static boolean developmentBuild;
//FILES
@Getter
@@ -97,8 +97,8 @@ public final class VirtualRealty extends JavaPlugin {
@Override
public void onEnable() {
- classLoader = getClassLoader();
instance = this;
+ classLoader = getClassLoader();
try {
jarFiles.add(new JarFile(getFile()));
} catch (IOException e) {
@@ -111,47 +111,32 @@ public void onEnable() {
plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain");
plotsSchemaFolder.mkdirs();
reloadConfigs();
- this.locale = new Locale(pluginConfiguration.locale.split("_")[0], pluginConfiguration.locale.split("_")[1]);
+ this.locale = new Locale(getPluginConfiguration().locale.split("_")[0], getPluginConfiguration().locale.split("_")[1]);
configureMessages();
- if (ServerVersion.valueOf(pluginConfiguration.initServerVersion) == ServerVersion.LEGACY && currentServerVersion == ServerVersion.MODERN) {
+ if (ServerVersion.valueOf(getPluginConfiguration().initServerVersion) == ServerVersion.LEGACY && currentServerVersion == ServerVersion.MODERN) {
this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « ");
- this.getLogger().severe(" You cannot migrate existing legacy plots (1.8-1.12) to a non-legacy server version (1.13 and higher)");
+ this.getLogger().severe(" You cannot migrate existing legacy plots (<1.13) to a non-legacy server version (1.13 and higher)");
this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « ");
this.getPluginLoader().disablePlugin(this);
return;
}
- if (ServerVersion.valueOf(pluginConfiguration.initServerVersion) == ServerVersion.MODERN && currentServerVersion == ServerVersion.LEGACY) {
+ if (ServerVersion.valueOf(getPluginConfiguration().initServerVersion) == ServerVersion.MODERN && currentServerVersion == ServerVersion.LEGACY) {
this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « ");
- this.getLogger().severe(" You cannot migrate existing non-legacy plots (1.13 and higher) to a legacy server version (1.8-1.12)");
+ this.getLogger().severe(" You cannot migrate existing non-legacy plots (1.13 and higher) to a legacy server version (<1.13)");
this.getLogger().severe(" » ------------------------------------------------------------------------------------------------ « ");
this.getPluginLoader().disablePlugin(this);
return;
}
- String[] updateCheck = UpdateChecker.getUpdate();
- if (updateCheck != null) {
- if (!updateCheck[0].equals(this.getDescription().getVersion())) {
- upToDate = false;
- latestVersion = updateCheck[0];
- this.getLogger().info("A newer version is available!");
- this.getLogger().info("The current version you use: " + this.getDescription().getVersion());
- this.getLogger().info("Latest version available: " + updateCheck[0]);
- this.getLogger().info("Download link: https://www.spigotmc.org/resources/virtual-realty.95599/");
- } else {
- upToDate = true;
- latestVersion = this.getDescription().getVersion();
- this.getLogger().info("Plugin is up to date!");
- }
- }
+ checkUpdates();
if (!pluginConfiguration.license.key.isEmpty() && !pluginConfiguration.license.email.isEmpty()) {
try {
- new Loader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion(), getLoader(), VirtualRealty.getPluginConfiguration().loaderDebugMode);
+ new Loader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion(), getLoader(), pluginConfiguration.loaderDebugMode);
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
e.printStackTrace();
getLogger().log(Level.WARNING, "Load of premium features failed.");
}
}
- metricsManager = new MetricsManager(this, 14066);
- metricsManager.registerMetrics();
+ loadMetrics();
loadSizesConfiguration();
try {
Database.connectToDatabase(databaseFile);
@@ -160,19 +145,12 @@ public void onEnable() {
this.getPluginLoader().disablePlugin(this);
return;
}
- PlotManager.loadPlots();
- PlotMemberManager.loadMembers();
- if (pluginConfiguration.dynmapMarkers) {
- dynmapManager = new DynmapManager(this);
- dynmapManager.registerDynmap();
- }
+ loadPlotsData();
+ loadDynMapHook();
registerCommands();
- configureCommands();
+ loadCommandsConfiguration();
registerListeners();
- if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
- new VirtualPlaceholders(this).register();
- debug("Registered new placeholders");
- }
+ registerPlaceholders();
debug("Server version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion());
}
@@ -189,7 +167,7 @@ public void onDisable() {
gridStructureEntryEntry.getKey().removeGrid();
});
DraftListener.DRAFT_MAP.clear();
- PlotManager.getPlots().forEach(Plot::update);
+ plotManager.getPlots().forEach(Plot::update);
tasks.forEach(BukkitTask::cancel);
try {
DataSource dataSource;
@@ -206,8 +184,93 @@ public void onDisable() {
FileUtils.deleteQuietly(loaderFile);
}
- public static void debug(String message) {
- if (VirtualRealty.getPluginConfiguration().debugMode) VirtualRealty.getInstance().getLogger().warning("DEBUG > " + message);
+ public void registerPlaceholders() {
+ if (!Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) return;
+ new VirtualPlaceholders(this).register();
+ debug("Registered new placeholders");
+ }
+
+ public void checkUpdates() {
+ String[] currentVersionNumbers = this.getDescription().getVersion().split("\\.");
+ String[] updateCheck = UpdateChecker.getUpdate();
+ if (updateCheck != null) {
+ String updateVersion = updateCheck[0];
+ String[] cloudVersionNumbers = updateVersion.split("\\.");
+ int currentMajor = Integer.parseInt(currentVersionNumbers[0]);
+ int currentMinor = Integer.parseInt(currentVersionNumbers[1]);
+ int currentPatch = Integer.parseInt(currentVersionNumbers[2]);
+
+ int updateMajor = Integer.parseInt(cloudVersionNumbers[0]);
+ int updateMinor = Integer.parseInt(cloudVersionNumbers[1]);
+ int updatePatch = Integer.parseInt(cloudVersionNumbers[2]);
+
+ boolean patchUpdate = updatePatch > currentPatch;
+ boolean minorUpdate = updateMinor > currentMinor;
+ boolean majorUpdate = updateMajor > currentMajor;
+
+ boolean majorDevelopment = currentMajor > updateMajor;
+ boolean minorDevelopment = currentMinor > updateMinor;
+
+ if (currentMajor == updateMajor && currentMinor == updateMinor && currentPatch == updatePatch) {
+ upToDate = true;
+ latestVersion = this.getDescription().getVersion();
+ this.getLogger().info("Plugin is up to date!");
+ return;
+ }
+ if (majorUpdate) {
+ registerUpdate(updateVersion, false);
+ } else {
+ if (minorUpdate) {
+ if (majorDevelopment) {
+ registerUpdate(updateVersion, true);
+ return;
+ }
+ registerUpdate(updateVersion, false);
+ } else {
+ if (patchUpdate) {
+ if (majorDevelopment || minorDevelopment) {
+ registerUpdate(updateVersion, true);
+ return;
+ }
+ registerUpdate(updateVersion, false);
+ } else {
+ registerUpdate(updateVersion, true);
+ }
+ }
+ }
+ }
+ }
+
+ private void registerUpdate(String version, boolean development) {
+ upToDate = false;
+ latestVersion = version;
+ if (development) {
+ developmentBuild = true;
+ this.getLogger().warning("You are running a development build!");
+ return;
+ }
+ this.getLogger().info("A newer version is available!");
+ this.getLogger().info("The current version you use: " + this.getDescription().getVersion());
+ this.getLogger().info("Latest version available: " + version);
+ this.getLogger().info("Download link: https://www.spigotmc.org/resources/virtual-realty.95599/");
+ }
+
+ public void loadPlotsData() {
+ plotManager = new PlotManager(this);
+ plotManager.loadPlots();
+ plotManager.loadMembers();
+ }
+
+ public void loadDynMapHook() {
+ if (getPluginConfiguration().dynmapMarkers) {
+ dynmapManager = new DynmapManager(this);
+ dynmapManager.registerDynmap();
+ }
+ }
+
+ public void loadMetrics() {
+ metricsManager = new MetricsManager(this, 14066);
+ metricsManager.registerMetrics();
}
public void configureMessages() {
@@ -216,9 +279,8 @@ public void configureMessages() {
configFactory.loadMessagesConfiguration(messagesConfigurationFile);
}
- public void configureCommands() {
+ public void loadCommandsConfiguration() {
commandsConfiguration = configFactory.loadCommandsConfiguration(commandsConfigurationFile);
- commandsConfiguration.refreshHelpMessages();
commandsConfiguration.assignAliases();
CommandRegistry.setupPlaceholders();
}
@@ -278,7 +340,7 @@ private void registerListeners() {
new ConfirmationListener(this);
try {
List> classes = new ArrayList<>();
- classes.add(Class.forName("com.modnmetl.virtualrealty.listeners.premium.PanelListener", true, getLoader()));
+ classes.add(Class.forName("com.modnmetl.virtualrealty.listener.premium.PanelListener", true, getLoader()));
for (Class> aClass : classes) {
aClass.getConstructors()[0].newInstance(this);
}
@@ -389,4 +451,9 @@ public void setClassLoader(ClassLoader newClassLoader) {
classLoader = newClassLoader;
}
+ public static void debug(String message) {
+ if (!VirtualRealty.getPluginConfiguration().debugMode) return;
+ VirtualRealty.getInstance().getLogger().warning("DEBUG > " + message);
+ }
+
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
index 2a9fba8..929166a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
@@ -3,14 +3,16 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.plot.PlotCommand;
import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.enums.commands.CommandType;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.utils.EnumUtils;
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
+import com.modnmetl.virtualrealty.model.other.CommandType;
+import com.modnmetl.virtualrealty.model.permission.ManagementPermission;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.util.EnumUtils;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.Material;
+import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
@@ -128,7 +130,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman
case "SET": {
if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
if (args.length == 2) {
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
if (args[1].isEmpty()) {
tabCompleter.add(String.valueOf(plot.getID()));
} else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) {
@@ -226,7 +228,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman
case "UNASSIGN": {
if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
if (args.length == 2) {
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
if (args[1].isEmpty()) {
tabCompleter.add(String.valueOf(plot.getID()));
} else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) {
@@ -252,7 +254,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman
case "TP": {
if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
if (args.length == 2) {
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
if (args[1].isEmpty()) {
tabCompleter.add(String.valueOf(plot.getID()));
} else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) {
@@ -369,13 +371,13 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman
@NotNull String[] finalArgs = args;
@NotNull String[] finalArgs1 = args;
switch (args[0].toUpperCase(Locale.ROOT)) {
- case "KICK":
case "ADD": {
if (args.length == 2) {
- PlotManager.getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> {
+ PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> {
+ if (plot.getMember(player.getUniqueId()) != null && !plot.getMember(player.getUniqueId()).hasManagementPermission(ManagementPermission.ADD_MEMBER)) return;
if (finalArgs[1].isEmpty()) {
tabCompleter.add(String.valueOf(plot.getID()));
- } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[0].toLowerCase())) {
+ } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[1].toLowerCase())) {
tabCompleter.add(String.valueOf(plot.getID()));
}
});
@@ -383,26 +385,56 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman
}
if (args.length == 3) {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
+ if (onlinePlayer.getName().equals(player.getName())) continue;
if (args[2].isEmpty()) {
tabCompleter.add(onlinePlayer.getName());
- } else if (onlinePlayer.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
+ } else if (onlinePlayer.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
tabCompleter.add(onlinePlayer.getName());
}
}
return tabCompleter;
}
+ break;
+ }
+ case "KICK": {
+ if (args.length == 2) {
+ PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> {
+ if (plot.getMember(player.getUniqueId()) != null && !plot.getMember(player.getUniqueId()).hasManagementPermission(ManagementPermission.KICK_MEMBER)) return;
+ if (finalArgs[1].isEmpty()) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[1].toLowerCase())) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ }
+ });
+ return tabCompleter;
+ }
+ if (args.length == 3) {
+ Plot plot = PlotManager.getInstance().getPlot(Integer.parseInt(args[1]));
+ if (plot == null) return null;
+ for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) {
+ if (Objects.equals(offlinePlayer.getName(), player.getName())) continue;
+ if (args[2].isEmpty()) {
+ tabCompleter.add(offlinePlayer.getName());
+ } else if (offlinePlayer.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
+ tabCompleter.add(offlinePlayer.getName());
+ }
+ }
+ return tabCompleter;
+ }
+ break;
}
case "TP": {
if (args.length == 2) {
- PlotManager.getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> {
+ PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> {
if (finalArgs1[1].isEmpty()) {
tabCompleter.add(String.valueOf(plot.getID()));
- } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs1[0].toLowerCase())) {
+ } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs1[1].toLowerCase())) {
tabCompleter.add(String.valueOf(plot.getID()));
}
});
return tabCompleter;
}
+ break;
}
}
return tabCompleter;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java
index 184fd10..c222ea1 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java
@@ -1,7 +1,7 @@
package com.modnmetl.virtualrealty.commands;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.commands.CommandType;
+import com.modnmetl.virtualrealty.model.other.CommandType;
import lombok.SneakyThrows;
import java.util.ArrayList;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
index c5493ff..5485ff9 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
@@ -1,10 +1,10 @@
package com.modnmetl.virtualrealty.commands;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.WorldsSetting;
-import com.modnmetl.virtualrealty.enums.commands.CommandType;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException;
+import com.modnmetl.virtualrealty.model.other.CommandType;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.exception.InsufficientPermissionsException;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
@@ -62,7 +62,7 @@ public SubCommand(CommandSender sender, Command command, String label, String[]
public void assertPlayer() throws FailedCommandException {
if (!(commandSender instanceof Player)) {
- commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cmdOnlyPlayers);
+ ChatMessage.of(VirtualRealty.getMessages().cmdOnlyPlayers).sendWithPrefix(commandSender);
throw new FailedCommandException();
}
}
@@ -96,9 +96,9 @@ public String getDefaultPermission() {
public void assertPermission() throws InsufficientPermissionsException {
if (!commandSender.hasPermission(getDefaultPermission())) {
if (commandSender.isOp()) {
- commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", getDefaultPermission()));
+ ChatMessage.of(VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", getDefaultPermission())).sendWithPrefix(commandSender);
} else {
- commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", getDefaultPermission()));
+ ChatMessage.of(VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", getDefaultPermission())).sendWithPrefix(commandSender);
}
throw new InsufficientPermissionsException();
}
@@ -107,34 +107,22 @@ public void assertPermission() throws InsufficientPermissionsException {
public void assertPermission(String permission) throws InsufficientPermissionsException {
if (!commandSender.hasPermission(permission)) {
if (commandSender.isOp()) {
- commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", permission));
+ ChatMessage.of(VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", permission)).sendWithPrefix(commandSender);
} else {
- commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", permission));
+ ChatMessage.of(VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", permission)).sendWithPrefix(commandSender);
}
throw new InsufficientPermissionsException();
}
}
- public boolean canCreateInWorld(Player player) {
- switch (WorldsSetting.valueOf(VirtualRealty.getPluginConfiguration().worldsSetting.toUpperCase())) {
- case ALL:
- break;
- case INCLUDED:
- if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().noneMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false;
- break;
- case EXCLUDED:
- if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().anyMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false;
- }
- return true;
- }
-
public boolean isBypass() {
return this.bypass;
}
public void printHelp() throws FailedCommandException {
for (String s : HELP_LIST) {
- commandSender.sendMessage(s.replaceAll("%command%", getSubCommandName()));
+ String message = s.replaceAll("%command%", getSubCommandName());
+ ChatMessage.of(message).send(commandSender);
}
throw new FailedCommandException();
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
index e20ae96..0bee5db 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
@@ -3,21 +3,19 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.CommandRegistry;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.commands.CommandType;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.model.other.CommandType;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
-import org.bukkit.command.TabExecutor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.logging.Level;
-import static com.modnmetl.virtualrealty.commands.CommandRegistry.PLOT_SUB_COMMAND_LIST;
-
public class PlotCommand implements CommandExecutor {
public static final LinkedList HELP_LIST = new LinkedList<>();
@@ -26,8 +24,6 @@ public class PlotCommand implements CommandExecutor {
HELP_LIST.add(" ");
HELP_LIST.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
HELP_LIST.add(" §a/plot %panel_command% §8- §7Opens your plots panel");
- HELP_LIST.add(" §a/plot %draft_command% §8- §7Shows layout of potential new plot");
- HELP_LIST.add(" §a/plot %stake_command% §8- §7Creates the plot shown with draft");
HELP_LIST.add(" §a/plot %info_command% §8- §7Shows plot info");
HELP_LIST.add(" §a/plot %gm_command% §8- §7Changes gamemode");
HELP_LIST.add(" §a/plot %add_command% §8- §7Adds a member");
@@ -54,10 +50,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
try {
Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getLoader());
} catch (Exception e) {
- sender.sendMessage("§aThis function is available with a valid license key");
+ ChatMessage.of("§aThis function is available with a valid license key").send(sender);
TextComponent linkComponent = new TextComponent("§fhttps://modnmetl.com/");
linkComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://modnmetl.com/category/virtual-realty-plugin-61eef16fe2eeab00116a3e64"));
- sender.spigot().sendMessage(new TextComponent("§aPlease visit "), linkComponent, new TextComponent(" §ato purchase one"));
+ ChatMessage.of(new TextComponent("§aPlease visit "), linkComponent, new TextComponent(" §ato purchase one")).send(sender);
return false;
}
}
@@ -74,8 +70,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
e.printStackTrace();
} else {
if (e.getCause() instanceof FailedCommandException) return false;
- sender.sendMessage("§cAn error occurred while executing the command.");
- sender.sendMessage("§cCheck console for details.");
+ ChatMessage.of("§cAn error occurred while executing the command.").send(sender);
+ ChatMessage.of("§cCheck console for details.").send(sender);
VirtualRealty.getInstance().getLogger().log(Level.SEVERE, "Failed command execution | Command Sender: " + sender.getName());
VirtualRealty.getInstance().getLogger().log(Level.SEVERE, "To print more details add \"--error\" argument at the end of the command.");
}
@@ -85,13 +81,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
private static void printHelp(CommandSender sender) {
for (String message : HELP_LIST) {
- final String[] finalMessage = {message};
+ final String[] finalMessage = { message };
CommandRegistry.PLOT_PLACEHOLDERS.forEach((s, s2) -> {
finalMessage[0] = finalMessage[0].replaceAll(s, s2);
});
- sender.sendMessage(
- finalMessage[0]
- );
+ if (!finalMessage[0].contains("_command%"))
+ sender.sendMessage(
+ finalMessage[0]
+ );
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java
index b4cd4d1..46a9263 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java
@@ -2,12 +2,12 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.PlotMember;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.model.permission.ManagementPermission;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.plot.PlotMember;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@@ -15,7 +15,6 @@
import org.bukkit.entity.Player;
import java.time.LocalDateTime;
-import java.util.Arrays;
import java.util.LinkedList;
public class AddSubCommand extends SubCommand {
@@ -46,49 +45,50 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(player);
return;
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[2]);
if (offlinePlayer.getFirstPlayed() == 0) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(player);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
if (!plot.hasMembershipAccess(player.getUniqueId())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot);
+ ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender);
return;
}
PlotMember plotMember = plot.getMember(player.getUniqueId());
if (plotMember != null) {
if (!plotMember.hasManagementPermission(ManagementPermission.ADD_MEMBER)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender);
return;
}
} else {
- if (plot.getPlotOwner().getUniqueId() != player.getUniqueId()) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ if (!plot.getOwnedBy().equals(player.getUniqueId())) {
+ ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender);
return;
}
}
if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ ChatMessage.of(VirtualRealty.getMessages().ownershipExpired).sendWithPrefix(sender);
return;
}
if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantAddYourself);
+ boolean equals = plot.getOwnedBy().equals(player.getUniqueId());
+ ChatMessage.of(equals ? VirtualRealty.getMessages().cantAddYourself : VirtualRealty.getMessages().alreadyInMembers).sendWithPrefix(sender);
return;
}
if (plot.getMember(offlinePlayer.getUniqueId()) != null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().alreadyInMembers);
+ ChatMessage.of(VirtualRealty.getMessages().alreadyInMembers).sendWithPrefix(sender);
return;
}
plot.addMember(offlinePlayer.getUniqueId());
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerAdd.replaceAll("%player%", offlinePlayer.getName()));
+ ChatMessage.of(VirtualRealty.getMessages().playerAdd.replaceAll("%player%", offlinePlayer.getName())).sendWithPrefix(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java
deleted file mode 100644
index 57d4667..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package com.modnmetl.virtualrealty.commands.plot.subcommand;
-
-import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.ConfirmationType;
-import com.modnmetl.virtualrealty.enums.Direction;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.enums.items.VItem;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.listeners.stake.DraftListener;
-import com.modnmetl.virtualrealty.managers.ConfirmationManager;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.PlotItem;
-import com.modnmetl.virtualrealty.objects.region.Cuboid;
-import com.modnmetl.virtualrealty.objects.region.GridStructure;
-import com.modnmetl.virtualrealty.utils.RegionUtil;
-import de.tr7zw.nbtapi.NBTItem;
-import org.bukkit.Material;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.PlayerInventory;
-
-import java.util.AbstractMap;
-import java.util.LinkedList;
-
-public class DraftSubCommand extends SubCommand {
-
- public DraftSubCommand() {}
-
- public DraftSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
- super(sender, command, label, args, new LinkedList<>());
- }
-
- @Override
- public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
- assertPlayer();
- Player player = ((Player) sender);
- if (DraftListener.DRAFT_MAP.containsKey(player)) {
- player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
- player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
- DraftListener.DRAFT_MAP.get(player).getKey().removeGrid();
- DraftListener.DRAFT_MAP.remove(player);
- ConfirmationManager.removeStakeConfirmations(ConfirmationType.STAKE, player.getUniqueId());
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeDisabled);
- return;
- }
- PlayerInventory inv;
- ItemStack claimItem;
- if (VirtualRealty.legacyVersion) {
- inv = player.getInventory();
- claimItem = player.getItemInHand();
- } else {
- inv = player.getInventory();
- claimItem = inv.getItemInMainHand();
- }
- NBTItem claimNbtItem;
- if (!(claimItem.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD)
- &&
- (claimNbtItem = new NBTItem(claimItem)).getString("vrplot_item") != null && claimNbtItem.getString("vrplot_item").equals("CLAIM"))) {
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notHoldingPlotClaim);
- return;
- }
- PlotItem plotItem = PlotItem.fromItemStack(claimItem);
- Plot plot = PlotManager.getPlot(player.getLocation());
- String replacement = null;
- if (plot == null) {
- if (!canCreateInWorld(player)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation);
- return;
- }
- replacement = VirtualRealty.getMessages().createFeature;
- } else {
- if (plotItem.getPlotSize().equals(plot.getPlotSize())) {
- if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) {
- replacement = VirtualRealty.getMessages().claimFeature;
- } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) {
- replacement = VirtualRealty.getMessages().extendFeature;
- }
- } else {
- if (!canCreateInWorld(player)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation);
- return;
- }
- replacement = VirtualRealty.getMessages().createFeature;
- }
- }
- String finalReplacement = replacement;
- if (plot != null && plotItem.getPlotSize().equals(plot.getPlotSize()) && plot.getPlotSize() != PlotSize.CUSTOM) {
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot);
- GridStructure previewStructure = new GridStructure(((Player) sender), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 0, plot.getCreatedLocation());
- previewStructure.preview(player.getLocation(), true, false);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed);
- PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT);
- DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(previewStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem)));
- inv.remove(claimItem);
- if (VirtualRealty.legacyVersion) {
- player.setItemInHand(draftItem.getItemStack());
- } else {
- inv.setItemInMainHand(draftItem.getItemStack());
- }
- VirtualRealty.getMessages().draftEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§")
- .replaceAll("%feature%", finalReplacement)
- ));
- return;
- }
- PlotSize plotSize = PlotSize.valueOf(claimNbtItem.getString("vrplot_size"));
- Cuboid cuboid = RegionUtil.getRegion(player.getLocation(), Direction.byYaw(player.getLocation().getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth());
- if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision);
- if (!GridStructure.isCuboidGridDisplaying(player, 0)) {
- new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, ((Player) sender).getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true);
- }
- return;
- }
- if (RegionUtil.isCollidingWithBedrock(cuboid)) {
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledBedrock);
- GridStructure.isCuboidGridDisplaying(player, 0);
- if (!GridStructure.isCuboidGridDisplaying(player, 0)) {
- new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, ((Player) sender).getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true);
- }
- return;
- }
- PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT);
- GridStructure draftStructure = new GridStructure(player, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), 0, ((Player) sender).getWorld(), 0, player.getLocation());
- DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(draftStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem)));
- inv.remove(claimItem);
- if (VirtualRealty.legacyVersion) {
- player.setItemInHand(draftItem.getItemStack());
- } else {
- inv.setItemInMainHand(draftItem.getItemStack());
- }
- draftStructure.preview(player.getLocation(), true, false);
- VirtualRealty.getMessages().draftEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§")
- .replaceAll("%feature%", finalReplacement)
- ));
- }
-
-}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java
index 0ffa378..9b515f9 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java
@@ -2,11 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.PlotMember;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.plot.PlotMember;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -64,7 +63,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeDisabled);
return;
}
- Plot plot = PlotManager.getBorderedPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (plot == null) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode);
return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java
index 9762fb0..00d4312 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java
@@ -2,10 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@@ -28,7 +28,7 @@ public InfoSubCommand(CommandSender sender, Command command, String label, Strin
public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
assertPlayer();
Player player = ((Player) sender);
- Plot plot = PlotManager.getPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (plot == null) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot);
return;
@@ -39,21 +39,21 @@ public void exec(CommandSender sender, Command command, String label, String[] a
private void printInfo(CommandSender sender, Plot plot) {
LocalDateTime localDateTime = plot.getOwnedUntilDate();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
- sender.sendMessage(" ");
- sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
- sender.sendMessage(" §7Plot ID §8§l‣ §f" + plot.getID());
- sender.sendMessage(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable"));
+ ChatMessage.of(" ").send(sender);
+ ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").send(sender);
+ ChatMessage.of(" §7Plot ID §8§l‣ §f" + plot.getID()).send(sender);
+ ChatMessage.of(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable")).send(sender);
if (plot.getMembers().size() != 0) {
- sender.sendMessage(" §7Members §8§l↴");
+ ChatMessage.of(" §7Members §8§l↴").send(sender);
for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) {
- sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName());
+ ChatMessage.of(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()).send(sender);
}
}
- sender.sendMessage(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime));
- sender.sendMessage(" §7Size §8§l‣ §f" + plot.getPlotSize());
- sender.sendMessage(" §7Length §8§l‣ §f" + plot.getLength());
- sender.sendMessage(" §7Height §8§l‣ §f" + plot.getHeight());
- sender.sendMessage(" §7Width §8§l‣ §f" + plot.getWidth());
+ ChatMessage.of(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime)).send(sender);
+ ChatMessage.of(" §7Size §8§l‣ §f" + plot.getPlotSize()).send(sender);
+ ChatMessage.of(" §7Length §8§l‣ §f" + plot.getLength()).send(sender);
+ ChatMessage.of(" §7Height §8§l‣ §f" + plot.getHeight()).send(sender);
+ ChatMessage.of(" §7Width §8§l‣ §f" + plot.getWidth()).send(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java
index 2a9fc7b..12e1e2c 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java
@@ -2,12 +2,12 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.PlotMember;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.model.permission.ManagementPermission;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.plot.PlotMember;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@@ -45,50 +45,51 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[2]);
if (offlinePlayer.getName() == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
if (!plot.hasMembershipAccess(player.getUniqueId())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot);
+ ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender);
return;
}
PlotMember plotMember = plot.getMember(player.getUniqueId());
if (plotMember != null) {
if (!plotMember.hasManagementPermission(ManagementPermission.KICK_MEMBER)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender);
return;
}
} else {
- if (plot.getPlotOwner().getUniqueId() != player.getUniqueId()) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ if (!plot.getOwnedBy().equals(player.getUniqueId())) {
+ ChatMessage.of(VirtualRealty.getMessages().noAccess).sendWithPrefix(sender);
return;
}
}
if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ ChatMessage.of(VirtualRealty.getMessages().ownershipExpired).sendWithPrefix(sender);
return;
}
if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickYourself);
+ boolean equals = plot.getOwnedBy().equals(player.getUniqueId());
+ ChatMessage.of(equals ? VirtualRealty.getMessages().cantKickYourself : VirtualRealty.getMessages().cantKickOwner).sendWithPrefix(sender);
return;
}
PlotMember member = plot.getMember(offlinePlayer.getUniqueId());
if (member == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender);
return;
}
plot.removeMember(member);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerKick.replaceAll("%player%", offlinePlayer.getName()));
+ ChatMessage.of(VirtualRealty.getMessages().playerKick.replaceAll("%player%", offlinePlayer.getName())).sendWithPrefix(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java
index 9850083..d4d0611 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java
@@ -2,10 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -30,14 +30,14 @@ public void exec(CommandSender sender, Command command, String label, String[] a
assertPlayer();
Player player = ((Player) sender);
boolean hasPlot = false;
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(player.getUniqueId()) && plot.getOwnedUntilDate().isAfter(LocalDateTime.now())) {
hasPlot = true;
break;
}
}
boolean isMember = false;
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
if (plot.getMember(player.getUniqueId()) != null) {
isMember = true;
break;
@@ -47,13 +47,13 @@ public void exec(CommandSender sender, Command command, String label, String[] a
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlayerPlotsFound);
return;
}
- sender.sendMessage(" ");
- sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
- sender.sendMessage(" ");
+ ChatMessage.of(" ").send(sender);
+ ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").send(sender);
+ ChatMessage.of(" ").send(sender);
if (hasPlot) {
- sender.sendMessage("§7§m ");
- sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |");
- for (Plot plot : PlotManager.getPlots()) {
+ ChatMessage.of("§7§m ").send(sender);
+ ChatMessage.of("§7| §a§l§oID§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |").send(sender);
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) {
LocalDateTime localDateTime = plot.getOwnedUntilDate();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
@@ -68,18 +68,18 @@ public void exec(CommandSender sender, Command command, String label, String[] a
size.append(" ");
}
BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + (isOwned ? " " : "") + dateTimeFormatter.format(localDateTime) + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString());
- sender.sendMessage(textComponent.toLegacyText());
+ ChatMessage.of(textComponent.toLegacyText()).send(sender);
}
}
- sender.sendMessage("§7§m ");
+ ChatMessage.of("§7§m ").send(sender);
}
if (isMember) {
- sender.sendMessage(" ");
- sender.sendMessage("§7 §fMember of §8§l↴");
- sender.sendMessage(" ");
- sender.sendMessage("§7§m ");
- sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |");
- for (Plot plot : PlotManager.getPlots()) {
+ ChatMessage.of(" ").send(sender);
+ ChatMessage.of("§7 §fMember of §8§l↴").send(sender);
+ ChatMessage.of(" ").send(sender);
+ ChatMessage.of("§7§m ").send(sender);
+ ChatMessage.of("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |").send(sender);
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
if (plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId()) && plot.hasMembershipAccess(player.getUniqueId())) {
StringBuilder ownedBy = new StringBuilder();
ownedBy.append((plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : VirtualRealty.getMessages().available));
@@ -92,11 +92,12 @@ public void exec(CommandSender sender, Command command, String label, String[] a
size.append(" ");
}
BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + (isOwned ? " " : "") + ownedBy + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString());
- sender.sendMessage(textComponent.toLegacyText());
+ ChatMessage.of(textComponent.toLegacyText()).send(sender);
}
}
- sender.sendMessage("§7§m ");
+ ChatMessage.of("§7§m ").send(sender);
}
+
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java
index cff3d50..153199b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java
@@ -2,10 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -40,24 +40,24 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
if (!plot.hasMembershipAccess(player.getUniqueId())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot);
+ ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender);
return;
}
if (plot.isOwnershipExpired()) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ ChatMessage.of(VirtualRealty.getMessages().ownershipExpired).sendWithPrefix(sender);
return;
}
plot.teleportPlayer(player);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot);
+ ChatMessage.of(VirtualRealty.getMessages().teleportedToPlot).sendWithPrefix(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
index c8dde22..278f460 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
@@ -2,12 +2,11 @@
import com.modnmetl.virtualrealty.commands.CommandRegistry;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.commands.CommandType;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.model.other.CommandType;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException;
+import com.modnmetl.virtualrealty.exception.InsufficientPermissionsException;
import org.bukkit.command.*;
-import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.jetbrains.annotations.NotNull;
@@ -88,9 +87,10 @@ private static void printHelp(CommandSender sender) {
CommandRegistry.VRPLOT_PLACEHOLDERS.forEach((s, s2) -> {
finalMessage[0] = finalMessage[0].replaceAll(s, s2);
});
- sender.sendMessage(
- finalMessage[0]
- );
+ if (!finalMessage[0].contains("_command%"))
+ sender.sendMessage(
+ finalMessage[0]
+ );
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java
index a44b8c7..ddf3fed 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java
@@ -2,11 +2,11 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.utils.UUIDUtils;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.util.UUIDUtils;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@@ -45,7 +45,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
try {
@@ -55,16 +55,16 @@ public void exec(CommandSender sender, Command command, String label, String[] a
offlinePlayer = Bukkit.getOfflinePlayer(args[2]);
}
if (offlinePlayer.getName() == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender);
return;
}
} catch (NullPointerException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
if (sender instanceof Player) {
@@ -75,7 +75,8 @@ public void exec(CommandSender sender, Command command, String label, String[] a
plot.setAssignedBy("SHOP_PURCHASE");
}
plot.setOwnedBy(offlinePlayer.getUniqueId());
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().assignedToBy.replaceAll("%assigned_to%", offlinePlayer.getName()).replaceAll("%assigned_by%", sender.getName()));
+ String text = VirtualRealty.getMessages().assignedToBy.replaceAll("%assigned_to%", offlinePlayer.getName()).replaceAll("%assigned_by%", sender.getName());
+ ChatMessage.of(text).sendWithPrefix(sender);
plot.update();
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java
index a2135d1..a1aa93c 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java
@@ -2,16 +2,16 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.Direction;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.region.Cuboid;
-import com.modnmetl.virtualrealty.objects.region.GridStructure;
-import com.modnmetl.virtualrealty.utils.RegionUtil;
-import com.modnmetl.virtualrealty.utils.multiversion.Chat;
-import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
+import com.modnmetl.virtualrealty.model.math.Direction;
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.region.Cuboid;
+import com.modnmetl.virtualrealty.model.region.GridStructure;
+import com.modnmetl.virtualrealty.util.RegionUtil;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
+import com.modnmetl.virtualrealty.util.multiversion.VMaterial;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
@@ -59,181 +59,102 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotSize = PlotSize.valueOf(args[1].toUpperCase());
} catch (IllegalArgumentException ignored) {}
- if (plotSize != null) {
- if (plotSize == PlotSize.AREA) {
- int length = plotSize.getLength();
- int height = plotSize.getHeight();
- int width = plotSize.getWidth();
- if (args.length > 2) {
- try {
- length = Integer.parseInt(args[2]);
- height = Integer.parseInt(args[3]);
- width = Integer.parseInt(args[4]);
- } catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
- return;
- }
- }
- if (length < 1 || width < 1 || height < 1) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().graterThenZero);
+ if (plotSize == null) {
+ ChatMessage.of(VirtualRealty.getMessages().sizeNotRecognised).sendWithPrefix(sender);
+ return;
+ }
+ if (plotSize == PlotSize.AREA) {
+ int length = plotSize.getLength();
+ int height = plotSize.getHeight();
+ int width = plotSize.getWidth();
+ if (args.length > 2) {
+ try {
+ length = Integer.parseInt(args[2]);
+ height = Integer.parseInt(args[3]);
+ width = Integer.parseInt(args[4]);
+ } catch (IllegalArgumentException e) {
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
- Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width);
- if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting);
- } else {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
- long timeStart = System.currentTimeMillis();
- Plot plot = PlotManager.createPlot(location, PlotSize.AREA, length, height, width, true);
- long timeEnd = System.currentTimeMillis();
- BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
- BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
- BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
- textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
- textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
- textComponent.addExtra(textComponent2);
- textComponent.addExtra(textComponent3);
- new Chat(textComponent).sendTo(player);
- new BukkitRunnable() {
- @Override
- public void run() {
- new GridStructure(player, plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false);
- }
- }.runTaskLater(VirtualRealty.getInstance(), 20);
- }
- } else {
- Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth());
- if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting);
- } else {
- boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
- Material floorMaterial = null;
- byte floorData = 0;
- Material borderMaterial = null;
- byte borderData = 0;
- if (args.length >= 3 && !natural) {
- try {
- floorMaterial = VMaterial.getMaterial(args[2].split(":")[0].toUpperCase());
- if (floorMaterial == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial);
- return;
- }
- } catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial);
- return;
- }
- if (args[2].split(":").length == 2) {
- floorData = Byte.parseByte(args[2].split(":")[1]);
- }
- }
- if (args.length >= 4) {
- try {
- borderMaterial = VMaterial.getMaterial(args[3].split(":")[0].toUpperCase());
- if (borderMaterial == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial);
- return;
- }
- } catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial);
- return;
- }
- if (args[3].split(":").length == 2) {
- borderData = Byte.parseByte(args[3].split(":")[1]);
- }
- }
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
- long timeStart = System.currentTimeMillis();
- Plot plot = PlotManager.createPlot(location, plotSize, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), natural);
- if (!natural) {
- if (floorMaterial != null) {
- plot.setFloorMaterial(floorMaterial, floorData);
- }
- if (borderMaterial != null) {
- plot.setBorderMaterial(borderMaterial, borderData);
- }
- }
- long timeEnd = System.currentTimeMillis();
- BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
- BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
- BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
- textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
- textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
- textComponent.addExtra(textComponent2);
- textComponent.addExtra(textComponent3);
- new Chat(textComponent).sendTo(player);
- new BukkitRunnable() {
- @Override
- public void run() {
- new GridStructure(player, plot.getPlotSize().getLength(), plot.getPlotSize().getHeight(), plot.getPlotSize().getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false);
- }
- }.runTaskLater(VirtualRealty.getInstance(), 20);
- }
}
+ if (length < 1 || width < 1 || height < 1) {
+ ChatMessage.of(VirtualRealty.getMessages().graterThenZero).sendWithPrefix(sender);
+ return;
+ }
+ Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width);
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
+ ChatMessage.of(VirtualRealty.getMessages().cantCreateOnExisting).sendWithPrefix(sender);
+ return;
+ }
+ ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender);
+ long timeStart = System.currentTimeMillis();
+ Plot plot = PlotManager.getInstance().createArea(location, length, height, width);
+ long timeEnd = System.currentTimeMillis();
+ BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
+ BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
+ BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
+ textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
+ textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
+ textComponent.addExtra(textComponent2);
+ textComponent.addExtra(textComponent3);
+ ChatMessage.of(textComponent).send(player);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ new GridStructure(
+ player,
+ plot.getLength(),
+ plot.getHeight(),
+ plot.getWidth(),
+ plot.getID(),
+ ((Player) sender).getWorld(),
+ GridStructure.DISPLAY_TICKS,
+ plot.getCreatedLocation()
+ ).preview(true, false);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 20);
} else {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().sizeNotRecognised);
- }
- } else {
- int length;
- int height;
- int width;
- try {
- length = Integer.parseInt(args[1]);
- height = Integer.parseInt(args[2]);
- width = Integer.parseInt(args[3]);
- } catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
- return;
- }
- if (length < 1 || width < 1 || height < 1) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().graterThenZero);
- return;
- }
- if (length > 500 || width > 500 || height > 500) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().hardLimit);
- return;
- }
- Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width);
- if (RegionUtil.isCollidingWithAnotherPlot(cuboid) || RegionUtil.isCollidingWithBedrock(cuboid)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting);
- } else {
+ Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth());
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
+ ChatMessage.of(VirtualRealty.getMessages().cantCreateOnExisting).sendWithPrefix(sender);
+ return;
+ }
boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
Material floorMaterial = null;
byte floorData = 0;
- if (args.length >= 5 && !natural) {
+ Material borderMaterial = null;
+ byte borderData = 0;
+ if (args.length >= 3 && !natural) {
try {
- floorMaterial = VMaterial.getMaterial(args[4].split(":")[0].toUpperCase());
+ floorMaterial = VMaterial.getMaterial(args[2].split(":")[0].toUpperCase());
if (floorMaterial == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial);
+ ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender);
return;
}
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial);
+ ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender);
return;
}
- if (args[4].split(":").length == 2) {
- floorData = Byte.parseByte(args[4].split(":")[1]);
- }
+ if (args[2].split(":").length == 2)
+ floorData = Byte.parseByte(args[2].split(":")[1]);
}
- Material borderMaterial = null;
- byte borderData = 0;
- if (args.length >= 6) {
+ if (args.length >= 4) {
try {
- borderMaterial = VMaterial.getMaterial(args[5].split(":")[0].toUpperCase());
+ borderMaterial = VMaterial.getMaterial(args[3].split(":")[0].toUpperCase());
if (borderMaterial == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial);
+ ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender);
return;
}
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial);
+ ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender);
return;
}
- if (args[5].split(":").length == 2) {
- borderData = Byte.parseByte(args[5].split(":")[1]);
- }
+ if (args[3].split(":").length == 2)
+ borderData = Byte.parseByte(args[3].split(":")[1]);
}
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
+ ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender);
long timeStart = System.currentTimeMillis();
- Plot plot = PlotManager.createPlot(location, PlotSize.CUSTOM, length, height, width, natural);
+ Plot plot = PlotManager.getInstance().createPlot(location, plotSize, natural);
if (!natural) {
if (floorMaterial != null) {
plot.setFloorMaterial(floorMaterial, floorData);
@@ -250,16 +171,117 @@ public void run() {
textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
textComponent.addExtra(textComponent2);
textComponent.addExtra(textComponent3);
- new Chat(textComponent).sendTo(player);
+ ChatMessage.of(textComponent).send(player);
new BukkitRunnable() {
@Override
public void run() {
- new GridStructure(player, plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false);
+ new GridStructure(
+ player,
+ plot.getPlotSize().getLength(),
+ plot.getPlotSize().getHeight(),
+ plot.getPlotSize().getWidth(),
+ plot.getID(),
+ ((Player) sender).getWorld(),
+ GridStructure.DISPLAY_TICKS,
+ plot.getCreatedLocation()
+ ).preview(true, false);
}
}.runTaskLater(VirtualRealty.getInstance(), 20);
}
+ } else {
+ int length;
+ int height;
+ int width;
+ try {
+ length = Integer.parseInt(args[1]);
+ height = Integer.parseInt(args[2]);
+ width = Integer.parseInt(args[3]);
+ } catch (IllegalArgumentException e) {
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
+ return;
+ }
+ if (length < 1 || width < 1 || height < 1) {
+ ChatMessage.of(VirtualRealty.getMessages().graterThenZero).sendWithPrefix(sender);
+ return;
+ }
+ if (length > 500 || width > 500 || height > 500) {
+ ChatMessage.of(VirtualRealty.getMessages().hardLimit).sendWithPrefix(sender);
+ return;
+ }
+ Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width);
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid) || RegionUtil.isCollidingWithBedrock(cuboid)) {
+ ChatMessage.of(VirtualRealty.getMessages().cantCreateOnExisting).sendWithPrefix(sender);
+ return;
+ }
+ boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
+ Material floorMaterial = null;
+ byte floorData = 0;
+ if (args.length >= 5 && !natural) {
+ try {
+ floorMaterial = VMaterial.getMaterial(args[4].split(":")[0].toUpperCase());
+ if (floorMaterial == null) {
+ ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender);
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ ChatMessage.of(VirtualRealty.getMessages().cantGetFloorMaterial).sendWithPrefix(sender);
+ return;
+ }
+ if (args[4].split(":").length == 2) {
+ floorData = Byte.parseByte(args[4].split(":")[1]);
+ }
+ }
+ Material borderMaterial = null;
+ byte borderData = 0;
+ if (args.length >= 6) {
+ try {
+ borderMaterial = VMaterial.getMaterial(args[5].split(":")[0].toUpperCase());
+ if (borderMaterial == null) {
+ ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender);
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ ChatMessage.of(VirtualRealty.getMessages().cantGetBorderMaterial).sendWithPrefix(sender);
+ return;
+ }
+ if (args[5].split(":").length == 2) {
+ borderData = Byte.parseByte(args[5].split(":")[1]);
+ }
+ }
+ ChatMessage.of(VirtualRealty.getMessages().notCollidingCreating).sendWithPrefix(sender);
+ long timeStart = System.currentTimeMillis();
+ Plot plot = PlotManager.getInstance().createCustomPlot(location, length, height, width, natural);
+ if (!natural) {
+ if (floorMaterial != null)
+ plot.setFloorMaterial(floorMaterial, floorData);
+ if (borderMaterial != null)
+ plot.setBorderMaterial(borderMaterial, borderData);
+ }
+ long timeEnd = System.currentTimeMillis();
+ BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
+ BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
+ BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
+ textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
+ textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
+ textComponent.addExtra(textComponent2);
+ textComponent.addExtra(textComponent3);
+ ChatMessage.of(textComponent).send(player);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ new GridStructure(
+ player,
+ plot.getLength(),
+ plot.getHeight(),
+ plot.getWidth(),
+ plot.getID(),
+ ((Player) sender).getWorld(),
+ GridStructure.DISPLAY_TICKS,
+ plot.getCreatedLocation()
+ ).preview(true, false);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 20);
}
}
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java
index bd6c847..a35fa4d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java
@@ -4,8 +4,8 @@
import com.google.gson.JsonParser;
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -33,32 +33,32 @@ public void exec(CommandSender sender, Command command, String label, String[] a
assertPermission();
VirtualRealty instance = VirtualRealty.getInstance();
if (System.currentTimeMillis() - LAST_REQUEST < 1500) {
- sender.sendMessage(VirtualRealty.PREFIX + "§cPlease wait " + Math.abs(System.currentTimeMillis() - LAST_REQUEST - 1500) + "ms. §7(Rate limiting)");
+ ChatMessage.of("§cPlease wait " + Math.abs(System.currentTimeMillis() - LAST_REQUEST - 1500) + "ms. §7(Rate limiting)").sendWithPrefix(sender);
return;
}
- sender.sendMessage(" ");
- sender.sendMessage(" §8§l«§8§m §8[§aDebug§8]§m §8§l»");
- sender.sendMessage(" §8┏ §7Operating System: §a" + System.getProperty("os.name") + " §7(" + System.getProperty("os.version") + "-" + System.getProperty("os.arch") + ")");
- sender.sendMessage(" §8┣ §7Java Version: §a" + System.getProperty("java.version"));
- sender.sendMessage(" §8┣ §7Engine: §a" + instance.getServer().getName() + " §7(" + instance.getServer().getBukkitVersion() + ")");
- sender.sendMessage(" §8┣ §7Core count: §a" + Runtime.getRuntime().availableProcessors());
- sender.sendMessage(" §8┣ §7RAM: §a" + format(Runtime.getRuntime().totalMemory()) + "§7/§a" + format(Runtime.getRuntime().maxMemory()) + " §7MB");
+ ChatMessage.of(" ").send(sender);
+ ChatMessage.of(" §8§l«§8§m §8[§aDebug§8]§m §8§l»").send(sender);
+ ChatMessage.of(" §8┏ §7Operating System: §a" + System.getProperty("os.name") + " §7(" + System.getProperty("os.version") + "-" + System.getProperty("os.arch") + ")").send(sender);
+ ChatMessage.of(" §8┣ §7Java Version: §a" + System.getProperty("java.version")).send(sender);
+ ChatMessage.of(" §8┣ §7Engine: §a" + instance.getServer().getName() + " §7(" + instance.getServer().getBukkitVersion() + ")").send(sender);
+ ChatMessage.of(" §8┣ §7Core count: §a" + Runtime.getRuntime().availableProcessors()).send(sender);
+ ChatMessage.of(" §8┣ §7RAM: §a" + format(Runtime.getRuntime().totalMemory()) + "§7/§a" + format(Runtime.getRuntime().maxMemory()) + " §7MB").send(sender);
try {
// API Rate Limit is 45 requests per minute
URL url = new URL("http://ip-api.com/json/?fields=org,isp,country,countryCode");
URLConnection urlConnection = url.openConnection();
JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(urlConnection.getInputStream())).getAsJsonObject();
LAST_REQUEST = System.currentTimeMillis();
- sender.sendMessage(" §8┣ §7Location: §a" + jsonObject.get("country").getAsString() + " §7(" + jsonObject.get("countryCode").getAsString() + ")");
- sender.sendMessage(" §8┣ §7ISP: §a" + jsonObject.get("isp").getAsString());
- sender.sendMessage(" §8┣ §7Host: §a" + jsonObject.get("org").getAsString());
+ ChatMessage.of(" §8┣ §7Location: §a" + jsonObject.get("country").getAsString() + " §7(" + jsonObject.get("countryCode").getAsString() + ")").send(sender);
+ ChatMessage.of(" §8┣ §7ISP: §a" + jsonObject.get("isp").getAsString()).send(sender);
+ ChatMessage.of(" §8┣ §7Host: §a" + jsonObject.get("org").getAsString()).send(sender);
} catch (IOException ignored) {
- sender.sendMessage(" §8┣ §7Couldn't connect to the IP-API");
+ ChatMessage.of(" §8┣ §7Couldn't connect to the IP-API").send(sender);
}
- sender.sendMessage(" §8┣ §7Default GM: §a" + instance.getServer().getDefaultGameMode().name().charAt(0) + instance.getServer().getDefaultGameMode().name().substring(1).toLowerCase());
+ ChatMessage.of(" §8┣ §7Default GM: §a" + instance.getServer().getDefaultGameMode().name().charAt(0) + instance.getServer().getDefaultGameMode().name().substring(1).toLowerCase()).send(sender);
Plugin[] plugins = instance.getServer().getPluginManager().getPlugins();
- sender.sendMessage(" §8┣ §7Version: §a" + VirtualRealty.currentServerVersion.name().substring(0, 1).toUpperCase() + VirtualRealty.currentServerVersion.name().substring(1).toLowerCase());
- sender.sendMessage(" §8┣ §7Plugins (§a" + plugins.length + "§7):");
+ ChatMessage.of(" §8┣ §7Version: §a" + VirtualRealty.currentServerVersion.name().substring(0, 1).toUpperCase() + VirtualRealty.currentServerVersion.name().substring(1).toLowerCase()).send(sender);
+ ChatMessage.of(" §8┣ §7Plugins (§a" + plugins.length + "§7):").send(sender);
int limit = sender instanceof Player ? 2 : 3;
int lastRow = (plugins.length / limit + (plugins.length % limit == 0 ? 0 : 1));
int pluginIndex = 0;
@@ -72,12 +72,11 @@ public void exec(CommandSender sender, Command command, String label, String[] a
Object o = Arrays.stream(plugins).skip((long) row * limit).limit(index + 2).toArray()[index + 1];
if (pluginIndex % limit != (limit == 2 ? 1 : 2))
sb.append(" §8| ");
- } catch (Exception ignored) {
- }
+ } catch (Exception ignored) {}
} else break;
pluginIndex++;
}
- sender.sendMessage(sb.toString());
+ ChatMessage.of(sb.toString()).send(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
index 2ed6a86..0c0bfff 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
@@ -2,10 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@@ -30,9 +30,9 @@ public void exec(CommandSender sender, Command command, String label, String[] a
assertPermission();
if (args.length < 2) {
assertPlayer();
- Plot plot = PlotManager.getPlot(((Player) sender).getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(((Player) sender).getLocation());
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot);
+ ChatMessage.of(VirtualRealty.getMessages().notStandingOnPlot).sendWithPrefix(sender);
return;
}
printInfo(sender, plot);
@@ -42,24 +42,26 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
- if (PlotManager.getPlots().isEmpty()) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots);
+ if (PlotManager.getInstance().getPlots().isEmpty()) {
+ ChatMessage.of(VirtualRealty.getMessages().noPlots).sendWithPrefix(sender);
return;
}
- if (plotID < PlotManager.getPlotMinID()) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getPlotMinID())));
+ if (plotID < PlotManager.getInstance().getPlotMinID()) {
+ String message = VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getInstance().getPlotMinID()));
+ ChatMessage.of(message).sendWithPrefix(sender);
return;
}
- if (plotID > PlotManager.getPlotMaxID()) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getPlotMaxID())));
+ if (plotID > PlotManager.getInstance().getPlotMaxID()) {
+ String message = VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getInstance().getPlotMaxID()));
+ ChatMessage.of(message).sendWithPrefix(sender);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
printInfo(sender, plot);
@@ -85,27 +87,27 @@ private void printInfo(CommandSender sender, Plot plot) {
}
}
}
- sender.sendMessage(" ");
- sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
- sender.sendMessage(" §7Plot ID §8§l‣ §f" + plot.getID());
- sender.sendMessage(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable"));
+ ChatMessage.of(" ").sendWithPrefix(sender);
+ ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").sendWithPrefix(sender);
+ ChatMessage.of(" §7Plot ID §8§l‣ §f" + plot.getID()).sendWithPrefix(sender);
+ ChatMessage.of(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable")).sendWithPrefix(sender);
if (plot.getMembers().size() != 0) {
- sender.sendMessage(" §7Members §8§l↴");
+ ChatMessage.of(" §7Members §8§l↴").send(sender);
for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) {
- sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName());
+ ChatMessage.of(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName()).send(sender);
}
}
- sender.sendMessage(" §7Assigned By §8§l‣ §a" + assignedBy);
- sender.sendMessage(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime));
- sender.sendMessage(" §7Size §8§l‣ §f" + plot.getPlotSize());
- sender.sendMessage(" §7Length §8§l‣ §f" + plot.getLength());
- sender.sendMessage(" §7Height §8§l‣ §f" + plot.getHeight());
- sender.sendMessage(" §7Width §8§l‣ §f" + plot.getWidth());
- sender.sendMessage(" §7Floor Material §8§l‣ §f" + plot.getFloorMaterialName());
- sender.sendMessage(" §7Border Material §8§l‣ §f" + plot.getBorderMaterialName());
- sender.sendMessage(" §7Pos 1 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getBottomLeftCorner().toString());
- sender.sendMessage(" §7Pos 2 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getTopRightCorner().toString());
- sender.sendMessage(" §7Created Direction §8§l‣ §f" + plot.getCreatedDirection().name());
+ ChatMessage.of(" §7Assigned By §8§l‣ §a" + assignedBy).send(sender);
+ ChatMessage.of(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime)).send(sender);
+ ChatMessage.of(" §7Size §8§l‣ §f" + plot.getPlotSize()).send(sender);
+ ChatMessage.of(" §7Length §8§l‣ §f" + plot.getLength()).send(sender);
+ ChatMessage.of(" §7Height §8§l‣ §f" + plot.getHeight()).send(sender);
+ ChatMessage.of(" §7Width §8§l‣ §f" + plot.getWidth()).send(sender);
+ ChatMessage.of(" §7Floor Material §8§l‣ §f" + plot.getFloorMaterialName()).send(sender);
+ ChatMessage.of(" §7Border Material §8§l‣ §f" + plot.getBorderMaterialName()).send(sender);
+ ChatMessage.of(" §7Pos 1 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getBottomLeftCorner().toString()).send(sender);
+ ChatMessage.of(" §7Pos 2 §8( §7X §8| §7Y §8| §7Z §8) §8§l‣ §f" + plot.getTopRightCorner().toString()).send(sender);
+ ChatMessage.of(" §7Created Direction §8§l‣ §f" + plot.getCreatedDirection().name()).send(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java
index 1f1eeab..ebbb550 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java
@@ -2,12 +2,12 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.enums.items.VItem;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.objects.data.PlotItem;
-import com.modnmetl.virtualrealty.utils.EnumUtils;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
+import com.modnmetl.virtualrealty.model.other.VItem;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.model.plot.PlotItem;
+import com.modnmetl.virtualrealty.util.EnumUtils;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
@@ -113,27 +113,27 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
additionalDays = Integer.parseInt(args[7-backwardArgs]);
} catch (NumberFormatException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue);
+ ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender);
return;
}
if (additionalDays < 0) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue);
+ ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender);
return;
}
int itemsAmount;
try {
itemsAmount = Integer.parseInt(args[8-backwardArgs]);
} catch (NumberFormatException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue);
+ ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender);
return;
}
if (itemsAmount < 1) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectValue);
+ ChatMessage.of(VirtualRealty.getMessages().incorrectValue).sendWithPrefix(sender);
return;
}
Player onlinePlayer = Bukkit.getPlayer(args[9-backwardArgs]);
if (onlinePlayer == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ ChatMessage.of(VirtualRealty.getMessages().playerNotFoundWithUsername).sendWithPrefix(sender);
return;
}
for (int i = 0; i < itemsAmount; i++) {
@@ -141,11 +141,11 @@ public void exec(CommandSender sender, Command command, String label, String[] a
ItemStack itemStack = plotItem.getItemStack();
onlinePlayer.getInventory().addItem(itemStack);
if (onlinePlayer.getInventory().contains(itemStack)) {
- sender.sendMessage(VirtualRealty.PREFIX + "§aPlot item has been assigned to " + onlinePlayer.getName() + " by " + (sender.getName()) + "!");
- onlinePlayer.sendMessage(VirtualRealty.PREFIX + "§aYou received a plot item from " + (sender.getName()) + "!");
+ ChatMessage.of("§aPlot item has been assigned to " + onlinePlayer.getName() + " by " + (sender.getName()) + "!").sendWithPrefix(sender);
+ ChatMessage.of("§aYou received a plot item from " + (sender.getName()) + "!").sendWithPrefix(onlinePlayer);
} else {
- sender.sendMessage(VirtualRealty.PREFIX + "§c" + onlinePlayer.getName() + " has no inventory space to receive plot item!");
- onlinePlayer.sendMessage(VirtualRealty.PREFIX + "§cNo inventory space to receive plot item from " + (sender.getName()) + "!");
+ ChatMessage.of("§c" + onlinePlayer.getName() + " has no inventory space to receive plot item!").sendWithPrefix(sender);
+ ChatMessage.of("§cNo inventory space to receive plot item from " + (sender.getName()) + "!").sendWithPrefix(onlinePlayer);
}
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java
index 55cece8..cbbe7c7 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java
@@ -2,11 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.utils.multiversion.Chat;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
@@ -30,20 +29,20 @@ public ListSubCommand(CommandSender sender, Command command, String label, Strin
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
assertPermission();
- if (PlotManager.getPlots().isEmpty()) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots);
+ if (PlotManager.getInstance().getPlots().isEmpty()) {
+ ChatMessage.of(VirtualRealty.getMessages().noPlots).sendWithPrefix(sender);
return;
}
- sender.sendMessage(" ");
- sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
- sender.sendMessage(" ");
- sender.sendMessage("§7§m ");
- sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |");
- for (Plot plot : PlotManager.getPlots()) {
+ ChatMessage.of(" ").send(sender);
+ ChatMessage.of(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»").send(sender);
+ ChatMessage.of(" ").send(sender);
+ ChatMessage.of("§7§m ").send(sender);
+ ChatMessage.of("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oOwned Until§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |").send(sender);
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
LocalDateTime localDateTime = plot.getOwnedUntilDate();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
StringBuilder ownedBy = new StringBuilder();
- ownedBy.append((plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : VirtualRealty.getMessages().available));
+ ownedBy.append((plot.getOwnedBy() != null ? ((Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName()) : VirtualRealty.getMessages().available));
boolean isOwned = !ownedBy.toString().equals(VirtualRealty.getMessages().available);
for (int i = ownedBy.length(); i < 16; i++) {
ownedBy.append(" ");
@@ -55,9 +54,9 @@ public void exec(CommandSender sender, Command command, String label, String[] a
BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + ownedBy.substring(0, 14) + "§8 §f" + (isOwned ? " " : "") + dateTimeFormatter.format(localDateTime) + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString());
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
- new Chat(textComponent).sendTo(sender);
+ ChatMessage.of(textComponent).send(sender);
}
- sender.sendMessage("§7§m ");
+ ChatMessage.of("§7§m ").send(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java
index 85111a9..0cfa47b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java
@@ -2,11 +2,11 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.DynmapManager;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.DynmapManager;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -31,7 +31,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
VirtualRealty.getDynmapManager().markerset.deleteMarkerSet();
}
VirtualRealty.getDynmapManager().registerDynmap();
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
DynmapManager.resetPlotMarker(plot);
}
} else {
@@ -40,12 +40,12 @@ public void exec(CommandSender sender, Command command, String label, String[] a
}
}
}
- PlotManager.loadPlots();
+ PlotManager.getInstance().loadPlots();
VirtualRealty.getInstance().loadSizesConfiguration();
} catch (Exception exception) {
exception.printStackTrace();
}
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().reloadComplete);
+ ChatMessage.of(VirtualRealty.getMessages().reloadComplete).sendWithPrefix(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java
index e4a5336..80e7338 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java
@@ -2,13 +2,13 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.ConfirmationType;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.ConfirmationManager;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.Confirmation;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.model.other.ConfirmationType;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.ConfirmationManager;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.Confirmation;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -46,47 +46,42 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
- if (sender instanceof Player) {
- if (this.isBypass()) {
- plot.remove(sender);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot);
- } else {
- for (String s : VirtualRealty.getMessages().removeConfirmation) {
- sender.sendMessage(VirtualRealty.PREFIX + s.replaceAll("%plot_id%", String.valueOf(plot.getID())));
- }
- Confirmation confirmation = new Confirmation(ConfirmationType.REMOVE, (Player) sender, plot.getID(), "YES") {
- @Override
- public void success() {
- plot.remove(((Player) sender).getKiller());
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot);
- ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType());
- }
+ if (this.isBypass() || !(sender instanceof Player)) {
+ plot.remove(sender);
+ ChatMessage.of(VirtualRealty.getMessages().removedPlot).sendWithPrefix(sender);
+ return;
+ }
+ for (String s : VirtualRealty.getMessages().removeConfirmation) {
+ ChatMessage.of(s.replaceAll("%plot_id%", String.valueOf(plot.getID()))).sendWithPrefix(sender);
+ }
+ Confirmation confirmation = new Confirmation(ConfirmationType.REMOVE, (Player) sender, plot.getID(), "YES") {
+ @Override
+ public void success() {
+ plot.remove(((Player) sender).getKiller());
+ ChatMessage.of(VirtualRealty.getMessages().removedPlot).sendWithPrefix(sender);
+ ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType());
+ }
- @Override
- public void failed() {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removalCancelled);
- ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType());
- }
+ @Override
+ public void failed() {
+ ChatMessage.of(VirtualRealty.getMessages().removalCancelled).sendWithPrefix(sender);
+ ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType());
+ }
- @Override
- public void expiry() {
- ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType());
- }
- };
- ConfirmationManager.confirmations.add(confirmation);
+ @Override
+ public void expiry() {
+ ConfirmationManager.removeConfirmations(plot.getID(), this.getConfirmationType());
}
- } else {
- plot.remove(sender);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot);
- }
+ };
+ ConfirmationManager.addConfirmation(confirmation);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java
index eae1663..83e2878 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java
@@ -2,12 +2,11 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.utils.UUIDUtils;
-import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.util.UUIDUtils;
+import com.modnmetl.virtualrealty.util.multiversion.VMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
@@ -75,7 +74,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
return;
@@ -137,7 +136,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
return;
@@ -175,7 +174,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
return;
@@ -224,7 +223,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().invalidDateProvided);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java
index 9aa0b72..a1dd7f8 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java
@@ -2,10 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -41,16 +41,15 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
plot.teleportPlayer(player);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot);
- }
+ ChatMessage.of(VirtualRealty.getMessages().teleportedToPlot).sendWithPrefix(sender);}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java
index f484c45..15492eb 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java
@@ -2,10 +2,10 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -38,17 +38,17 @@ public void exec(CommandSender sender, Command command, String label, String[] a
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
plot.setAssignedBy(null);
plot.setOwnedBy(null);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().unassigned);
+ ChatMessage.of(VirtualRealty.getMessages().unassigned).sendWithPrefix(sender);
plot.update();
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java
index 693f7f5..ace1fe9 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java
@@ -2,8 +2,8 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
@@ -28,7 +28,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick here to download new version!")}));
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/"));
}
- sender.spigot().sendMessage(new TextComponent(VirtualRealty.PREFIX + "Version: §a" + VirtualRealty.getInstance().getDescription().getVersion()), textComponent);
+ ChatMessage.of(new TextComponent("Version: §a" + VirtualRealty.getInstance().getDescription().getVersion()), textComponent).sendWithPrefix(sender);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java
index e7ff5fd..ee64607 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java
@@ -2,11 +2,11 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.region.GridStructure;
-import lombok.NoArgsConstructor;
+import com.modnmetl.virtualrealty.exception.FailedCommandException;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.region.GridStructure;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -26,7 +26,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a
assertPlayer();
assertPermission();
Player player = ((Player) sender);
- Plot plot = PlotManager.getPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (plot == null) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot);
return;
@@ -35,9 +35,18 @@ public void exec(CommandSender sender, Command command, String label, String[] a
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryActive);
return;
}
- GridStructure previewStructure = new GridStructure(((Player) sender), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation());
+ GridStructure previewStructure = new GridStructure(
+ ((Player) sender),
+ plot.getLength(),
+ plot.getHeight(),
+ plot.getWidth(),
+ plot.getID(),
+ ((Player) sender).getWorld(),
+ GridStructure.DISPLAY_TICKS,
+ plot.getCreatedLocation()
+ );
previewStructure.preview(player.getLocation(), true, false);
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed);
+ ChatMessage.of(VirtualRealty.getMessages().visualBoundaryDisplayed).sendWithPrefix(sender);
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java
index 67e7fe8..a999411 100644
--- a/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java
@@ -5,9 +5,10 @@
import com.modnmetl.virtualrealty.commands.SubCommand;
import com.modnmetl.virtualrealty.commands.plot.PlotCommand;
import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand;
-import com.modnmetl.virtualrealty.enums.commands.CommandType;
+import com.modnmetl.virtualrealty.model.other.CommandType;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.*;
+import lombok.SneakyThrows;
import java.lang.reflect.Field;
import java.util.*;
@@ -20,24 +21,45 @@
@Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE)
public class CommandsConfiguration extends OkaeriConfig {
- public LinkedHashMap plotAliases = getPlotAliasesHashMap();
- public LinkedHashMap vrplotAliases = getVRPlotAliasesHashMap();
+ public PlotAliases plotAliases = new PlotAliases();
+ public Map vrplotAliases = getVRPlotAliasesHashMap();
- public LinkedHashMap> plotCommandsHelp = getCommandsHelp(CommandType.PLOT);
- public LinkedHashMap> vrplotCommandsHelp = getCommandsHelp(CommandType.VRPLOT);
+ public Map> plotCommandsHelp = getCommandsHelp(CommandType.PLOT);
+ public Map> vrplotCommandsHelp = getCommandsHelp(CommandType.VRPLOT);
- public static LinkedHashMap getVRPlotAliasesHashMap() {
- LinkedHashMap aliasesHashMap = new LinkedHashMap<>();
- for (String s : CommandManager.SUBCOMMANDS.get(VirtualRealtyCommand.class)) {
- if (s == null || s.isEmpty()) continue;
- aliasesHashMap.put(s, s);
+
+
+ @Names(strategy = NameStrategy.HYPHEN_CASE)
+ public static class PlotAliases extends OkaeriConfig {
+
+ public String panel = "panel";
+ public String add = "add";
+ public String gm = "gm";
+ public String info = "info";
+ public String kick = "kick";
+ public String list = "list";
+ public String tp = "tp";
+
+ public PlotAliases() {
+ super.setRemoveOrphans(true);
}
- return aliasesHashMap;
+
+ @SneakyThrows
+ public Map getAliasesMap() {
+ Map aliasesMap = new HashMap<>();
+ for (Field field : this.getClass().getDeclaredFields()) {
+ String name = field.getName();
+ String alias = (String) field.get(this);
+ aliasesMap.put(name, alias);
+ }
+ return aliasesMap;
+ }
+
}
- public static LinkedHashMap getPlotAliasesHashMap() {
+ public static LinkedHashMap getVRPlotAliasesHashMap() {
LinkedHashMap aliasesHashMap = new LinkedHashMap<>();
- for (String s : CommandManager.SUBCOMMANDS.get(PlotCommand.class)) {
+ for (String s : CommandManager.SUBCOMMANDS.get(VirtualRealtyCommand.class)) {
if (s == null || s.isEmpty()) continue;
aliasesHashMap.put(s, s);
}
@@ -126,7 +148,7 @@ public void assignAliases() {
Optional any = CommandRegistry.VRPLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> subCommand.getSubCommandClassName().equalsIgnoreCase(original)).findAny();
any.ifPresent(subCommand -> subCommand.setAlias(alias));
});
- plotAliases.forEach((original, alias) -> {
+ plotAliases.getAliasesMap().forEach((original, alias) -> {
Optional any = CommandRegistry.PLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> subCommand.getSubCommandClassName().equalsIgnoreCase(original)).findAny();
any.ifPresent(subCommand -> subCommand.setAlias(alias));
});
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
index cc2f741..32de2f7 100644
--- a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
@@ -79,6 +79,7 @@ public class MessagesConfiguration extends OkaeriConfig {
public String unassigned = "§aPlot has been unassigned!";
public String cantAddYourself = "§cYou can't add yourself to the plot!";
public String cantKickYourself = "§cYou can't kick yourself from the plot!";
+ public String cantKickOwner = "§cYou can't kick the owner!";
public String alreadyInMembers = "§cThis player is already one of the plot members!";
public String standingOnPlot = "§cYou are standing on a plot!";
public String notStandingOnPlot = "§cYou aren't standing on any plot!";
@@ -96,20 +97,19 @@ public class MessagesConfiguration extends OkaeriConfig {
public String enteredProtectedArea = "§6You have entered a protected area!";
public String leftProtectedArea = "§6You have left a protected area!";
- //Draft
+ //Claim Mode
public String notHoldingPlotClaim = "§cYou currently don't hold any plot claim item in your hand.";
- public String cantPlaceDraftItems = "§cYou can't place draft items.";
- public String noDraftClaimEnabled = "§cYou don't have plot draft claim enabled.";
- public String draftModeDisabled = "§aDraft mode successfully disabled!";
- public String draftModeCancelledBedrock = "§cDraft cancelled. Colliding with bedrock.";
- public String draftModeCancelledCollision = "§cDraft cancelled. Colliding with another plot.";
- public String draftModeDisabledDueToDeath = "§cDraft mode has been disabled due to death.";
- public List draftEnabled = Arrays.asList(
+ public String cantPlaceClaimItems = "§cYou can't place claim items.";
+ public String claimModeDisabled = "§aClaim mode successfully disabled!";
+ public String claimModeCancelledBedrock = "§cClaim cancelled. Colliding with bedrock.";
+ public String claimModeCancelledCollision = "§cClaim cancelled. Colliding with another plot.";
+ public String claimModeDisabledDueToDeath = "§cClaim mode has been disabled due to death.";
+ public List claimEnabled = Arrays.asList(
" ",
- " §8§l«§8§m §8[§aDraft Mode§8]§m §8§l»",
+ " §8§l«§8§m §8[§aClaim Mode§8]§m §8§l»",
" ",
- " §8§l» §7Type §a/plot stake §7to %feature%.",
- " §8§l» §7If you want to leave draft mode type §a/plot draft",
+ " §8§l» §aLeft-Click §7to %feature%.",
+ " §8§l» §7If you want to leave claim mode §cRight-Click.",
" "
);
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java
index 58edb82..f3f6e9d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java
@@ -1,11 +1,9 @@
package com.modnmetl.virtualrealty.configs;
-import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
+import com.modnmetl.virtualrealty.model.permission.RegionPermission;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.*;
-import javax.swing.plaf.synth.Region;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java
index 0b95a6d..effab4a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java
@@ -1,15 +1,14 @@
package com.modnmetl.virtualrealty.configs;
-import com.modnmetl.virtualrealty.enums.WorldsSetting;
-import com.modnmetl.virtualrealty.enums.dynmap.HighlightType;
-import com.modnmetl.virtualrealty.enums.ServerVersion;
+import com.modnmetl.virtualrealty.model.other.HighlightType;
+import com.modnmetl.virtualrealty.model.other.WorldSetting;
+import com.modnmetl.virtualrealty.model.other.ServerVersion;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.*;
import com.modnmetl.virtualrealty.VirtualRealty;
import lombok.NoArgsConstructor;
import org.bukkit.GameMode;
-import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
@@ -22,14 +21,14 @@
@Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE)
public class PluginConfiguration extends OkaeriConfig {
- @Comment("Changing this value will break your plugin!")
+ @Comment("Changing this value might break your plugin!")
@CustomKey("initial-version")
public String initServerVersion = VirtualRealty.legacyVersion ? ServerVersion.LEGACY.toString() : ServerVersion.MODERN.toString();
- @Comment("Debug mode")
+ @Comment("Debug mode (Displays more detailed info about plugin executions)")
public boolean debugMode = false;
- @Comment("Loader debug mode (only for devs)")
+ @Comment("Local loader mode (for devs)")
public boolean loaderDebugMode = false;
@Comment("Here you put your license details")
@@ -47,6 +46,9 @@ public static class License extends OkaeriConfig {
public boolean enablePlotGamemode = false;
@Comment("Set your wanted language (locale)")
+ @Comment("You can create your own configuration for your language")
+ @Comment("To do so: go into the `messages` folder and create new file called `messages_%locale%.yml`")
+ @Comment("Replace `%locale%` with your locale (It doesn't matter if it conforms to the standard, it should just match the locale here in `config.yml`)")
public String locale = "en_GB";
@Comment("Set which gamemode players change to when they enter their plot")
@@ -63,7 +65,7 @@ public static class License extends OkaeriConfig {
@Comment("ALL - all worlds are capable of creating plots with plot claim items and 'worlds-list' setting is skipped")
@Comment("INCLUDED - only worlds included in 'worlds-list' setting are capable of creating plots with plot claim items")
@Comment("EXCLUDED - all worlds mentioned in 'worlds-list' setting won't be capable of creating plots with plot claim items")
- public String worldsSetting = WorldsSetting.ALL.name();
+ public String worldsSetting = WorldSetting.ALL.name();
@Comment("List of worlds")
public List worldsList = Arrays.asList("%world%", "%world%_nether", "%world%_the_end");
@@ -88,7 +90,8 @@ public GameMode getDefaultPlotGamemode() {
try {
return GameMode.valueOf(plotGamemode);
} catch (Exception e) {
- VirtualRealty.getInstance().getLogger().warning("Couldn't parse plot-gamemode from config.yml\nUsing default: SURVIVAL");
+ VirtualRealty.getInstance().getLogger().warning("Couldn't parse plot-gamemode from config.yml");
+ VirtualRealty.getInstance().getLogger().warning("Using default: SURVIVAL");
return GameMode.SURVIVAL;
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java
index 1df10df..b7189ce 100644
--- a/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java
@@ -2,8 +2,7 @@
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.*;
-import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.PlotSize;
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
import lombok.NoArgsConstructor;
@Header("--------------------------------------------------------------#")
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/migration/C0001_Remove_Old_Plot_Sub_Commands.java b/src/main/java/com/modnmetl/virtualrealty/configs/migration/C0001_Remove_Old_Plot_Sub_Commands.java
new file mode 100644
index 0000000..3b0ccf1
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/migration/C0001_Remove_Old_Plot_Sub_Commands.java
@@ -0,0 +1,16 @@
+package com.modnmetl.virtualrealty.configs.migration;
+
+import eu.okaeri.configs.migrate.builtin.NamedMigration;
+
+import static eu.okaeri.configs.migrate.ConfigMigrationDsl.delete;
+
+public class C0001_Remove_Old_Plot_Sub_Commands extends NamedMigration {
+
+ public C0001_Remove_Old_Plot_Sub_Commands() {
+ super(
+ "Removing unused subcommands for plot command",
+ delete("plot-aliases.stake"),
+ delete("plot-aliases.draft")
+ );
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/WorldsSetting.java b/src/main/java/com/modnmetl/virtualrealty/enums/WorldsSetting.java
deleted file mode 100644
index 076f39a..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/enums/WorldsSetting.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.modnmetl.virtualrealty.enums;
-
-public enum WorldsSetting {
-
- ALL,
- INCLUDED,
- EXCLUDED,
-
-
-}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java b/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java
deleted file mode 100644
index 31ca896..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.modnmetl.virtualrealty.enums.dynmap;
-
-public enum HighlightType {
-
- ALL,
- AVAILABLE,
- OWNED
-
-}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java b/src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java
deleted file mode 100644
index 5b8a7c9..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.modnmetl.virtualrealty.enums.items;
-
-public enum VItem {
-
- CLAIM,
- DRAFT
-
-}
diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java b/src/main/java/com/modnmetl/virtualrealty/exception/FailedCommandException.java
similarity index 72%
rename from src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java
rename to src/main/java/com/modnmetl/virtualrealty/exception/FailedCommandException.java
index b221512..9300648 100644
--- a/src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java
+++ b/src/main/java/com/modnmetl/virtualrealty/exception/FailedCommandException.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.exceptions;
+package com.modnmetl.virtualrealty.exception;
public class FailedCommandException extends Exception {
diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java b/src/main/java/com/modnmetl/virtualrealty/exception/InsufficientPermissionsException.java
similarity index 75%
rename from src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java
rename to src/main/java/com/modnmetl/virtualrealty/exception/InsufficientPermissionsException.java
index b56fdac..1c35e04 100644
--- a/src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java
+++ b/src/main/java/com/modnmetl/virtualrealty/exception/InsufficientPermissionsException.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.exceptions;
+package com.modnmetl.virtualrealty.exception;
public class InsufficientPermissionsException extends Exception {
diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java b/src/main/java/com/modnmetl/virtualrealty/exception/MaterialMatchException.java
similarity index 75%
rename from src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java
rename to src/main/java/com/modnmetl/virtualrealty/exception/MaterialMatchException.java
index a95b1cb..135d0b7 100644
--- a/src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java
+++ b/src/main/java/com/modnmetl/virtualrealty/exception/MaterialMatchException.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.exceptions;
+package com.modnmetl.virtualrealty.exception;
public class MaterialMatchException extends Exception {
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/PlotEntranceListener.java
similarity index 94%
rename from src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/PlotEntranceListener.java
index e9a129d..512360a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/PlotEntranceListener.java
@@ -1,10 +1,10 @@
-package com.modnmetl.virtualrealty.listeners;
+package com.modnmetl.virtualrealty.listener;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
+import com.modnmetl.virtualrealty.manager.PlotManager;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.PlotMember;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.plot.PlotMember;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -34,7 +34,7 @@ public void onPlotMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
Location to = e.getTo();
if (to == null) return;
- Plot plot = PlotManager.getPlot(to);
+ Plot plot = PlotManager.getInstance().getPlot(to, true);
if (plot != null) {
OfflinePlayer offlinePlayer;
String enterPlotString = VirtualRealty.getMessages().enteredAvailablePlot;
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/VirtualListener.java
similarity index 90%
rename from src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/VirtualListener.java
index 8a90af1..44a900f 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/VirtualListener.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.listeners;
+package com.modnmetl.virtualrealty.listener;
import com.modnmetl.virtualrealty.VirtualRealty;
import org.bukkit.event.Listener;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/listener/player/PlayerActionListener.java
similarity index 50%
rename from src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/player/PlayerActionListener.java
index 6aebde8..6662a5d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/player/PlayerActionListener.java
@@ -1,21 +1,22 @@
-package com.modnmetl.virtualrealty.commands.plot.subcommand;
+package com.modnmetl.virtualrealty.listener.player;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.commands.SubCommand;
-import com.modnmetl.virtualrealty.enums.ConfirmationType;
-import com.modnmetl.virtualrealty.enums.Direction;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
-import com.modnmetl.virtualrealty.listeners.stake.DraftListener;
-import com.modnmetl.virtualrealty.managers.ConfirmationManager;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.Confirmation;
-import com.modnmetl.virtualrealty.objects.data.PlotItem;
-import com.modnmetl.virtualrealty.objects.region.Cuboid;
-import com.modnmetl.virtualrealty.objects.region.GridStructure;
-import com.modnmetl.virtualrealty.utils.RegionUtil;
-import com.modnmetl.virtualrealty.utils.multiversion.Chat;
+import com.modnmetl.virtualrealty.model.other.ConfirmationType;
+import com.modnmetl.virtualrealty.model.math.Direction;
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
+import com.modnmetl.virtualrealty.model.other.WorldSetting;
+import com.modnmetl.virtualrealty.model.other.VItem;
+import com.modnmetl.virtualrealty.listener.VirtualListener;
+import com.modnmetl.virtualrealty.listener.stake.DraftListener;
+import com.modnmetl.virtualrealty.manager.ConfirmationManager;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.other.Confirmation;
+import com.modnmetl.virtualrealty.model.plot.PlotItem;
+import com.modnmetl.virtualrealty.model.region.Cuboid;
+import com.modnmetl.virtualrealty.model.region.GridStructure;
+import com.modnmetl.virtualrealty.util.RegionUtil;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import de.tr7zw.nbtapi.NBTItem;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
@@ -23,42 +24,69 @@
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.PlayerInventory;
import org.bukkit.scheduler.BukkitRunnable;
import java.time.LocalDateTime;
-import java.util.*;
+import java.util.AbstractMap;
-public class StakeSubCommand extends SubCommand {
+public class PlayerActionListener extends VirtualListener {
- public StakeSubCommand() {}
+ public PlayerActionListener(VirtualRealty plugin) {
+ super(plugin);
+ }
- public StakeSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
- super(sender, command, label, args, new LinkedList<>());
+ @EventHandler
+ public void onPlayerJoin(PlayerJoinEvent e) {
+ Player player = e.getPlayer();
+ if (!player.isOp()) return;
+ if (VirtualRealty.upToDate) return;
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (VirtualRealty.developmentBuild) {
+ player.sendMessage(VirtualRealty.PREFIX + "§6You are running a development build of VirtualRealty plugin. §7[" + VirtualRealty.getInstance().getDescription().getVersion() + "]");
+ } else {
+ player.sendMessage(VirtualRealty.PREFIX + "§7A new version of VirtualRealty plugin is available. §a[" + VirtualRealty.latestVersion + "]");
+ TextComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aDownload the new version of the plugin here!");
+ textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick here to download the update!")}));
+ textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/"));
+ player.spigot().sendMessage(textComponent);
+ }
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 5);
}
- @Override
- public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
- assertPlayer();
- Player player = ((Player) sender);
- if (!DraftListener.DRAFT_MAP.containsKey(player)) {
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noDraftClaimEnabled);
- return;
- }
+
+ @EventHandler
+ public void onPlotItemStake(PlayerInteractEvent e) {
+ Player player = e.getPlayer();
+ if (e.getHand() == EquipmentSlot.OFF_HAND) return;
+ if (!(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) return;
+ if (!DraftListener.DRAFT_MAP.containsKey(player)) return;
+ e.setCancelled(true);
GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey();
PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey();
Cuboid cuboid = RegionUtil.getRegion(gridStructure.getPreviewLocation(), Direction.byYaw(gridStructure.getPreviewLocation().getYaw()), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth());
- Plot plot = PlotManager.getPlot(gridStructure.getPreviewLocation());
+ Plot plot = PlotManager.getInstance().getPlot(gridStructure.getPreviewLocation());
if (plot != null) {
if (plotItem.getPlotSize().equals(plot.getPlotSize())) {
if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) {
+ if (ConfirmationManager.doesConfirmationExist(ConfirmationType.CLAIM, player.getUniqueId())) {
+ player.sendMessage(VirtualRealty.PREFIX + "§cYou already have a confirmation to confirm!");
+ return;
+ }
for (String s : VirtualRealty.getMessages().claimConfirmation) {
player.sendMessage(VirtualRealty.PREFIX + s);
}
- Confirmation confirmation = new Confirmation(ConfirmationType.CLAIM, (Player) sender, "YES") {
+ Confirmation confirmation = new Confirmation(ConfirmationType.CLAIM, player, "YES") {
@Override
public void success() {
ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack();
@@ -89,13 +117,17 @@ public void expiry() {
ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId());
}
};
- ConfirmationManager.confirmations.add(confirmation);
+ ConfirmationManager.addConfirmation(confirmation);
return;
} else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) {
+ if (ConfirmationManager.doesConfirmationExist(ConfirmationType.EXTEND, player.getUniqueId())) {
+ player.sendMessage(VirtualRealty.PREFIX + "§cYou already have a confirmation to confirm!");
+ return;
+ }
for (String s : VirtualRealty.getMessages().extendConfirmation) {
player.sendMessage(VirtualRealty.PREFIX + s);
}
- Confirmation confirmation = new Confirmation(ConfirmationType.EXTEND, (Player) sender, "YES") {
+ Confirmation confirmation = new Confirmation(ConfirmationType.EXTEND, player, "YES") {
@Override
public void success() {
PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey();
@@ -129,11 +161,15 @@ public void expiry() {
ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId());
}
};
- ConfirmationManager.confirmations.add(confirmation);
+ ConfirmationManager.addConfirmation(confirmation);
return;
}
}
}
+ if (ConfirmationManager.doesConfirmationExist(ConfirmationType.STAKE, player.getUniqueId())) {
+ player.sendMessage(VirtualRealty.PREFIX + "§cYou already have a confirmation to confirm!");
+ return;
+ }
if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
@@ -142,13 +178,13 @@ public void expiry() {
gridStructure.removeGrid();
gridStructure.setDisplayTicks(20L * 6);
gridStructure.preview(true, true);
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledCollision);
return;
}
for (String s : VirtualRealty.getMessages().stakeConfirmation) {
- sender.sendMessage(VirtualRealty.PREFIX + s);
+ player.sendMessage(VirtualRealty.PREFIX + s);
}
- Confirmation confirmation = new Confirmation(ConfirmationType.STAKE, (Player) sender, "YES") {
+ Confirmation confirmation = new Confirmation(ConfirmationType.STAKE, player, "YES") {
@Override
public void success() {
GridStructure gridStructure = DraftListener.DRAFT_MAP.get(this.getSender()).getKey();
@@ -159,7 +195,7 @@ public void success() {
gridStructure.removeGrid();
this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
long timeStart = System.currentTimeMillis();
- Plot plot = PlotManager.createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.isNatural());
+ Plot plot = PlotManager.getInstance().createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.isNatural());
AbstractMap.SimpleEntry floorData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_floor_material"), item.getByte("vrplot_floor_data"));
AbstractMap.SimpleEntry borderData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_border_material"), item.getByte("vrplot_border_data"));
if (!plotItem.isNatural()) {
@@ -186,7 +222,7 @@ public void success() {
textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
textComponent.addExtra(textComponent2);
textComponent.addExtra(textComponent3);
- new Chat(textComponent).sendTo(this.getSender());
+ ChatMessage.of(textComponent).send(this.getSender());
new BukkitRunnable() {
@Override
public void run() {
@@ -215,7 +251,156 @@ public void expiry() {
ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId());
}
};
- ConfirmationManager.confirmations.add(confirmation);
+ ConfirmationManager.addConfirmation(confirmation);
+ }
+
+ @EventHandler
+ public void onPlotItemDraft(PlayerInteractEvent e) {
+ Player player = e.getPlayer();
+ if (e.getHand() == EquipmentSlot.OFF_HAND) return;
+ if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
+ if (DraftListener.DRAFT_MAP.containsKey(player)) {
+ e.setCancelled(true);
+ player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
+ DraftListener.DRAFT_MAP.get(player).getKey().removeGrid();
+ DraftListener.DRAFT_MAP.remove(player);
+ ConfirmationManager.removeStakeConfirmations(ConfirmationType.STAKE, player.getUniqueId());
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeDisabled);
+ return;
+ }
+ PlayerInventory inv = player.getInventory();
+ ItemStack claimItem = VirtualRealty.legacyVersion ? player.getItemInHand() : inv.getItemInMainHand();
+ NBTItem claimNbtItem;
+ if (!(claimItem.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD)
+ &&
+ (claimNbtItem = new NBTItem(claimItem)).getString("vrplot_item") != null && claimNbtItem.getString("vrplot_item").equals("CLAIM"))) {
+ return;
+ }
+ e.setCancelled(true);
+ PlotItem plotItem = PlotItem.fromItemStack(claimItem);
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
+ String featureName;
+ if (plot == null) {
+ if (!canCreateInWorld(player)) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation);
+ return;
+ }
+ featureName = VirtualRealty.getMessages().createFeature;
+ } else {
+ if (plotItem.getPlotSize().equals(plot.getPlotSize())) {
+ if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) {
+ featureName = VirtualRealty.getMessages().claimFeature;
+ } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) {
+ featureName = VirtualRealty.getMessages().extendFeature;
+ } else return;
+ } else {
+ if (!canCreateInWorld(player)) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().disabledPlotCreation);
+ return;
+ }
+ featureName = VirtualRealty.getMessages().createFeature;
+ }
+ }
+ String finalFeatureName = featureName;
+ if (plot != null && plotItem.getPlotSize().equals(plot.getPlotSize()) && plot.getPlotSize() != PlotSize.CUSTOM) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot);
+ GridStructure previewStructure = new GridStructure(
+ player,
+ plot.getLength(),
+ plot.getHeight(),
+ plot.getWidth(),
+ plot.getID(),
+ player.getWorld(),
+ 0,
+ plot.getCreatedLocation()
+ );
+ previewStructure.preview(player.getLocation(), true, false);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed);
+ PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT);
+ DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(previewStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem)));
+ inv.remove(claimItem);
+ ItemStack draftItemStack = draftItem.getItemStack();
+ if (VirtualRealty.legacyVersion) {
+ player.setItemInHand(draftItemStack);
+ } else {
+ inv.setItemInMainHand(draftItemStack);
+ }
+ VirtualRealty.getMessages().claimEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§")
+ .replaceAll("%feature%", finalFeatureName)
+ ));
+ return;
+ }
+ PlotSize plotSize = PlotSize.valueOf(claimNbtItem.getString("vrplot_size"));
+ Cuboid cuboid = RegionUtil.getRegion(player.getLocation(), Direction.byYaw(player.getLocation().getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth());
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledCollision);
+ if (!GridStructure.isCuboidGridDisplaying(player, 0)) {
+ new GridStructure(
+ player,
+ plotSize.getLength(),
+ plotSize.getHeight(),
+ plotSize.getWidth(),
+ 0,
+ player.getWorld(),
+ GridStructure.DISPLAY_TICKS,
+ player.getLocation()
+ ).preview(player.getLocation(),true, true);
+ }
+ return;
+ }
+ if (RegionUtil.isCollidingWithBedrock(cuboid)) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeCancelledBedrock);
+ GridStructure.isCuboidGridDisplaying(player, 0);
+ if (!GridStructure.isCuboidGridDisplaying(player, 0)) {
+ new GridStructure(
+ player,
+ plotSize.getLength(),
+ plotSize.getHeight(),
+ plotSize.getWidth(),
+ 0,
+ player.getWorld(),
+ GridStructure.DISPLAY_TICKS,
+ player.getLocation()
+ ).preview(player.getLocation(),true, true);
+ }
+ return;
+ }
+ PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT);
+ GridStructure draftStructure = new GridStructure(
+ player,
+ plotItem.getLength(),
+ plotItem.getHeight(),
+ plotItem.getWidth(),
+ 0,
+ player.getWorld(),
+ 0,
+ player.getLocation()
+ );
+ DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(draftStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem)));
+ inv.remove(claimItem);
+ if (VirtualRealty.legacyVersion) {
+ player.setItemInHand(draftItem.getItemStack());
+ } else {
+ inv.setItemInMainHand(draftItem.getItemStack());
+ }
+ draftStructure.preview(player.getLocation(), true, false);
+ VirtualRealty.getMessages().claimEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§")
+ .replaceAll("%feature%", finalFeatureName)
+ ));
+ }
+
+ public boolean canCreateInWorld(Player player) {
+ switch (WorldSetting.valueOf(VirtualRealty.getPluginConfiguration().worldsSetting.toUpperCase())) {
+ case ALL:
+ break;
+ case INCLUDED:
+ if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().noneMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false;
+ break;
+ case EXCLUDED:
+ if (VirtualRealty.getPluginConfiguration().getWorldsList().stream().anyMatch(s -> player.getWorld().getName().equalsIgnoreCase(s))) return false;
+ }
+ return true;
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/protection/BorderProtectionListener.java
similarity index 68%
rename from src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/protection/BorderProtectionListener.java
index e39ba01..64d46f2 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/protection/BorderProtectionListener.java
@@ -1,10 +1,9 @@
-package com.modnmetl.virtualrealty.listeners.protection;
+package com.modnmetl.virtualrealty.listener.protection;
-import com.modnmetl.virtualrealty.listeners.VirtualListener;
+import com.modnmetl.virtualrealty.listener.VirtualListener;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import org.bukkit.command.CommandSender;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
@@ -17,8 +16,9 @@ public BorderProtectionListener(VirtualRealty plugin) {
@EventHandler
public void onBorderBreak(BlockBreakEvent e) {
- Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation(), true);
if (plot == null) return;
+ if (plot.isBorderLess()) return;
if (e.getPlayer().isOp()) return;
if (!plot.getBorderBlocks().contains(e.getBlock())) return;
e.setCancelled(true);
@@ -27,8 +27,9 @@ public void onBorderBreak(BlockBreakEvent e) {
@EventHandler
public void onBorderPlace(BlockPlaceEvent e) {
- Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation(), true);
if (plot == null) return;
+ if (plot.isBorderLess()) return;
if (e.getPlayer().isOp()) return;
if (!plot.getBorderBlocks().contains(e.getBlock())) return;
e.setCancelled(true);
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/protection/PlotProtectionListener.java
similarity index 88%
rename from src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/protection/PlotProtectionListener.java
index 343d2bf..708b579 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/protection/PlotProtectionListener.java
@@ -1,15 +1,15 @@
-package com.modnmetl.virtualrealty.listeners.protection;
+package com.modnmetl.virtualrealty.listener.protection;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.materials.DoorMaterial;
-import com.modnmetl.virtualrealty.enums.materials.InteractMaterial;
-import com.modnmetl.virtualrealty.enums.materials.StorageMaterial;
-import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
-import com.modnmetl.virtualrealty.enums.materials.SwitchMaterial;
-import com.modnmetl.virtualrealty.listeners.VirtualListener;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.PlotMember;
+import com.modnmetl.virtualrealty.model.material.DoorMaterial;
+import com.modnmetl.virtualrealty.model.material.InteractMaterial;
+import com.modnmetl.virtualrealty.model.material.StorageMaterial;
+import com.modnmetl.virtualrealty.model.permission.RegionPermission;
+import com.modnmetl.virtualrealty.model.material.SwitchMaterial;
+import com.modnmetl.virtualrealty.listener.VirtualListener;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.plot.PlotMember;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -27,7 +27,6 @@
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;
-import org.bukkit.material.Crops;
import org.bukkit.permissions.Permission;
import java.util.ArrayList;
@@ -46,27 +45,23 @@ public class PlotProtectionListener extends VirtualListener {
static {
for (InteractMaterial value : InteractMaterial.values()) {
Material material = Material.getMaterial(value.toString());
- if (Objects.nonNull(material)) {
+ if (Objects.nonNull(material))
INTERACT.add(material);
- }
}
for (SwitchMaterial value : SwitchMaterial.values()) {
Material material = Material.getMaterial(value.toString());
- if (Objects.nonNull(material)) {
+ if (Objects.nonNull(material))
SWITCHES.add(material);
- }
}
for (StorageMaterial value : StorageMaterial.values()) {
Material material = Material.getMaterial(value.toString());
- if (Objects.nonNull(material)) {
+ if (Objects.nonNull(material))
STORAGES.add(material);
- }
}
for (DoorMaterial value : DoorMaterial.values()) {
Material material = Material.getMaterial(value.toString());
- if (Objects.nonNull(material)) {
+ if (Objects.nonNull(material))
DOORS.add(material);
- }
}
}
@@ -79,14 +74,13 @@ public void onMobSpawn(CreatureSpawnEvent e) {
if (e.isCancelled()) return;
if (e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) return;
Location location = e.getLocation();
- Plot plot = PlotManager.getPlot(location);
+ Plot plot = PlotManager.getInstance().getPlot(location);
if (plot != null) {
if (VirtualRealty.getPluginConfiguration().disablePlotMobsSpawn) {
e.setCancelled(true);
} else if (VirtualRealty.getPluginConfiguration().disablePlotMonsterSpawn) {
- if ((e.getEntity() instanceof Monster) || e.getEntityType() == EntityType.SLIME) {
+ if ((e.getEntity() instanceof Monster) || e.getEntityType() == EntityType.SLIME)
e.setCancelled(true);
- }
}
}
}
@@ -97,12 +91,11 @@ public void onCropInteract(PlayerInteractEvent e) {
Player player = e.getPlayer();
if (e.getAction() != Action.PHYSICAL) return;
if (e.getClickedBlock() == null) return;
- if (VirtualRealty.legacyVersion) {
+ if (VirtualRealty.legacyVersion)
if (e.getClickedBlock().getType() == Material.getMaterial("CROPS")) return;
- } else {
- if (e.getClickedBlock().getType() != Material.FARMLAND) return;
- }
- Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ else
+ if (e.getClickedBlock().getType() != Material.FARMLAND) return;
+ Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -138,7 +131,7 @@ public void onBlockInteract(PlayerInteractEvent e) {
if (e.getHand() == EquipmentSlot.OFF_HAND) return;
if (!e.getClickedBlock().getType().isInteractable() && !(e.getClickedBlock().getType().name().endsWith("PRESSURE_PLATE"))) return;
}
- Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
boolean isModernSwitch = !VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch;
@@ -207,7 +200,7 @@ public void onChestEvent(PlayerInteractEvent e) {
if (!STORAGES.contains(e.getClickedBlock().getType())) return;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (player.isSneaking() && e.isBlockInHand()) return;
- Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -236,7 +229,7 @@ public void onPotInteract(PlayerInteractEvent e) {
Player player = e.getPlayer();
if (e.getClickedBlock() == null) return;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
- Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -279,7 +272,7 @@ public void onPotInteract(PlayerInteractEvent e) {
public void onLiquidPlace(PlayerBucketEmptyEvent e) {
if (e.isCancelled()) return;
Player player = e.getPlayer();
- Plot plot = PlotManager.getBorderedPlot(e.getBlockClicked().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlockClicked().getLocation(), true);
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -307,7 +300,7 @@ public void onVehicleDestroy(VehicleDestroyEvent e) {
if (e.isCancelled()) return;
if (!(e.getAttacker() instanceof Player)) return;
Player player = (Player) e.getAttacker();
- Plot plot = PlotManager.getBorderedPlot(e.getVehicle().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getVehicle().getLocation(), true);
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -334,7 +327,7 @@ public void onVehicleDestroy(VehicleDestroyEvent e) {
public void onLiquidTake(PlayerBucketFillEvent e) {
if (e.isCancelled()) return;
Player player = e.getPlayer();
- Plot plot = PlotManager.getBorderedPlot(e.getBlockClicked().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlockClicked().getLocation(), true);
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -360,7 +353,7 @@ public void onLiquidTake(PlayerBucketFillEvent e) {
@EventHandler(priority = EventPriority.LOW)
public void onBlockPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
- Plot plot = PlotManager.getBorderedPlot(e.getBlockPlaced().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlockPlaced().getLocation(), true);
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -387,7 +380,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
public void onBlockBreak(BlockBreakEvent e) {
if (e.isCancelled()) return;
Player player = e.getPlayer();
- Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation(), true);
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -414,19 +407,17 @@ public void onBlockBreak(BlockBreakEvent e) {
public void onPistonRetract(BlockPistonRetractEvent e) {
if (e.isCancelled()) return;
Block piston = e.getBlock();
- Plot fromPlot = PlotManager.getPlot(piston.getLocation());
+ Plot fromPlot = PlotManager.getInstance().getPlot(piston.getLocation());
e.getBlocks().forEach(block -> {
Location toLocation = block.getLocation();
- Plot toPlot = PlotManager.getPlot(toLocation);
- Plot toBorderedPlot = PlotManager.getBorderedPlot(toLocation);
+ Plot toPlot = PlotManager.getInstance().getPlot(toLocation);
+ Plot toBorderedPlot = PlotManager.getInstance().getPlot(toLocation, true);
if (fromPlot != null) {
- if (toPlot == null) {
+ if (toPlot == null)
e.setCancelled(true);
- }
} else {
- if (toBorderedPlot != null) {
+ if (toBorderedPlot != null)
e.setCancelled(true);
- }
}
});
}
@@ -436,8 +427,8 @@ public void onBlockMove(BlockPistonExtendEvent e) {
if (e.isCancelled()) return;
for (Block block : e.getBlocks()) {
Location blockLocation = block.getLocation();
- Plot plot = PlotManager.getPlot(blockLocation);
- Plot borderedPlot = PlotManager.getBorderedPlot(blockLocation);
+ Plot plot = PlotManager.getInstance().getPlot(blockLocation);
+ Plot borderedPlot = PlotManager.getInstance().getPlot(blockLocation, true);
if (borderedPlot != null) {
if (plot == null) {
e.setCancelled(true);
@@ -454,7 +445,7 @@ public void onIgniteEvent(BlockIgniteEvent e) {
Player player = e.getPlayer();
if (player == null) return;
if (e.getIgnitingBlock() == null) return;
- Plot plot = PlotManager.getBorderedPlot(e.getIgnitingBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation(), true);
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -480,8 +471,8 @@ public void onIgniteEvent(BlockIgniteEvent e) {
public void onBlockIgnite(BlockIgniteEvent e){
if (e.isCancelled()) return;
if (e.getCause() != BlockIgniteEvent.IgniteCause.SPREAD) return;
- Plot fromPlot = PlotManager.getPlot(e.getBlock().getLocation());
- Plot toPlot = PlotManager.getPlot(e.getIgnitingBlock().getLocation());
+ Plot fromPlot = PlotManager.getInstance().getPlot(e.getBlock().getLocation());
+ Plot toPlot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation());
if (toPlot != null && fromPlot == null) {
e.setCancelled(true);
}
@@ -493,8 +484,8 @@ public void onTreeGrow(StructureGrowEvent e) {
for (BlockState block : new ArrayList<>(e.getBlocks())) {
Location saplingLocation = e.getLocation();
Location blockLocation = block.getLocation();
- Plot fromPlot = PlotManager.getPlot(saplingLocation);
- Plot toPlot = PlotManager.getPlot(blockLocation);
+ Plot fromPlot = PlotManager.getInstance().getPlot(saplingLocation);
+ Plot toPlot = PlotManager.getInstance().getPlot(blockLocation);
if (fromPlot != null) {
if (toPlot != null) {
if (fromPlot.getID() == toPlot.getID()) return;
@@ -515,8 +506,8 @@ public void onDragonEggMove(BlockFromToEvent e) {
if (block == Material.DRAGON_EGG || block == Material.LAVA || block == Material.WATER) {
Location fromLocation = e.getBlock().getLocation();
Location toLocation = e.getToBlock().getLocation();
- Plot fromPlot = PlotManager.getPlot(fromLocation);
- Plot toPlot = PlotManager.getPlot(toLocation);
+ Plot fromPlot = PlotManager.getInstance().getPlot(fromLocation);
+ Plot toPlot = PlotManager.getInstance().getPlot(toLocation);
if (toPlot != null) {
if (fromPlot == null) {
e.setCancelled(true);
@@ -533,7 +524,7 @@ public void onProjectileLaunch(ProjectileLaunchEvent e) {
if (e.getEntity().getShooter() == null) return;
if (!(e.getEntity().getShooter() instanceof Player)) return;
Player shooter = ((Player) e.getEntity().getShooter());
- Plot plot = PlotManager.getPlot(e.getEntity().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation());
if (plot == null) return;
if (hasPermission(shooter, PLOT_BUILD)) return;
if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player) e.getEntity().getShooter()).getUniqueId()))
@@ -547,7 +538,7 @@ public void onProjectileHit(ProjectileHitEvent e) {
if (e.getEntity().getShooter() == null) return;
if (!(e.getEntity().getShooter() instanceof Player)) return;
Player shooter = ((Player) e.getEntity().getShooter());
- Plot plot = PlotManager.getPlot(e.getEntity().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation());
if (plot == null) return;
if (hasPermission(shooter, PLOT_BUILD)) return;
if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player) e.getEntity().getShooter()).getUniqueId()))
@@ -559,7 +550,7 @@ public void onProjectileHit(ProjectileHitEvent e) {
@EventHandler(priority = EventPriority.LOW)
public void onArmorStandChange(PlayerArmorStandManipulateEvent e) {
if (e.isCancelled()) return;
- Plot plot = PlotManager.getPlot(e.getPlayer().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getPlayer().getLocation());
Player player = e.getPlayer();
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
@@ -588,7 +579,7 @@ public void onItemFrameDamage(HangingBreakByEntityEvent e) {
if (e.isCancelled()) return;
if (!(e.getRemover() instanceof Player)) return;
Player player = (Player) e.getRemover();
- Plot plot = PlotManager.getPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -615,7 +606,7 @@ public void onItemFrameDamage(HangingBreakByEntityEvent e) {
public void onItemFrameRotate(PlayerInteractEntityEvent e) {
if (e.isCancelled()) return;
Player player = e.getPlayer();
- Plot plot = PlotManager.getPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (!(e.getRightClicked() instanceof ItemFrame)) return;
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
@@ -646,7 +637,7 @@ private void onInteract(PlayerInteractEvent e) {
if (e.getItem() == null) return;
if (e.getItem().getType() != Material.ARMOR_STAND) return;
if (e.getClickedBlock() == null) return;
- Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -674,7 +665,7 @@ public void onHangingPlace(HangingPlaceEvent e) {
if (e.isCancelled()) return;
Player player = e.getPlayer();
if (player == null) return;
- Plot plot = PlotManager.getPlot(e.getEntity().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -703,7 +694,7 @@ public void onEntityDamage(EntityDamageByEntityEvent e) {
if (!(e.getDamager() instanceof Player)) return;
if (!(e.getEntity() instanceof Creature) && !(e.getEntity() instanceof Player)) return;
Player player = (Player) e.getDamager();
- Plot plot = PlotManager.getPlot(e.getEntity().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -732,7 +723,7 @@ public void onStaticEntityDamage(EntityDamageByEntityEvent e) {
if (e.getEntity() instanceof Creature || e.getEntity() instanceof Player) return;
if (!(e.getDamager() instanceof Player)) return;
Player player = (Player) e.getDamager();
- Plot plot = PlotManager.getPlot(e.getEntity().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation());
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -758,7 +749,7 @@ public void onStaticEntityDamage(EntityDamageByEntityEvent e) {
@EventHandler(priority = EventPriority.LOW)
public void onEntityExplode(EntityExplodeEvent e) {
for (Block block : new ArrayList<>(e.blockList())) {
- Plot plot = PlotManager.getBorderedPlot(block.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(block.getLocation(), true);
if (plot != null)
e.blockList().remove(block);
}
@@ -767,7 +758,7 @@ public void onEntityExplode(EntityExplodeEvent e) {
@EventHandler(priority = EventPriority.LOW)
public void onBlockExplode(BlockExplodeEvent e) {
for (Block block : new ArrayList<>(e.blockList())) {
- Plot plot = PlotManager.getBorderedPlot(block.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(block.getLocation(), true);
if (plot != null)
e.blockList().remove(block);
}
@@ -775,21 +766,25 @@ public void onBlockExplode(BlockExplodeEvent e) {
@EventHandler
public void onFireSpread(BlockSpreadEvent e) {
- Plot plot = PlotManager.getBorderedPlot(e.getNewState().getLocation());
- if (plot != null)
- e.setCancelled(true);
+ Plot plot = PlotManager.getInstance().getPlot(e.getNewState().getLocation(), true);
+ if (
+ !(plot != null &&
+ (e.getSource().getType() == Material.FIRE &&
+ (e.getSource().getType() == e.getNewState().getType() ||
+ e.getNewState().getType() == Material.AIR)))
+ ) return;
+ e.setCancelled(true);
}
@EventHandler
public void onFireBurn(BlockBurnEvent e) {
if (!VirtualRealty.legacyVersion) {
- Plot fromPlot = PlotManager.getPlot(e.getIgnitingBlock().getLocation());
- Plot toPlot = PlotManager.getPlot(e.getBlock().getLocation());
+ Plot fromPlot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation());
+ Plot toPlot = PlotManager.getInstance().getPlot(e.getBlock().getLocation());
if (toPlot == null) return;
if (fromPlot != null) {
- if (toPlot.getID() != fromPlot.getID()) {
+ if (toPlot.getID() != fromPlot.getID())
e.setCancelled(true);
- }
} else {
e.setCancelled(true);
}
@@ -802,7 +797,7 @@ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) {
if (!((e.getDamager() instanceof Projectile) && ((Projectile) e.getDamager()).getShooter() instanceof Player))
return;
Player player = ((Player) ((Projectile) e.getDamager()).getShooter());
- Plot plot = PlotManager.getBorderedPlot(e.getDamager().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getDamager().getLocation(), true);
if (plot == null) return;
if (hasPermission(player, PLOT_BUILD)) return;
if (plot.hasMembershipAccess(player.getUniqueId())) {
@@ -829,4 +824,4 @@ public boolean hasPermission(CommandSender sender, Permission permission) {
return sender.hasPermission(permission);
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/protection/WorldProtectionListener.java
similarity index 87%
rename from src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/protection/WorldProtectionListener.java
index a5a1c6e..68592ca 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/protection/WorldProtectionListener.java
@@ -1,11 +1,11 @@
-package com.modnmetl.virtualrealty.listeners.protection;
+package com.modnmetl.virtualrealty.listener.protection;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
-import com.modnmetl.virtualrealty.listeners.VirtualListener;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.utils.WorldUtil;
+import com.modnmetl.virtualrealty.model.permission.RegionPermission;
+import com.modnmetl.virtualrealty.listener.VirtualListener;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.util.WorldUtil;
import org.bukkit.Material;
import org.bukkit.block.data.type.Switch;
import org.bukkit.command.CommandSender;
@@ -45,7 +45,7 @@ public void onBlockInteract(PlayerInteractEvent e) {
if (e.getHand() == EquipmentSlot.OFF_HAND) return;
if (!e.getClickedBlock().getType().isInteractable()) return;
}
- Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation());
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
try {
@@ -75,7 +75,7 @@ public void onChestClick(PlayerInteractEvent e) {
if (e.getClickedBlock().getType() != Material.CHEST) return;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (player.isSneaking() && e.isBlockInHand()) return;
- Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getClickedBlock().getLocation());
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.CHEST_ACCESS)) return;
@@ -87,7 +87,7 @@ public void onChestClick(PlayerInteractEvent e) {
public void onBlockPlace(BlockPlaceEvent e) {
if (e.isCancelled()) return;
Player player = e.getPlayer();
- Plot plot = PlotManager.getPlot(e.getBlockPlaced().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlockPlaced().getLocation());
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.PLACE)) return;
@@ -99,7 +99,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
public void onBlockBreak(BlockBreakEvent e) {
if (e.isCancelled()) return;
Player player = e.getPlayer();
- Plot plot = PlotManager.getPlot(e.getBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getBlock().getLocation());
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.BREAK)) return;
@@ -113,7 +113,7 @@ public void onIgniteEvent(BlockIgniteEvent e) {
Player player = e.getPlayer();
if (player == null) return;
if (e.getIgnitingBlock() == null) return;
- Plot plot = PlotManager.getBorderedPlot(e.getIgnitingBlock().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getIgnitingBlock().getLocation());
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.ITEM_USE)) return;
@@ -124,7 +124,7 @@ public void onIgniteEvent(BlockIgniteEvent e) {
@EventHandler(priority = EventPriority.LOW)
public void onArmorStandChange(PlayerArmorStandManipulateEvent e) {
if (e.isCancelled()) return;
- Plot plot = PlotManager.getPlot(e.getPlayer().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getPlayer().getLocation());
Player player = e.getPlayer();
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
@@ -138,7 +138,7 @@ public void onItemFrameDamage(HangingBreakByEntityEvent e) {
if (e.isCancelled()) return;
if (!(e.getRemover() instanceof Player)) return;
Player player = (Player) e.getRemover();
- Plot plot = PlotManager.getPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) return;
@@ -151,7 +151,7 @@ public void onItemFrameRotate(PlayerInteractEntityEvent e) {
if (e.isCancelled()) return;
if (!e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) return;
Player player = e.getPlayer();
- Plot plot = PlotManager.getPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (plot != null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.ITEM_USE)) return;
@@ -165,7 +165,7 @@ public void onEntityDamage(EntityDamageByEntityEvent e) {
if (e.isCancelled()) return;
if (!(e.getDamager() instanceof Player)) return;
Player player = (Player) e.getDamager();
- Plot plot = PlotManager.getPlot(e.getEntity().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getEntity().getLocation());
if (plot == null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) return;
@@ -179,7 +179,7 @@ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) {
if (!((e.getDamager() instanceof Projectile) && ((Projectile) e.getDamager()).getShooter() instanceof Player))
return;
Player player = ((Player) ((Projectile) e.getDamager()).getShooter());
- Plot plot = PlotManager.getBorderedPlot(e.getDamager().getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(e.getDamager().getLocation());
if (plot == null) return;
if (hasPermission(player, WORLD_BUILD)) return;
if (WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/stake/ConfirmationListener.java
similarity index 50%
rename from src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/stake/ConfirmationListener.java
index 459b961..ec5efda 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/ConfirmationListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/stake/ConfirmationListener.java
@@ -1,37 +1,15 @@
-package com.modnmetl.virtualrealty.listeners.stake;
+package com.modnmetl.virtualrealty.listener.stake;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.commands.plot.subcommand.StakeSubCommand;
-import com.modnmetl.virtualrealty.commands.vrplot.subcommand.RemoveSubCommand;
-import com.modnmetl.virtualrealty.enums.ConfirmationType;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.listeners.VirtualListener;
-import com.modnmetl.virtualrealty.managers.ConfirmationManager;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.data.Confirmation;
-import com.modnmetl.virtualrealty.objects.data.PlotItem;
-import com.modnmetl.virtualrealty.objects.region.GridStructure;
-import com.modnmetl.virtualrealty.utils.multiversion.Chat;
-import de.tr7zw.nbtapi.NBTItem;
-import net.md_5.bungee.api.chat.BaseComponent;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.HoverEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-import org.bukkit.Bukkit;
-import org.bukkit.Material;
+import com.modnmetl.virtualrealty.listener.VirtualListener;
+import com.modnmetl.virtualrealty.manager.ConfirmationManager;
+import com.modnmetl.virtualrealty.model.other.Confirmation;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
-import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
-import javax.persistence.Version;
-import java.awt.event.KeyEvent;
-import java.time.LocalDateTime;
-import java.util.AbstractMap;
-
public class ConfirmationListener extends VirtualListener {
public ConfirmationListener(VirtualRealty plugin) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java b/src/main/java/com/modnmetl/virtualrealty/listener/stake/DraftListener.java
similarity index 83%
rename from src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listener/stake/DraftListener.java
index 921406c..38c9f70 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listener/stake/DraftListener.java
@@ -1,9 +1,9 @@
-package com.modnmetl.virtualrealty.listeners.stake;
+package com.modnmetl.virtualrealty.listener.stake;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.listeners.VirtualListener;
-import com.modnmetl.virtualrealty.objects.data.PlotItem;
-import com.modnmetl.virtualrealty.objects.region.GridStructure;
+import com.modnmetl.virtualrealty.listener.VirtualListener;
+import com.modnmetl.virtualrealty.model.plot.PlotItem;
+import com.modnmetl.virtualrealty.model.region.GridStructure;
import de.tr7zw.nbtapi.NBTItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -16,7 +16,6 @@
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.PlayerInventory;
import java.util.HashMap;
import java.util.Map;
@@ -67,21 +66,15 @@ public void onPlayerDeath(PlayerDeathEvent e) {
player.getInventory().addItem(DRAFT_MAP.get(player).getValue().getKey().getItemStack());
DRAFT_MAP.get(player).getKey().removeGrid();
DRAFT_MAP.remove(player);
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeDisabledDueToDeath);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().claimModeDisabledDueToDeath);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
- ItemStack itemInHand;
- if (VirtualRealty.legacyVersion) {
- itemInHand = player.getItemInHand();
- } else {
- itemInHand = player.getInventory().getItemInMainHand();
- }
+ ItemStack itemInHand = VirtualRealty.legacyVersion ? player.getItemInHand() : player.getInventory().getItemInMainHand();
if (itemInHand.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) && (new NBTItem(itemInHand)).hasKey("vrplot_item")) {
e.setCancelled(true);
- player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantPlaceDraftItems);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java
deleted file mode 100644
index f0445e2..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.modnmetl.virtualrealty.listeners.player;
-
-import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.listeners.VirtualListener;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.HoverEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.player.PlayerJoinEvent;
-import org.bukkit.scheduler.BukkitRunnable;
-
-public class PlayerActionListener extends VirtualListener {
-
- public PlayerActionListener(VirtualRealty plugin) {
- super(plugin);
- }
-
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent e) {
- Player player = e.getPlayer();
- if (!player.isOp()) return;
- if (VirtualRealty.upToDate) return;
- new BukkitRunnable() {
- @Override
- public void run() {
- player.sendMessage(VirtualRealty.PREFIX + "§7A new version of VirtualRealty plugin is available. §a[" + VirtualRealty.latestVersion + "]");
- TextComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aDownload the new version of the plugin here!");
- textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{ new TextComponent("§a§oClick here to download the update!") }));
- textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/"));
- player.spigot().sendMessage(textComponent);
- }
- }.runTaskLater(VirtualRealty.getInstance(), 5);
- }
-
-}
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/ConfirmationManager.java
similarity index 56%
rename from src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java
rename to src/main/java/com/modnmetl/virtualrealty/manager/ConfirmationManager.java
index 2215906..eb17958 100644
--- a/src/main/java/com/modnmetl/virtualrealty/managers/ConfirmationManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/manager/ConfirmationManager.java
@@ -1,7 +1,7 @@
-package com.modnmetl.virtualrealty.managers;
+package com.modnmetl.virtualrealty.manager;
-import com.modnmetl.virtualrealty.enums.ConfirmationType;
-import com.modnmetl.virtualrealty.objects.data.Confirmation;
+import com.modnmetl.virtualrealty.model.other.ConfirmationType;
+import com.modnmetl.virtualrealty.model.other.Confirmation;
import lombok.Getter;
import java.util.ArrayList;
@@ -11,7 +11,15 @@
public class ConfirmationManager {
@Getter
- public static final List confirmations = new ArrayList<>();
+ private static final List confirmations = new ArrayList<>();
+
+ public static void addConfirmation(Confirmation confirmation) {
+ confirmations.add(confirmation);
+ }
+
+ public static boolean doesConfirmationExist(ConfirmationType confirmationType, UUID player) {
+ return confirmations.stream().anyMatch(confirmation -> confirmation.getConfirmationType() == confirmationType && confirmation.getSender().getUniqueId().equals(player));
+ }
public static void removeConfirmations(int plotID, ConfirmationType confirmationType) {
confirmations.removeIf(confirmation -> confirmation.getPlotID() == plotID && confirmation.getConfirmationType() == confirmationType);
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/DynmapManager.java
similarity index 92%
rename from src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java
rename to src/main/java/com/modnmetl/virtualrealty/manager/DynmapManager.java
index 654de7b..6e8d41d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/manager/DynmapManager.java
@@ -1,8 +1,8 @@
-package com.modnmetl.virtualrealty.managers;
+package com.modnmetl.virtualrealty.manager;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.dynmap.HighlightType;
-import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.model.other.HighlightType;
+import com.modnmetl.virtualrealty.model.plot.Plot;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@@ -66,7 +66,7 @@ public void run() {
}
} catch (IOException ignored) {}
VirtualRealty.debug("Registering plots markers..");
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
resetPlotMarker(plot);
}
VirtualRealty.debug("Registered plots markers");
@@ -78,9 +78,7 @@ public void run() {
private static AreaMarker getAreaMarker(String areaMarkerName) {
if (VirtualRealty.getDynmapManager() == null) return null;
for (AreaMarker areaMarker : VirtualRealty.getDynmapManager().markerset.getAreaMarkers()) {
- if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) {
- return areaMarker;
- }
+ if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) return areaMarker;
}
return null;
}
@@ -116,16 +114,15 @@ public static void resetPlotMarker(Plot plot) {
marker.setFillStyle(opacity, color);
marker.setLineStyle(2, 0.8, 0x474747);
marker.setMarkerSet(VirtualRealty.getDynmapManager().markerset);
- VirtualRealty.debug("Updated dynmap marker #" + plot.getID());
}
public static void removeDynMapMarker(Plot plot) {
- if (VirtualRealty.getDynmapManager() == null || !VirtualRealty.getDynmapManager().isDynmapPresent() || VirtualRealty.getDynmapManager().dapi == null || VirtualRealty.getDynmapManager().markerset == null) return;
+ if (VirtualRealty.getDynmapManager() == null || !VirtualRealty.getDynmapManager().isDynmapPresent() || VirtualRealty.getDynmapManager().dapi == null || VirtualRealty.getDynmapManager().markerset == null)
+ return;
AreaMarker marker = VirtualRealty.getDynmapManager().markerset.findAreaMarker("virtualrealty.plots." + plot.getID());
- if (marker != null) {
- areaMarkers.remove(marker);
- marker.deleteMarker();
- }
+ if (marker == null) return;
+ areaMarkers.remove(marker);
+ marker.deleteMarker();
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/MetricsManager.java
similarity index 93%
rename from src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java
rename to src/main/java/com/modnmetl/virtualrealty/manager/MetricsManager.java
index 391ea13..f3da919 100644
--- a/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/manager/MetricsManager.java
@@ -1,7 +1,7 @@
-package com.modnmetl.virtualrealty.managers;
+package com.modnmetl.virtualrealty.manager;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.model.plot.Plot;
import lombok.Getter;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
@@ -34,7 +34,7 @@ public void registerMetrics() {
int largePlots = 0;
int customPlots = 0;
int areas = 0;
- for (Plot plot : PlotManager.getPlots()) {
+ for (Plot plot : PlotManager.getInstance().getPlots()) {
switch (plot.getPlotSize()) {
case SMALL: {
smallPlots++;
diff --git a/src/main/java/com/modnmetl/virtualrealty/manager/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/manager/PlotManager.java
new file mode 100644
index 0000000..e42faa5
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/manager/PlotManager.java
@@ -0,0 +1,271 @@
+package com.modnmetl.virtualrealty.manager;
+
+import com.modnmetl.virtualrealty.model.plot.PlotSize;
+import com.modnmetl.virtualrealty.model.plot.PlotMember;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.model.region.Cuboid;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.math.BlockVector3;
+import com.modnmetl.virtualrealty.sql.Database;
+import lombok.Data;
+import org.bukkit.Location;
+import org.bukkit.Material;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.*;
+import java.util.logging.Level;
+
+@Data
+public final class PlotManager {
+
+ private final VirtualRealty plugin;
+
+ private final Set plots;
+
+ private final List plotMembers;
+
+ public PlotManager(VirtualRealty plugin) {
+ this.plugin = plugin;
+ this.plots = new LinkedHashSet<>();
+ this.plotMembers = new ArrayList<>();
+ }
+
+ public void loadPlots() {
+ try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`"); ResultSet rs = ps.executeQuery()) {
+ plots.clear();
+ while (rs.next())
+ plots.add(new Plot(rs));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void loadMembers() {
+ try (Connection conn = Database.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`"); ResultSet rs = ps.executeQuery()) {
+ while (rs.next())
+ plotMembers.add(new PlotMember(rs));
+ checkDupes();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void checkDupes() {
+ HashMap dupes = new HashMap<>();
+ for (PlotMember plotMember : plotMembers) {
+ int plotId;
+ try {
+ plotId = plotMember.getPlot().getID();
+ } catch (Exception e) {
+ VirtualRealty.getInstance().getLogger().log(Level.WARNING, "Removal of plot member for lack of allocated plot | UUID: " + plotMember.getUuid());
+ plotMember.delete();
+ continue;
+ }
+ if (dupes.containsKey(plotMember.getUuid()) && dupes.get(plotMember.getUuid()) == plotId) {
+ VirtualRealty.debug("Found duped plot member: " + plotMember.getUuid() + " | " + plotId + " - Removing from database..");
+ plotMember.getPlot().removeMember(plotMember);
+ } else {
+ dupes.put(plotMember.getUuid(), plotMember.getPlot().getID());
+ }
+ }
+ }
+
+ public Plot createPlot(Location creationLocation, PlotSize plotSize, boolean natural) {
+ return createPlot(
+ creationLocation,
+ plotSize,
+ plotSize.getLength(),
+ plotSize.getHeight(),
+ plotSize.getWidth(),
+ plotSize.getFloorMaterial(),
+ plotSize.getFloorMaterial(),
+ natural
+ );
+ }
+
+ public Plot createPlot(Location creationLocation, PlotSize plotSize, boolean natural, Material floorMaterial, Material borderMaterial) {
+ return createPlot(
+ creationLocation,
+ plotSize,
+ plotSize.getLength(),
+ plotSize.getHeight(),
+ plotSize.getWidth(),
+ floorMaterial,
+ borderMaterial,
+ natural
+ );
+ }
+
+ public Plot createCustomPlot(Location creationLocation, int length, int height, int width, boolean natural) {
+ return createPlot(
+ creationLocation,
+ PlotSize.CUSTOM,
+ length,
+ height,
+ width,
+ PlotSize.CUSTOM.getFloorMaterial(),
+ PlotSize.CUSTOM.getBorderMaterial(),
+ natural
+ );
+ }
+
+ public Plot createCustomPlot(Location creationLocation, int length, int height, int width, boolean natural, Material floorMaterial, Material borderMaterial) {
+ return createPlot(
+ creationLocation,
+ PlotSize.CUSTOM,
+ length,
+ height,
+ width,
+ floorMaterial,
+ borderMaterial,
+ natural
+ );
+ }
+
+ public Plot createArea(Location creationLocation, int length, int height, int width) {
+ return createPlot(
+ creationLocation,
+ PlotSize.AREA,
+ length,
+ height,
+ width,
+ Material.AIR,
+ Material.AIR,
+ true
+ );
+ }
+
+ private Plot createPlot(Location creationLocation, PlotSize plotSize, int length, int height, int width, Material floorMaterial, Material borderMaterial, boolean natural) {
+ Plot plot = new Plot(creationLocation, floorMaterial, borderMaterial, plotSize, length, width, height, natural);
+ plots.add(plot);
+ long time = System.currentTimeMillis();
+ plot.insert();
+ VirtualRealty.debug("Plot database insertion time: " + (System.currentTimeMillis() - time) + " ms");
+ return plot;
+ }
+
+ public Plot getPlot(int ID) {
+ for (Plot plot : plots) {
+ if (plot.getID() == ID)
+ return plot;
+ }
+ return null;
+ }
+
+ public List getPlots(String world) {
+ List newPlots = new LinkedList<>();
+ for (Plot plot : plots)
+ if (plot.getCreatedWorldString().equals(world)) newPlots.add(plot);
+ return newPlots;
+ }
+
+ public HashMap getPlots(UUID owner) {
+ HashMap plotHashMap = new HashMap<>();
+ for (Plot plot : plots) {
+ if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(owner))
+ plotHashMap.put(plot.getID(), plot);
+ }
+ return plotHashMap;
+ }
+
+ public HashMap getAccessPlots(UUID player) {
+ HashMap plotHashMap = new HashMap<>();
+ for (Plot plot : plots) {
+ if (plot.getMember(player) != null || (plot.getOwnedBy() != null && plot.getPlotOwner().getUniqueId() == player))
+ plotHashMap.put(plot.getID(), plot);
+ }
+ return plotHashMap;
+ }
+
+ public int getPlotMinID() {
+ return plots.isEmpty() ? 0 : plots.stream().findFirst().get().getID();
+ }
+
+ public int getPlotMaxID() {
+ Plot[] plotArray = plots.toArray(new Plot[0]);
+ Plot lastPlot = plotArray[plotArray.length - 1];
+ return lastPlot.getID();
+ }
+
+ public List getPlayerPlots(UUID owner) {
+ LinkedList playerPlots = new LinkedList<>();
+ for (Plot plot : plots) {
+ if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(owner))
+ playerPlots.add(plot);
+ }
+ return playerPlots;
+ }
+
+ public void removePlotFromCollection(Plot plot) {
+ plots.remove(plot);
+ }
+
+ public boolean isLocationInPlot(Location location, Plot plot) {
+ BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld());
+ return region.isIn(newVector, location.getWorld());
+ }
+
+// public Plot getPlot(Location location) {
+// BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+// for (Plot plot : plots) {
+// Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld());
+// if (region.isIn(newVector, plot.getCreatedWorld())) {
+// return plot;
+// }
+// }
+// return null;
+// }
+//
+
+ public Plot getPlot(Location location) {
+ BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ for (Plot plot : plots) {
+ if (plot.isBorderLess()) {
+ return getBorderedPlot(location);
+ } else {
+ Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld());
+ if (region.isIn(newVector, plot.getCreatedWorld()))
+ return plot;
+ }
+ }
+ return null;
+ }
+
+ public Plot getPlot(Location location, boolean withBorder) {
+ BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ for (Plot plot : plots) {
+ if (withBorder) {
+ return getBorderedPlot(location);
+ } else {
+ Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld());
+ if (region.isIn(newVector, plot.getCreatedWorld()))
+ return plot;
+ }
+ }
+ return null;
+ }
+
+ private Plot getBorderedPlot(Location location) {
+ BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ for (Plot plot : plots) {
+ Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld());
+ if (region.isIn(newVector, plot.getCreatedWorld()))
+ return plot;
+ }
+ return null;
+ }
+
+ public boolean isLocationInBorderedPlot(Location location, Plot plot) {
+ BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld());
+ return region.isIn(newVector, plot.getCreatedWorld());
+ }
+
+ public static PlotManager getInstance() {
+ return VirtualRealty.getInstance().getPlotManager();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
deleted file mode 100644
index b89133a..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package com.modnmetl.virtualrealty.managers;
-
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.objects.math.BlockVector2;
-import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.objects.region.Cuboid;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.math.BlockVector3;
-import com.modnmetl.virtualrealty.sql.Database;
-import lombok.Getter;
-import org.bukkit.Location;
-import org.bukkit.Material;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.*;
-
-public class PlotManager {
-
- @Getter
- private static final Set plots = new LinkedHashSet<>();
-
- public static void loadPlots() {
- plots.clear();
- try {
- ResultSet rs = Database.getInstance().getStatement().executeQuery("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`");
- while (rs.next()) {
- plots.add(new Plot(rs));
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
-
- public static Plot createPlot(Location creationLocation, PlotSize plotSize, int length, int height, int width, boolean natural) {
- Plot plot = new Plot(creationLocation, Material.matchMaterial(VirtualRealty.legacyVersion ? "GRASS" : "GRASS_BLOCK"), Material.matchMaterial(VirtualRealty.legacyVersion ? "STEP" : "STONE_BRICK_SLAB"), plotSize, length, width, height, natural);
- plots.add(plot);
- long time = System.currentTimeMillis();
- plot.insert();
- VirtualRealty.debug("Plot database insertion time: " + (System.currentTimeMillis() - time) + " ms");
- return plot;
- }
-
- public static Plot getPlot(int ID) {
- for (Plot plot : plots) {
- if (plot.getID() == ID) {
- return plot;
- }
- }
- return null;
- }
-
- public static List getPlots(String world) {
- List newPlots = new LinkedList<>();
- for (Plot plot : plots) {
- if (plot.getCreatedWorldString().equals(world)) newPlots.add(plot);
- }
- return newPlots;
- }
-
- public static HashMap getPlots(UUID owner) {
- HashMap plotHashMap = new HashMap<>();
- for (Plot plot : plots) {
- if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(owner)) {
- plotHashMap.put(plot.getID(), plot);
- }
- }
- return plotHashMap;
- }
-
- public static HashMap getAccessPlots(UUID player) {
- HashMap plotHashMap = new HashMap<>();
- for (Plot plot : plots) {
- if (plot.getMember(player) != null || (plot.getOwnedBy() != null && plot.getPlotOwner().getUniqueId() == player)) {
- plotHashMap.put(plot.getID(), plot);
- }
- }
- return plotHashMap;
- }
-
- public static int getPlotMinID() {
- return plots.isEmpty() ? 0 : plots.stream().findFirst().get().getID();
- }
-
- public static int getPlotMaxID() {
- Plot[] plotArray = PlotManager.plots.toArray(new Plot[0]);
- Plot lastPlot = plotArray[plotArray.length - 1];
- return lastPlot.getID();
- }
-
- public static List getPlayerPlots(UUID owner) {
- LinkedList playerPlots = new LinkedList<>();
- for (Plot plot : plots) {
- if (plot.getOwnedBy() != null) {
- if (plot.getOwnedBy().equals(owner)) {
- playerPlots.add(plot);
- }
- }
- }
- return playerPlots;
- }
-
- public static Plot getPlot(Location location) {
- BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
- for (Plot plot : plots) {
- Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld());
- if (region.isIn(newVector, plot.getCreatedWorld())) {
- return plot;
- }
- }
- return null;
- }
-
- public static void removePlotFromList(Plot plot) {
- plots.remove(plot);
- }
-
- public static boolean isLocationInPlot(Location location, Plot plot) {
- BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
- Cuboid region = new Cuboid(plot.getBottomLeftCorner(), plot.getTopRightCorner(), location.getWorld());
- return region.isIn(newVector, location.getWorld());
- }
-
- public static Plot getBorderedPlot(Location location) {
- BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
- for (Plot plot : plots) {
- Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld());
- if (region.isIn(newVector, plot.getCreatedWorld())) {
- return plot;
- }
- }
- return null;
- }
-
- public static boolean isLocationInBorderedPlot(Location location, Plot plot) {
- BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
- Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld());
- return region.isIn(newVector, plot.getCreatedWorld());
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java
deleted file mode 100644
index b8e7037..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.modnmetl.virtualrealty.managers;
-
-import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.objects.data.PlotMember;
-import com.modnmetl.virtualrealty.sql.Database;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-public class PlotMemberManager {
-
- public static void loadMembers() {
- try {
- ResultSet rs = Database.getInstance().getStatement().executeQuery("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`");
- while (rs.next()) new PlotMember(rs);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
-}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/DoorMaterial.java
similarity index 80%
rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java
rename to src/main/java/com/modnmetl/virtualrealty/model/material/DoorMaterial.java
index 1c9e466..4df87a3 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/DoorMaterial.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/material/DoorMaterial.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums.materials;
+package com.modnmetl.virtualrealty.model.material;
public enum DoorMaterial {
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/InteractMaterial.java
similarity index 97%
rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java
rename to src/main/java/com/modnmetl/virtualrealty/model/material/InteractMaterial.java
index 9850029..0fff730 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/material/InteractMaterial.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums.materials;
+package com.modnmetl.virtualrealty.model.material;
public enum InteractMaterial {
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/StorageMaterial.java
similarity index 91%
rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java
rename to src/main/java/com/modnmetl/virtualrealty/model/material/StorageMaterial.java
index 882855a..833f16c 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/StorageMaterial.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/material/StorageMaterial.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums.materials;
+package com.modnmetl.virtualrealty.model.material;
public enum StorageMaterial {
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java b/src/main/java/com/modnmetl/virtualrealty/model/material/SwitchMaterial.java
similarity index 90%
rename from src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java
rename to src/main/java/com/modnmetl/virtualrealty/model/material/SwitchMaterial.java
index c0bd071..be536b1 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/material/SwitchMaterial.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums.materials;
+package com.modnmetl.virtualrealty.model.material;
public enum SwitchMaterial {
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector2.java
similarity index 95%
rename from src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
rename to src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector2.java
index 2d3ff64..35f895d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector2.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.objects.math;
+package com.modnmetl.virtualrealty.model.math;
import org.bukkit.Location;
import org.bukkit.World;
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector3.java
similarity index 96%
rename from src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java
rename to src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector3.java
index d8acf26..4a073ea 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/math/BlockVector3.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.objects.math;
+package com.modnmetl.virtualrealty.model.math;
import org.bukkit.Location;
import org.bukkit.World;
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java b/src/main/java/com/modnmetl/virtualrealty/model/math/Direction.java
similarity index 90%
rename from src/main/java/com/modnmetl/virtualrealty/enums/Direction.java
rename to src/main/java/com/modnmetl/virtualrealty/model/math/Direction.java
index 772a253..07b3d02 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/math/Direction.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums;
+package com.modnmetl.virtualrealty.model.math;
public enum Direction {
@@ -18,7 +18,7 @@ public enum Direction {
public static Direction byYaw(float yaw) {
float absoluteYaw = Math.abs(yaw);
Direction direction = null;
- if(absoluteYaw > 315 || absoluteYaw <= 45) {
+ if (absoluteYaw > 315 || absoluteYaw <= 45) {
//south
direction = SOUTH;
} else if(absoluteYaw > 45 && absoluteYaw <= 135) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/model/other/ChatMessage.java b/src/main/java/com/modnmetl/virtualrealty/model/other/ChatMessage.java
new file mode 100644
index 0000000..db3381f
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/ChatMessage.java
@@ -0,0 +1,40 @@
+package com.modnmetl.virtualrealty.model.other;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.TextComponent;
+import org.bukkit.command.CommandSender;
+
+public class ChatMessage {
+
+ private final BaseComponent message;
+
+ private ChatMessage(BaseComponent message) {
+ this.message = message;
+ }
+
+ private ChatMessage(String message) {
+ this.message = new TextComponent(message);
+ }
+
+ public static ChatMessage of(String message) {
+ return new ChatMessage(message);
+ }
+
+ public static ChatMessage of(BaseComponent... messages) {
+ return new ChatMessage(new TextComponent(messages));
+ }
+
+ public static ChatMessage of(BaseComponent message) {
+ return new ChatMessage(message);
+ }
+
+ public void sendWithPrefix(CommandSender player) {
+ player.spigot().sendMessage(new TextComponent(VirtualRealty.PREFIX), message);
+ }
+
+ public void send(CommandSender player) {
+ player.spigot().sendMessage(message);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java b/src/main/java/com/modnmetl/virtualrealty/model/other/CommandType.java
similarity index 50%
rename from src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java
rename to src/main/java/com/modnmetl/virtualrealty/model/other/CommandType.java
index 5a85ab2..1a2f63f 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/CommandType.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums.commands;
+package com.modnmetl.virtualrealty.model.other;
public enum CommandType {
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java b/src/main/java/com/modnmetl/virtualrealty/model/other/Confirmation.java
similarity index 80%
rename from src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java
rename to src/main/java/com/modnmetl/virtualrealty/model/other/Confirmation.java
index 0509f6c..015e8bc 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/data/Confirmation.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/Confirmation.java
@@ -1,9 +1,7 @@
-package com.modnmetl.virtualrealty.objects.data;
+package com.modnmetl.virtualrealty.model.other;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.ConfirmationType;
-import com.modnmetl.virtualrealty.managers.ConfirmationManager;
-import com.modnmetl.virtualrealty.objects.Executable;
+import com.modnmetl.virtualrealty.manager.ConfirmationManager;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@@ -41,7 +39,7 @@ private void runExpiry() {
@Override
public void run() {
if (ConfirmationManager.isConfirmationAvailable(confirmationUUID)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().confirmationExpired);
+ ChatMessage.of(VirtualRealty.getMessages().confirmationExpired).sendWithPrefix(sender);
expiry();
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java b/src/main/java/com/modnmetl/virtualrealty/model/other/ConfirmationType.java
similarity index 62%
rename from src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java
rename to src/main/java/com/modnmetl/virtualrealty/model/other/ConfirmationType.java
index bd1e14a..a623dd2 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/ConfirmationType.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums;
+package com.modnmetl.virtualrealty.model.other;
public enum ConfirmationType {
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java b/src/main/java/com/modnmetl/virtualrealty/model/other/Executable.java
similarity index 65%
rename from src/main/java/com/modnmetl/virtualrealty/objects/Executable.java
rename to src/main/java/com/modnmetl/virtualrealty/model/other/Executable.java
index 1dfa53d..2311b04 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/Executable.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/Executable.java
@@ -1,11 +1,9 @@
-package com.modnmetl.virtualrealty.objects;
+package com.modnmetl.virtualrealty.model.other;
public interface Executable {
void success();
-
void failed();
-
void expiry();
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java b/src/main/java/com/modnmetl/virtualrealty/model/other/HighlightType.java
similarity index 58%
rename from src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java
rename to src/main/java/com/modnmetl/virtualrealty/model/other/HighlightType.java
index d9e3bb9..65af39b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/HighlightType.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums;
+package com.modnmetl.virtualrealty.model.other;
public enum HighlightType {
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java b/src/main/java/com/modnmetl/virtualrealty/model/other/ServerVersion.java
similarity index 53%
rename from src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java
rename to src/main/java/com/modnmetl/virtualrealty/model/other/ServerVersion.java
index 951ab5a..6586173 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/ServerVersion.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums;
+package com.modnmetl.virtualrealty.model.other;
public enum ServerVersion {
diff --git a/src/main/java/com/modnmetl/virtualrealty/model/other/VItem.java b/src/main/java/com/modnmetl/virtualrealty/model/other/VItem.java
new file mode 100644
index 0000000..6a412c7
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/VItem.java
@@ -0,0 +1,8 @@
+package com.modnmetl.virtualrealty.model.other;
+
+public enum VItem {
+
+ CLAIM,
+ DRAFT
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/model/other/WorldSetting.java b/src/main/java/com/modnmetl/virtualrealty/model/other/WorldSetting.java
new file mode 100644
index 0000000..fa9c755
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/model/other/WorldSetting.java
@@ -0,0 +1,10 @@
+package com.modnmetl.virtualrealty.model.other;
+
+public enum WorldSetting {
+
+ ALL,
+ INCLUDED,
+ EXCLUDED,
+
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java b/src/main/java/com/modnmetl/virtualrealty/model/permission/ManagementPermission.java
similarity index 90%
rename from src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java
rename to src/main/java/com/modnmetl/virtualrealty/model/permission/ManagementPermission.java
index 2267a22..81c51c1 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/permission/ManagementPermission.java
@@ -1,7 +1,7 @@
-package com.modnmetl.virtualrealty.enums.permissions;
+package com.modnmetl.virtualrealty.model.permission;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.utils.data.ItemBuilder;
+import com.modnmetl.virtualrealty.util.data.ItemBuilder;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/Permission.java b/src/main/java/com/modnmetl/virtualrealty/model/permission/Permission.java
similarity index 89%
rename from src/main/java/com/modnmetl/virtualrealty/enums/Permission.java
rename to src/main/java/com/modnmetl/virtualrealty/model/permission/Permission.java
index e84f66c..85f74ca 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/Permission.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/permission/Permission.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums;
+package com.modnmetl.virtualrealty.model.permission;
public enum Permission {
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java b/src/main/java/com/modnmetl/virtualrealty/model/permission/RegionPermission.java
similarity index 93%
rename from src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java
rename to src/main/java/com/modnmetl/virtualrealty/model/permission/RegionPermission.java
index fa33974..48db04a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/permission/RegionPermission.java
@@ -1,7 +1,7 @@
-package com.modnmetl.virtualrealty.enums.permissions;
+package com.modnmetl.virtualrealty.model.permission;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.utils.data.ItemBuilder;
+import com.modnmetl.virtualrealty.util.data.ItemBuilder;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/Plot.java
similarity index 74%
rename from src/main/java/com/modnmetl/virtualrealty/objects/Plot.java
rename to src/main/java/com/modnmetl/virtualrealty/model/plot/Plot.java
index 50b18ae..6298791 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/Plot.java
@@ -1,19 +1,17 @@
-package com.modnmetl.virtualrealty.objects;
+package com.modnmetl.virtualrealty.model.plot;
import com.modnmetl.virtualrealty.configs.PluginConfiguration;
-import com.modnmetl.virtualrealty.enums.Direction;
-import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.managers.DynmapManager;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.data.PlotMember;
-import com.modnmetl.virtualrealty.objects.region.Cuboid;
+import com.modnmetl.virtualrealty.model.math.Direction;
+import com.modnmetl.virtualrealty.model.permission.RegionPermission;
+import com.modnmetl.virtualrealty.manager.DynmapManager;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.region.Cuboid;
import com.modnmetl.virtualrealty.sql.Database;
-import com.modnmetl.virtualrealty.utils.EnumUtils;
-import com.modnmetl.virtualrealty.utils.data.OldSchematicUtil;
-import com.modnmetl.virtualrealty.utils.data.SchematicUtil;
+import com.modnmetl.virtualrealty.util.EnumUtils;
+import com.modnmetl.virtualrealty.util.data.OldSchematicUtil;
+import com.modnmetl.virtualrealty.util.data.SchematicUtil;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.objects.math.BlockVector3;
+import com.modnmetl.virtualrealty.model.math.BlockVector3;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
@@ -24,9 +22,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
+import java.sql.*;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
@@ -34,7 +30,7 @@
@Getter
@Setter
-public class Plot {
+public final class Plot {
public static final LocalDateTime MAX_DATE = LocalDateTime.of(2999, 12, 31, 0, 0);
public static final DateTimeFormatter PLOT_DATE_FORMAT = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
@@ -59,7 +55,7 @@ public class Plot {
private LocalDateTime createdAt;
public Plot(Location location, Material floorMaterial, Material borderMaterial, PlotSize plotSize, int length, int width, int height, boolean natural) {
- this.ID = PlotManager.getPlots().isEmpty() ? 10000 : PlotManager.getPlotMaxID() + 1;
+ this.ID = PlotManager.getInstance().getPlots().isEmpty() ? 10000 : PlotManager.getInstance().getPlotMaxID() + 1;
this.ownedBy = null;
this.members = new LinkedList<>();
this.nonMemberPermissions = new HashSet<>(VirtualRealty.getPermissions().getDefaultNonMemberPlotPerms());
@@ -85,9 +81,8 @@ public Plot(Location location, Material floorMaterial, Material borderMaterial,
this.width = width;
this.height = height;
initialize(natural);
- if (VirtualRealty.getDynmapManager() != null && VirtualRealty.getDynmapManager().markerset != null) {
+ if (VirtualRealty.getDynmapManager() != null && VirtualRealty.getDynmapManager().markerset != null)
DynmapManager.resetPlotMarker(this);
- }
}
@SneakyThrows
@@ -105,9 +100,14 @@ public Plot(ResultSet rs) {
this.assignedBy = rs.getString("assignedBy").equalsIgnoreCase("null") ? null : rs.getString("assignedBy");
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral(' ').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.SQLITE) {
- this.ownedUntilDate = LocalDateTime.parse(rs.getString("ownedUntilDate"), dateTimeFormatter);
- if (rs.getString("created") != null)
- this.createdAt = LocalDateTime.parse(rs.getString("created"), dateTimeFormatter);
+ this.ownedUntilDate = rs.getTimestamp("ownedUntilDate").toLocalDateTime();
+ if (rs.getString("created") != null) {
+ try {
+ this.createdAt = rs.getTimestamp("created").toLocalDateTime();
+ } catch (Exception ignored) {
+ this.createdAt = LocalDateTime.parse(rs.getString("created"), dateTimeFormatter);
+ }
+ }
} else {
this.ownedUntilDate = rs.getTimestamp("ownedUntilDate").toLocalDateTime();
if (rs.getTimestamp("created") != null)
@@ -173,11 +173,10 @@ public boolean hasMembershipAccess(UUID uuid) {
public void togglePermission(RegionPermission plotPermission) {
modified();
- if (nonMemberPermissions.contains(plotPermission)) {
+ if (nonMemberPermissions.contains(plotPermission))
nonMemberPermissions.remove(plotPermission);
- } else {
- nonMemberPermissions.add(plotPermission);
- }
+ else
+ nonMemberPermissions.add(plotPermission);
}
public boolean hasPermission(RegionPermission plotPermission) {
@@ -200,9 +199,9 @@ public PlotMember getMember(UUID uuid) {
}
public void addMember(UUID uuid) {
- PlotMember plotMember = new PlotMember(uuid, this);
- members.add(plotMember);
+ PlotMember plotMember = new PlotMember(uuid, this.getID());
plotMember.insert();
+ members.add(plotMember);
}
public void removeMember(PlotMember plotMember) {
@@ -210,33 +209,36 @@ public void removeMember(PlotMember plotMember) {
plotMember.delete();
}
+ public void removeAllMembers() {
+ for (PlotMember member : members) {
+ removeMember(member);
+ }
+ }
+
public boolean isOwnershipExpired() {
return ownedUntilDate.isBefore(LocalDateTime.now());
}
public int getXMin() {
- return Math.min(this.getBorderBottomLeftCorner().getBlockX(), this.borderTopRightCorner.getBlockX());
+ return Math.min(this.borderBottomLeftCorner.getBlockX(), this.borderTopRightCorner.getBlockX());
}
public int getXMax() {
- return Math.max(this.getBorderBottomLeftCorner().getBlockX(), this.borderTopRightCorner.getBlockX());
+ return Math.max(this.borderBottomLeftCorner.getBlockX(), this.borderTopRightCorner.getBlockX());
}
public int getZMin() {
- return Math.min(this.getBorderBottomLeftCorner().getBlockZ(), this.borderTopRightCorner.getBlockZ());
+ return Math.min(this.borderBottomLeftCorner.getBlockZ(), this.borderTopRightCorner.getBlockZ());
}
public int getZMax() {
- return Math.max(this.getBorderBottomLeftCorner().getBlockZ(), this.borderTopRightCorner.getBlockZ());
+ return Math.max(this.borderBottomLeftCorner.getBlockZ(), this.borderTopRightCorner.getBlockZ());
}
public void setOwnedBy(UUID ownedBy) {
modified();
this.ownedBy = ownedBy;
- PlotMember plotMember = getMember(ownedBy);
- if (plotMember != null) {
- removeMember(plotMember);
- }
+ removeAllMembers();
updateMarker();
}
@@ -253,21 +255,6 @@ public void setFloorMaterial(Material floorMaterial, byte data) {
initializeFloor();
}
- private void initializeFloor() {
- for (Block floorBlock : getFloorBlocks()) {
- floorBlock.setType(this.floorMaterial);
- if (VirtualRealty.legacyVersion) {
- try {
- Method m2 = Block.class.getDeclaredMethod("setData", byte.class);
- m2.setAccessible(true);
- m2.invoke(floorBlock, this.floorData);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
public void setBorderMaterial(Material borderMaterial, byte data) {
modified();
this.borderMaterial = borderMaterial;
@@ -304,6 +291,10 @@ public String getCreatedWorldString() {
return createdWorld;
}
+ public boolean isBorderLess() {
+ return this.borderMaterial == Material.AIR || this.plotSize == PlotSize.AREA;
+ }
+
public OfflinePlayer getPlotOwner() {
return ownedBy == null ? null : Bukkit.getOfflinePlayer(ownedBy);
}
@@ -365,8 +356,9 @@ public void prepareCorners() {
public void initialize(boolean natural) {
long time = System.currentTimeMillis();
prepareCorners();
- if (plotSize != PlotSize.AREA) prepareBlocks(createdLocation, natural);
- VirtualRealty.debug("Plot initialize time: " + (System.currentTimeMillis() - time) + " ms");
+ if (plotSize != PlotSize.AREA)
+ prepareRegion(createdLocation, natural);
+ VirtualRealty.debug("Plot initialization time: " + (System.currentTimeMillis() - time) + " ms");
}
public Set getBorderBlocks() {
@@ -467,7 +459,7 @@ public Set getFloorBlocks() {
return blocks;
}
- public void prepareBlocks(Location location, boolean natural) {
+ public void prepareRegion(Location location, boolean natural) {
Direction direction = Direction.byYaw(location.getYaw());
Location location1;
Location location2;
@@ -475,25 +467,25 @@ public void prepareBlocks(Location location, boolean natural) {
case SOUTH: {
location1 = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() - 1);
location2 = new Location(location.getWorld(), location.getBlockX() - width, location.getBlockY() + height, location.getBlockZ() + length);
- SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock()));
+ SchematicUtil.save(ID, location1.getBlock(), location2.getBlock());
break;
}
case WEST: {
location1 = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() + 1);
location2 = new Location(location.getWorld(), location.getBlockX() - length, location.getBlockY() + height, location.getBlockZ() - width);
- SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock()));
+ SchematicUtil.save(ID, location1.getBlock(), location2.getBlock());
break;
}
case NORTH: {
location1 = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() - 10, location.getBlockZ() + 1);
location2 = new Location(location.getWorld(), location.getBlockX() + width, location.getBlockY() + height, location.getBlockZ() - length);
- SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock()));
+ SchematicUtil.save(ID, location1.getBlock(), location2.getBlock());
break;
}
case EAST: {
location1 = new Location(location.getWorld(), location.getBlockX() + length, location.getBlockY() - 10, location.getBlockZ() - 1);
location2 = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() + height, location.getBlockZ() + width);
- SchematicUtil.save(ID, SchematicUtil.getStructure(location1.getBlock(), location2.getBlock()));
+ SchematicUtil.save(ID, location1.getBlock(), location2.getBlock());
break;
}
}
@@ -570,82 +562,138 @@ public void prepareBlocks(Location location, boolean natural) {
}
public void unloadPlot() {
- if (SchematicUtil.isOldSerialization(ID)) {
- long time = System.currentTimeMillis();
- Location location = null;
- switch (createdDirection) {
- case SOUTH: {
- location = new Location(getCreatedWorld(), createdLocation.getBlockX() - width, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1);
- break;
- }
- case WEST: {
- location = new Location(getCreatedWorld(), createdLocation.getBlockX() - length, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - width);
- break;
- }
- case NORTH: {
- location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - length);
- break;
- }
- case EAST: {
- location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1);
- break;
- }
- }
- OldSchematicUtil.paste(ID, location);
- VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms (Old Serialization)");
- } else {
- long time = System.currentTimeMillis();
+ if (!SchematicUtil.isOldSerialization(ID)) {
SchematicUtil.paste(ID);
- VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms");
+ return;
}
+ long time = System.currentTimeMillis();
+ Location location = null;
+ switch (createdDirection) {
+ case SOUTH: {
+ location = new Location(getCreatedWorld(), createdLocation.getBlockX() - width, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1);
+ break;
+ }
+ case WEST: {
+ location = new Location(getCreatedWorld(), createdLocation.getBlockX() - length, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - width);
+ break;
+ }
+ case NORTH: {
+ location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - length);
+ break;
+ }
+ case EAST: {
+ location = new Location(getCreatedWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1);
+ break;
+ }
+ }
+ OldSchematicUtil.paste(ID, location);
+ VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms [old-serialization]");
}
private void modified() {
modified = Instant.now();
}
- @SneakyThrows
- public void insert() {
- String serializedLocation =
- Objects.requireNonNull(this.getCreatedWorld()).getName() + ";" +
- this.createdLocation.getX() + ";" +
- this.createdLocation.getY() + ";" +
- this.createdLocation.getZ() + ";" +
- this.createdLocation.getYaw() + ";" +
- this.createdLocation.getPitch() + ";";
+ private void initializeFloor() {
+ for (Block floorBlock : getFloorBlocks()) {
+ floorBlock.setType(this.floorMaterial);
+ if (VirtualRealty.legacyVersion) {
+ try {
+ Method m2 = Block.class.getDeclaredMethod("setData", byte.class);
+ m2.setAccessible(true);
+ m2.invoke(floorBlock, this.floorData);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private String getNonMemberPermissionsString() {
StringBuilder permissions = new StringBuilder();
for (RegionPermission permission : this.nonMemberPermissions) {
permissions.append(permission.name()).append("¦");
}
- Database.getInstance().getStatement().execute("INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName +
- "` (`ID`, `ownedBy`, `nonMemberPermissions`, `assignedBy`, `ownedUntilDate`, `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`, `createdLocation`, `created`, `modified`, `selectedGameMode`) " +
- "VALUES ('" + this.ID + "', '" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "', '" + permissions + "', '" + this.assignedBy + "', '" + Timestamp.valueOf(this.ownedUntilDate) + "', '" +
- this.floorMaterial + ":" + this.floorData + "', '" + this.borderMaterial + ":" + this.borderData + "', '" + this.plotSize + "', '" + this.length + "', '" + this.width + "', '" +
- this.height + "', '" + serializedLocation + "', '" + Timestamp.from(Instant.now()) + "', '" + Timestamp.from(Instant.now()) + "', '" + this.selectedGameMode.name()
- + "')");
+ return permissions.toString();
+ }
+
+ private String getSerializedCreatedLocation() {
+ return Objects.requireNonNull(this.getCreatedWorld()).getName() + ";" +
+ this.createdLocation.getX() + ";" +
+ this.createdLocation.getY() + ";" +
+ this.createdLocation.getZ() + ";" +
+ this.createdLocation.getYaw() + ";" +
+ this.createdLocation.getPitch() + ";";
+ }
+
+ @SneakyThrows
+ public void insert() {
+ try (Connection conn = Database.getInstance().getConnection();
+ PreparedStatement ps = conn.prepareStatement(
+ "INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName +
+ "` (`ID`, `ownedBy`, `nonMemberPermissions`, `assignedBy`, `ownedUntilDate`," +
+ " `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`," +
+ " `createdLocation`, `created`, `modified`, `selectedGameMode`) " +
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
+ )) {
+ ps.setInt(1, this.ID);
+ ps.setString(2, (this.ownedBy == null ? "" : this.ownedBy.toString()));
+ ps.setString(3, getNonMemberPermissionsString());
+ ps.setString(4, (this.assignedBy == null ? "null" : this.assignedBy));
+ ps.setTimestamp(5, Timestamp.valueOf(this.ownedUntilDate));
+ ps.setString(6, this.floorMaterial + ":" + this.floorData);
+ ps.setString(7, this.borderMaterial + ":" + this.borderData);
+ ps.setString(8, this.plotSize.toString());
+ ps.setInt(9, this.length);
+ ps.setInt(10, this.width);
+ ps.setInt(11, this.height);
+ ps.setString(12, getSerializedCreatedLocation());
+ ps.setTimestamp(13, Timestamp.from(Instant.now()));
+ ps.setTimestamp(14, Timestamp.from(Instant.now()));
+ ps.setString(15, this.selectedGameMode.name());
+ ps.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
@SneakyThrows
public void update() {
- StringBuilder permissions = new StringBuilder();
- for (RegionPermission permission : this.nonMemberPermissions) {
- permissions.append(permission.name()).append("¦");
+ try (Connection conn = Database.getInstance().getConnection();
+ PreparedStatement ps = conn.prepareStatement(
+ "UPDATE `" +
+ VirtualRealty.getPluginConfiguration().mysql.plotsTableName +
+ "` SET `ownedBy`= ?," +
+ " `nonMemberPermissions`= ?," +
+ " `assignedBy`= ?," +
+ " `ownedUntilDate`= ?," +
+ " `floorMaterial`= ?," +
+ " `borderMaterial`= ?," +
+ " `plotSize`= ?," +
+ " `length`= ?," +
+ " `width`= ?," +
+ " `height`= ?," +
+ " `modified`= ?," +
+ " `selectedGameMode`= ?" +
+ " WHERE `ID`= ?"
+ )) {
+ ps.setString(1, (this.ownedBy == null ? "" : this.ownedBy.toString()));
+ ps.setString(2, getNonMemberPermissionsString());
+ ps.setString(3, (this.assignedBy == null ? "null" : this.assignedBy));
+ ps.setTimestamp(4, Timestamp.valueOf(this.ownedUntilDate));
+ ps.setString(5, this.floorMaterial + ":" + this.floorData);
+ ps.setString(6, this.borderMaterial + ":" + this.borderData);
+ ps.setString(7, this.plotSize.toString());
+ ps.setInt(8, this.length);
+ ps.setInt(9, this.width);
+ ps.setInt(10, this.height);
+ ps.setTimestamp(11, (this.modified != null ? Timestamp.from(this.modified) : Timestamp.from(Instant.now())));
+ ps.setString(12, this.selectedGameMode.name());
+ ps.setInt(13, this.ID);
+ ps.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
}
- Database.getInstance().getStatement().execute("UPDATE `" +
- VirtualRealty.getPluginConfiguration().mysql.plotsTableName +
- "` SET `ownedBy`='" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "'," +
- " `nonMemberPermissions`='" + permissions + "'," +
- " `assignedBy`='" + this.assignedBy + "'," +
- " `ownedUntilDate`='" + Timestamp.valueOf(this.ownedUntilDate) + "'," +
- " `floorMaterial`='" + this.floorMaterial + ":" + this.floorData + "'," +
- " `borderMaterial`='" + this.borderMaterial + ":" + this.borderData + "'," +
- " `plotSize`='" + this.plotSize + "'," +
- " `length`='" + this.length + "'," +
- " `width`='" + this.width + "'," +
- " `height`='" + this.height + "'," +
- " `modified`='" + (this.modified != null ? Timestamp.from(this.modified) : Timestamp.from(Instant.now())) + "'," +
- " `selectedGameMode`='" + this.selectedGameMode.name() + "'" +
- " WHERE `ID`='" + this.ID + "'");
}
public void remove(CommandSender sender) {
@@ -657,18 +705,20 @@ public void remove(CommandSender sender) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noRegionFileFound);
}
}
- for (PlotMember member : this.getMembers()) {
- removeMember(member);
- }
+ removeAllMembers();
if (VirtualRealty.getDynmapManager() != null) {
DynmapManager.removeDynMapMarker(this);
}
- try {
- Database.getInstance().getStatement().execute("DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` WHERE `ID` = '" + ID + "';");
- } catch (SQLException e) {
+ try (Connection conn = Database.getInstance().getConnection();
+ PreparedStatement ps = conn.prepareStatement(
+ "DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` WHERE `ID` = ?"
+ )) {
+ ps.setInt(1, this.ID);
+ ps.execute();
+ } catch (Exception e) {
e.printStackTrace();
}
- PlotManager.removePlotFromList(this);
+ PlotManager.getInstance().removePlotFromCollection(this);
VirtualRealty.debug("Removed plot #" + this.ID);
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotItem.java
similarity index 90%
rename from src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java
rename to src/main/java/com/modnmetl/virtualrealty/model/plot/PlotItem.java
index 3c975c8..5a5704f 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotItem.java
@@ -1,10 +1,9 @@
-package com.modnmetl.virtualrealty.objects.data;
+package com.modnmetl.virtualrealty.model.plot;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.PlotSize;
-import com.modnmetl.virtualrealty.enums.items.VItem;
-import com.modnmetl.virtualrealty.utils.data.ItemBuilder;
-import com.modnmetl.virtualrealty.utils.data.SkullUtil;
+import com.modnmetl.virtualrealty.model.other.VItem;
+import com.modnmetl.virtualrealty.util.data.ItemBuilder;
+import com.modnmetl.virtualrealty.util.data.SkullUtil;
import de.tr7zw.nbtapi.NBTItem;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -38,12 +37,9 @@ public class PlotItem {
private UUID uuid;
public ItemStack getItemStack() {
- ItemBuilder itemBuilder;
- if (uuid == null) {
- itemBuilder = new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b"));
- } else {
- itemBuilder = new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b", uuid));
- }
+ ItemBuilder itemBuilder = (uuid == null)
+ ? new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b"))
+ : new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b", uuid));
switch (itemType) {
case CLAIM: {
itemBuilder
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotMember.java
similarity index 58%
rename from src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java
rename to src/main/java/com/modnmetl/virtualrealty/model/plot/PlotMember.java
index 7abf8f4..24f3b21 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotMember.java
@@ -1,16 +1,16 @@
-package com.modnmetl.virtualrealty.objects.data;
+package com.modnmetl.virtualrealty.model.plot;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission;
-import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.model.permission.ManagementPermission;
+import com.modnmetl.virtualrealty.model.permission.RegionPermission;
+import com.modnmetl.virtualrealty.manager.PlotManager;
import com.modnmetl.virtualrealty.sql.Database;
import lombok.Data;
-import lombok.Setter;
import lombok.SneakyThrows;
import org.bukkit.GameMode;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set;
@@ -20,15 +20,16 @@
public class PlotMember {
private final UUID uuid;
- private final Plot plot;
+
+ private final int plotId;
private GameMode selectedGameMode;
private final Set permissions;
private final Set managementPermissions;
- public PlotMember(UUID uuid, Plot plot) {
+ public PlotMember(UUID uuid, int plotId) {
this.uuid = uuid;
- this.plot = plot;
- this.selectedGameMode = plot.getSelectedGameMode();
+ this.plotId = plotId;
+ this.selectedGameMode = getPlot().getSelectedGameMode();
this.permissions = new HashSet<>(VirtualRealty.getPermissions().getDefaultMemberPerms());
this.managementPermissions = new HashSet<>();
}
@@ -36,8 +37,7 @@ public PlotMember(UUID uuid, Plot plot) {
@SneakyThrows
public PlotMember(ResultSet rs) {
this.uuid = UUID.fromString(rs.getString("uuid"));
- Plot plot = PlotManager.getPlot(rs.getInt("plot"));
- this.plot = plot;
+ this.plotId = rs.getInt("plot");
this.selectedGameMode = GameMode.valueOf(rs.getString("selectedGameMode"));
Set plotPermissions = new HashSet<>();
if (!rs.getString("permissions").isEmpty()) {
@@ -53,8 +53,12 @@ public PlotMember(ResultSet rs) {
}
}
this.managementPermissions = managementPermissions;
- if (plot != null)
- plot.members.add(this);
+ if (getPlot() != null)
+ getPlot().members.add(this);
+ }
+
+ public Plot getPlot() {
+ return PlotManager.getInstance().getPlot(this.plotId);
}
public void togglePermission(RegionPermission plotPermission) {
@@ -109,10 +113,21 @@ public void insert() {
for (ManagementPermission permission : this.managementPermissions) {
managementPermissions.append(permission.name()).append("¦");
}
- Database.getInstance().getStatement().execute("INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName +
- "` (`uuid`, `plot`, `selectedGameMode`, `permissions`, `managementPermissions`) " +
- "VALUES ('" + this.uuid.toString() + "', '" + this.plot.getID() + "', '" + this.getSelectedGameMode().name() + "', '" + permissions + "', '" + managementPermissions
- + "')");
+ try (Connection conn = Database.getInstance().getConnection();
+ PreparedStatement ps = conn.prepareStatement(
+ "INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName +
+ "` (`uuid`, `plot`, `selectedGameMode`, `permissions`, `managementPermissions`) " +
+ "VALUES (?, ?, ?, ?, ?)"
+ )) {
+ ps.setString(1, this.uuid.toString());
+ ps.setInt(2, this.plotId);
+ ps.setString(3, this.getSelectedGameMode().name());
+ ps.setString(4, permissions.toString());
+ ps.setString(5, managementPermissions.toString());
+ ps.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
@SneakyThrows
@@ -125,17 +140,39 @@ public void update() {
for (ManagementPermission permission : this.managementPermissions) {
managementPermissions.append(permission.name()).append("¦");
}
- Database.getInstance().getStatement().execute("UPDATE `" +
- VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName +
- "` SET `permissions`='" + permissions + "'," +
- "`managementPermissions`='" + managementPermissions + "'," +
- "`selectedGameMode`='" + selectedGameMode.name() + "'" +
- " WHERE `uuid`='" + this.uuid.toString() + "' AND `plot`='" + this.plot.getID() + "'");
+ try (Connection conn = Database.getInstance().getConnection();
+ PreparedStatement ps = conn.prepareStatement(
+ "UPDATE `" +
+ VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName +
+ "` SET `permissions`= ?," +
+ "`managementPermissions`= ?," +
+ "`selectedGameMode`= ?" +
+ " WHERE `uuid`= ? AND `plot`= ?"
+ )) {
+ ps.setString(1, permissions.toString());
+ ps.setString(2, managementPermissions.toString());
+ ps.setString(3, selectedGameMode.name());
+ ps.setString(4, this.uuid.toString());
+ ps.setInt(5, this.plotId);
+ ps.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
@SneakyThrows
public void delete() {
- Database.getInstance().getStatement().execute("DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "` WHERE `uuid` = '" + this.uuid + "' AND `plot`=" + plot.getID() + ";");
+ try (Connection conn = Database.getInstance().getConnection();
+ PreparedStatement ps = conn.prepareStatement(
+ "DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`" +
+ " WHERE `uuid` = ? AND `plot` = ?"
+ )) {
+ ps.setString(1, this.uuid.toString());
+ ps.setInt(2, this.plotId);
+ ps.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotSize.java
similarity index 98%
rename from src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java
rename to src/main/java/com/modnmetl/virtualrealty/model/plot/PlotSize.java
index d35eadf..fa9e28e 100644
--- a/src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/plot/PlotSize.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.enums;
+package com.modnmetl.virtualrealty.model.plot;
import com.modnmetl.virtualrealty.VirtualRealty;
import lombok.Data;
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java b/src/main/java/com/modnmetl/virtualrealty/model/region/Cuboid.java
similarity index 96%
rename from src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
rename to src/main/java/com/modnmetl/virtualrealty/model/region/Cuboid.java
index f5d6b6b..a923e03 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/region/Cuboid.java
@@ -1,13 +1,10 @@
-package com.modnmetl.virtualrealty.objects.region;
+package com.modnmetl.virtualrealty.model.region;
-import com.modnmetl.virtualrealty.objects.math.BlockVector2;
-import com.modnmetl.virtualrealty.objects.math.BlockVector3;
-import org.bukkit.Bukkit;
+import com.modnmetl.virtualrealty.model.math.BlockVector2;
+import com.modnmetl.virtualrealty.model.math.BlockVector3;
import org.bukkit.Location;
-import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
-import org.bukkit.entity.Player;
import java.util.*;
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java b/src/main/java/com/modnmetl/virtualrealty/model/region/GridStructure.java
similarity index 77%
rename from src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java
rename to src/main/java/com/modnmetl/virtualrealty/model/region/GridStructure.java
index 1537d2b..58e6e9a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/region/GridStructure.java
@@ -1,12 +1,11 @@
-package com.modnmetl.virtualrealty.objects.region;
+package com.modnmetl.virtualrealty.model.region;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.Direction;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.math.BlockVector2;
-import com.modnmetl.virtualrealty.utils.VectorUtils;
-import com.modnmetl.virtualrealty.utils.data.VirtualBlock;
+import com.modnmetl.virtualrealty.model.math.Direction;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.math.BlockVector2;
+import com.modnmetl.virtualrealty.util.VectorUtils;
import lombok.Data;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
@@ -23,6 +22,8 @@
@Data
public class GridStructure {
+ public static final long DISPLAY_TICKS = 20 * 10;
+
public static final HashMap> ACTIVE_GRIDS = new HashMap<>();
private final Player viewer;
@@ -31,7 +32,7 @@ public class GridStructure {
private int height;
private int width;
private int cuboidId;
- private final Set changedBlocks;
+ private final List changedBlocks;
private final String world;
private boolean displayingBlocks;
private long displayTicks;
@@ -46,7 +47,7 @@ public GridStructure(Player viewer, int length, int height, int width, int cuboi
this.height = height;
this.width = width;
this.cuboidId = cuboidId;
- this.changedBlocks = new HashSet<>();
+ this.changedBlocks = new ArrayList<>();
this.world = world.getName();
this.displayTicks = displayTicks;
this.previewLocation = previewLocation;
@@ -69,7 +70,7 @@ public void preview(Location playerPreviewLocation, boolean visualization, boole
if (!VirtualRealty.legacyVersion)
maxDistance = viewer.getClientViewDistance() * 16;
changedBlocks.clear();
- Plot plot = PlotManager.getPlot(cuboidId);
+ Plot plot = PlotManager.getInstance().getPlot(cuboidId);
LinkedList blocks = new LinkedList<>();
LinkedList borderBlocks = new LinkedList<>();
Direction direction = Direction.byYaw(previewLocation.getYaw());
@@ -109,10 +110,7 @@ public void preview(Location playerPreviewLocation, boolean visualization, boole
default:
throw new IllegalStateException("Unexpected value: " + direction);
}
- Location distanceCalculateLoc = previewLocation;
- if (playerPreviewLocation != null) {
- distanceCalculateLoc = playerPreviewLocation;
- }
+ Location distanceCalculateLoc = playerPreviewLocation != null ? playerPreviewLocation : previewLocation;
for (int x = minX - 1; x < maxX; x++) {
for (int z = minZ; z < maxZ; z++) {
if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) {
@@ -210,33 +208,47 @@ public void run() {
@SneakyThrows
public void removeGrid() {
+ List newBlocks = new ArrayList<>();
for (VirtualBlock changedBlock : changedBlocks) {
- Block changedBukkitBlock = changedBlock.getBlock(getCreatedWorld());
- if (VirtualRealty.legacyVersion) {
- viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getType(), changedBukkitBlock.getData());
- } else {
- viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getBlockData());
- }
+ newBlocks.add(changedBlock.getBlock(getCreatedWorld()));
}
+ Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> {
+ for (Block block : newBlocks) {
+ if (VirtualRealty.legacyVersion) {
+ viewer.sendBlockChange(block.getLocation(), block.getType(), block.getData());
+ } else {
+ viewer.sendBlockChange(block.getLocation(), block.getBlockData());
+ }
+ }
+ });
}
private void swapBlocks(LinkedList blocks, boolean collidingArea) {
- Plot plot = PlotManager.getPlot(previewLocation);
- for (Block block : blocks) {
- Location blockLocation = block.getLocation();
- VirtualBlock convertedBlock;
- if (VirtualRealty.legacyVersion) {
- convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getType().getId(), block.getData());
- viewer.sendBlockChange(blockLocation, Objects.requireNonNull(Material.matchMaterial("STAINED_GLASS")), ((plot != null && plot.getID() == cuboidId) ? (byte)1 : collidingArea ? (byte)14 : (byte)5));
- } else {
- convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getBlockData().getAsString());
- BlockData greenBlockData = Material.LIME_STAINED_GLASS.createBlockData();
- BlockData redBlockData = Material.RED_STAINED_GLASS.createBlockData();
- BlockData orangeBlockData = Material.ORANGE_STAINED_GLASS.createBlockData();
- viewer.sendBlockChange(blockLocation, ((plot != null && plot.getID() == cuboidId) ? orangeBlockData : collidingArea ? redBlockData : greenBlockData));
+ Plot plot = PlotManager.getInstance().getPlot(previewLocation);
+ Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> {
+ for (Block block : blocks) {
+ Location blockLocation = block.getLocation();
+ VirtualBlock convertedBlock;
+ if (VirtualRealty.legacyVersion) {
+ convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getType().getId(), block.getData());
+ viewer.sendBlockChange(
+ blockLocation,
+ Objects.requireNonNull(Material.matchMaterial("STAINED_GLASS")),
+ ((plot != null && plot.getID() == cuboidId) ? (byte) 1 : collidingArea ? (byte) 14 : (byte) 5)
+ );
+ } else {
+ convertedBlock = new VirtualBlock(block.getX(), block.getY(), block.getZ(), block.getBlockData().getAsString());
+ BlockData greenBlockData = Material.LIME_STAINED_GLASS.createBlockData();
+ BlockData redBlockData = Material.RED_STAINED_GLASS.createBlockData();
+ BlockData orangeBlockData = Material.ORANGE_STAINED_GLASS.createBlockData();
+ viewer.sendBlockChange(
+ blockLocation,
+ ((plot != null && plot.getID() == cuboidId) ? orangeBlockData : collidingArea ? redBlockData : greenBlockData)
+ );
+ }
+ changedBlocks.add(convertedBlock);
}
- changedBlocks.add(convertedBlock);
- }
+ });
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualBlock.java
similarity index 75%
rename from src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java
rename to src/main/java/com/modnmetl/virtualrealty/model/region/VirtualBlock.java
index 782f893..e976a3a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java
+++ b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualBlock.java
@@ -1,16 +1,10 @@
-package com.modnmetl.virtualrealty.utils.data;
+package com.modnmetl.virtualrealty.model.region;
import lombok.Data;
-import lombok.Getter;
-import lombok.Setter;
-import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.InflaterInputStream;
@Data
public class VirtualBlock implements Serializable {
diff --git a/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualLocation.java b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualLocation.java
new file mode 100644
index 0000000..ba41fbd
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/model/region/VirtualLocation.java
@@ -0,0 +1,27 @@
+package com.modnmetl.virtualrealty.model.region;
+
+import lombok.Data;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+
+import java.io.Serializable;
+
+@Data
+public class VirtualLocation implements Serializable {
+
+ private int x;
+ private int y;
+ private int z;
+
+ public VirtualLocation(int x, int y, int z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public Block getBlock(World world) {
+ return world.getBlockAt(x,y,z);
+ }
+
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java
index 2a929a9..86f5246 100644
--- a/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java
+++ b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java
@@ -1,9 +1,9 @@
package com.modnmetl.virtualrealty.registry;
-import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.manager.PlotManager;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.model.plot.Plot;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -101,7 +101,7 @@ public boolean canRegister(){
public String onPlaceholderRequest(Player player, @NotNull String identifier){
if(player == null) return "";
- Plot plot = PlotManager.getBorderedPlot(player.getLocation());
+ Plot plot = PlotManager.getInstance().getPlot(player.getLocation());
if (identifier.equals("plot_id")) {
if (plot == null) return "";
return String.valueOf(plot.getID());
diff --git a/src/main/java/com/modnmetl/virtualrealty/sql/Database.java b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
index b422b4a..43d2776 100644
--- a/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
+++ b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
@@ -4,12 +4,14 @@
import com.modnmetl.virtualrealty.configs.PluginConfiguration;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
+import lombok.SneakyThrows;
import org.sqlite.SQLiteDataSource;
import javax.sql.DataSource;
import java.io.File;
import java.io.PrintWriter;
import java.sql.Connection;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
@@ -23,21 +25,14 @@ public class Database {
@Getter
private final DataSource dataSource;
- @Getter
- private final Connection connection;
- @Getter
- private final Statement statement;
- public Database(File file) throws SQLException {
+ public Database(File file) {
dataModel = VirtualRealty.getPluginConfiguration().dataModel;
SQLiteDataSource sqLiteDataSource = new SQLiteDataSource();
sqLiteDataSource.setUrl("jdbc:sqlite:" + file.getAbsolutePath());
dataSource = sqLiteDataSource;
- connection = dataSource.getConnection();
- statement = connection.createStatement();
instance = this;
createTables();
- updateTables();
}
public Database(String hostname, int port, String username, String password, String database) throws SQLException {
@@ -50,65 +45,34 @@ public Database(String hostname, int port, String username, String password, Str
hikariDataSource.setPassword(password);
}
dataSource.setLogWriter(new PrintWriter(System.out));
- connection = dataSource.getConnection();
- statement = connection.createStatement();
instance = this;
createTables();
- updateTables();
}
- private void createTables() {
- try {
- statement.execute("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID` INT(12) NOT NULL, `ownedBy` VARCHAR(36) NOT NULL, `nonMemberPermissions` TEXT NOT NULL, `assignedBy` VARCHAR(36) NOT NULL, `ownedUntilDate` DATETIME NOT NULL, `floorMaterial` VARCHAR(32) NOT NULL, `borderMaterial` VARCHAR(32) NOT NULL, `plotSize` VARCHAR(32) NOT NULL, `length` INT(24) NOT NULL, `width` INT(24) NOT NULL, `height` INT(24) NOT NULL, `createdLocation` TEXT(500) NOT NULL, `created` DATETIME, `modified` DATETIME, `selectedGameMode` TEXT, PRIMARY KEY(`ID`))");
- statement.execute("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "` (`uuid` VARCHAR(36) NOT NULL, `plot` INT(11) NOT NULL, `selectedGameMode` TEXT NOT NULL, `permissions` TEXT NOT NULL, `managementPermissions` TEXT NOT NULL)");
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
+ @SneakyThrows
+ public Connection getConnection() {
+ return dataSource.getConnection();
}
- private void updateTables() {
- if (dataModel == PluginConfiguration.DataModel.MYSQL) {
- try {
- statement.execute("ALTER TABLE IF EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `borderMaterial` VARCHAR(32) AFTER `floorMaterial`;");
- } catch (SQLException ignored) {}
- try {
- statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` DROP `members`;");
- } catch (SQLException ignored) {}
- try {
- statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `created` DATETIME AFTER `createdLocation`;");
- } catch (SQLException ignored) {}
- try {
- statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `modified` DATETIME AFTER `created`;");
- } catch (SQLException ignored) {}
- try {
- statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `selectedGameMode` TEXT;");
- } catch (SQLException ignored) {}
- try {
- statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` ADD `nonMemberPermissions` TEXT NOT NULL AFTER `ownedBy`;");
- } catch (SQLException ignored) {}
+
+ private void createTables() {
+ try (Connection conn = getConnection();
+ PreparedStatement ps = conn.prepareStatement("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID` INT(12) NOT NULL, `ownedBy` VARCHAR(36) NOT NULL, `nonMemberPermissions` TEXT NOT NULL, `assignedBy` VARCHAR(36) NOT NULL, `ownedUntilDate` DATETIME NOT NULL, `floorMaterial` VARCHAR(32) NOT NULL, `borderMaterial` VARCHAR(32) NOT NULL, `plotSize` VARCHAR(32) NOT NULL, `length` INT(24) NOT NULL, `width` INT(24) NOT NULL, `height` INT(24) NOT NULL, `createdLocation` TEXT(500) NOT NULL, `created` DATETIME, `modified` DATETIME, `selectedGameMode` TEXT, PRIMARY KEY(`ID`))")) {
+ ps.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
}
- if (dataModel == PluginConfiguration.DataModel.SQLITE) {
- try {
- statement.execute("SELECT `nonMemberPermissions` FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "`");
- } catch (SQLException ex) {
- try {
- statement.execute("ALTER TABLE `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` RENAME TO `_" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "_old`;");
- createTables();
- statement.execute("INSERT INTO `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID`, `ownedBy`, `nonMemberPermissions`, `assignedBy`, `ownedUntilDate`, `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`, `createdLocation`, `created`, `modified`, `selectedGameMode`)" +
- " SELECT `ID`, `ownedBy`, '" + "" + "', `assignedBy`, `ownedUntilDate`, `floorMaterial`, `borderMaterial`, `plotSize`, `length`, `width`, `height`, `createdLocation`, `created`, `modified`, '" + "" + "'" +
- " FROM _" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "_old;");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
+ try (Connection conn = getConnection();
+ PreparedStatement ps = conn.prepareStatement("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "` (`uuid` VARCHAR(36) NOT NULL, `plot` INT(11) NOT NULL, `selectedGameMode` TEXT NOT NULL, `permissions` TEXT NOT NULL, `managementPermissions` TEXT NOT NULL)")) {
+ ps.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
public static void connectToDatabase(File databaseFile) throws SQLException {
- if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.SQLITE) {
- new Database(databaseFile);
- }
- if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.MYSQL) {
+ if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.SQLITE) new Database(databaseFile);
+ if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.MYSQL)
new Database(
VirtualRealty.getPluginConfiguration().mysql.hostname,
VirtualRealty.getPluginConfiguration().mysql.port,
@@ -116,7 +80,6 @@ public static void connectToDatabase(File databaseFile) throws SQLException {
VirtualRealty.getPluginConfiguration().mysql.password,
VirtualRealty.getPluginConfiguration().mysql.database
);
- }
VirtualRealty.debug("Connected to database");
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java b/src/main/java/com/modnmetl/virtualrealty/util/EnumUtils.java
similarity index 84%
rename from src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java
rename to src/main/java/com/modnmetl/virtualrealty/util/EnumUtils.java
index 03f2181..e244f66 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/EnumUtils.java
@@ -1,6 +1,6 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util;
-public class EnumUtils {
+public final class EnumUtils {
public static > boolean isValidEnum(Class enumClass, String enumName) {
if (enumName == null) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java b/src/main/java/com/modnmetl/virtualrealty/util/PermissionsUtil.java
similarity index 63%
rename from src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java
rename to src/main/java/com/modnmetl/virtualrealty/util/PermissionsUtil.java
index d1cc936..c33633c 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/PermissionsUtil.java
@@ -1,15 +1,15 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util;
-import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.model.other.ChatMessage;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
-public class Permissions {
+public final class PermissionsUtil {
public static boolean hasPermission(CommandSender sender, Permission basePermission, String permission) {
Permission finalPermission = new Permission(basePermission.getName() + "." + permission);
if (!sender.hasPermission(finalPermission)) {
- sender.sendMessage(VirtualRealty.PREFIX + "§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)");
+ ChatMessage.of("§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)").sendWithPrefix(sender);
return false;
}
return true;
@@ -18,7 +18,7 @@ public static boolean hasPermission(CommandSender sender, Permission basePermiss
public static boolean hasPermission(CommandSender sender, String permission) {
Permission finalPermission = new Permission(permission);
if (!sender.hasPermission(finalPermission)) {
- sender.sendMessage(VirtualRealty.PREFIX + "§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)");
+ ChatMessage.of("§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)").sendWithPrefix(sender);
return false;
}
return true;
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/RegionUtil.java
similarity index 86%
rename from src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
rename to src/main/java/com/modnmetl/virtualrealty/util/RegionUtil.java
index f8a61b4..696a2e4 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/RegionUtil.java
@@ -1,17 +1,17 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.Direction;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.math.BlockVector2;
-import com.modnmetl.virtualrealty.objects.region.Cuboid;
-import com.modnmetl.virtualrealty.objects.math.BlockVector3;
+import com.modnmetl.virtualrealty.model.math.Direction;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.math.BlockVector2;
+import com.modnmetl.virtualrealty.model.region.Cuboid;
+import com.modnmetl.virtualrealty.model.math.BlockVector3;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
-public class RegionUtil {
+public final class RegionUtil {
public static Cuboid getRegion(Location location, Direction direction, int length, int height, int width) {
Location location1;
@@ -53,7 +53,7 @@ public static boolean isCollidingWithBedrock(Cuboid cuboid) {
public static boolean isCollidingWithAnotherPlot(Cuboid cuboid) {
long time = System.currentTimeMillis();
- for (Plot plot : PlotManager.getPlots(cuboid.getWorld().getName())) {
+ for (Plot plot : PlotManager.getInstance().getPlots(cuboid.getWorld().getName())) {
for (BlockVector2 blockVector2 : plot.getCuboid().getFlatRegion()) {
if (cuboid.isIn(blockVector2, cuboid.getWorld(), VirtualRealty.getPluginConfiguration().plotSpacing)) {
VirtualRealty.debug("Collision checked! (Found) " + (System.currentTimeMillis() - time) + " ms | Spacing: " + VirtualRealty.getPluginConfiguration().plotSpacing);
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java b/src/main/java/com/modnmetl/virtualrealty/util/UUIDUtils.java
similarity index 77%
rename from src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java
rename to src/main/java/com/modnmetl/virtualrealty/util/UUIDUtils.java
index f39d2a8..410afee 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/UUIDUtils.java
@@ -1,8 +1,8 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util;
import java.util.UUID;
-public class UUIDUtils {
+public final class UUIDUtils {
public static boolean isValidUUID(String uuidString) {
try {
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java b/src/main/java/com/modnmetl/virtualrealty/util/UpdateChecker.java
similarity index 95%
rename from src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java
rename to src/main/java/com/modnmetl/virtualrealty/util/UpdateChecker.java
index 052b0f4..5895ce0 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/UpdateChecker.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -9,7 +9,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
-public class UpdateChecker {
+public final class UpdateChecker {
private static final String VERSION_URL = "https://api.spiget.org/v2/resources/95599/versions/latest";
private static final String DESCRIPTION_URL = "https://api.spiget.org/v2/resources/95599/updates/latest";
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java b/src/main/java/com/modnmetl/virtualrealty/util/VectorUtils.java
similarity index 77%
rename from src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java
rename to src/main/java/com/modnmetl/virtualrealty/util/VectorUtils.java
index bf5643a..71d1f4d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/VectorUtils.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/VectorUtils.java
@@ -1,9 +1,9 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util;
-import com.modnmetl.virtualrealty.objects.math.BlockVector2;
+import com.modnmetl.virtualrealty.model.math.BlockVector2;
import org.bukkit.util.NumberConversions;
-public class VectorUtils {
+public final class VectorUtils {
public static double distance(BlockVector2 vector, BlockVector2 vector2) {
return Math.sqrt(distanceSquared(vector, vector2));
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/WorldUtil.java
similarity index 87%
rename from src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java
rename to src/main/java/com/modnmetl/virtualrealty/util/WorldUtil.java
index 98a6ca8..bdc51a5 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/WorldUtil.java
@@ -1,11 +1,11 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
+import com.modnmetl.virtualrealty.model.permission.RegionPermission;
import java.util.List;
-public class WorldUtil {
+public final class WorldUtil {
public static List getWorldPermissions() {
return VirtualRealty.getPermissions().getWorldProtection();
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java b/src/main/java/com/modnmetl/virtualrealty/util/configuration/ConfigurationFactory.java
similarity index 80%
rename from src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java
rename to src/main/java/com/modnmetl/virtualrealty/util/configuration/ConfigurationFactory.java
index 8fa76f8..976f9c7 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/configuration/ConfigurationFactory.java
@@ -1,8 +1,9 @@
-package com.modnmetl.virtualrealty.utils.configuration;
+package com.modnmetl.virtualrealty.util.configuration;
+import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.configs.*;
+import com.modnmetl.virtualrealty.configs.migration.C0001_Remove_Old_Plot_Sub_Commands;
import eu.okaeri.configs.ConfigManager;
-import eu.okaeri.configs.postprocessor.SectionSeparator;
import eu.okaeri.configs.validator.okaeri.OkaeriValidator;
import eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer;
import eu.okaeri.configs.yaml.bukkit.serdes.SerdesBukkit;
@@ -17,6 +18,7 @@ public PluginConfiguration loadPluginConfiguration(File pluginConfigurationFile)
return ConfigManager.create(PluginConfiguration.class, (it) -> {
it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
it.withBindFile(pluginConfigurationFile);
+ it.withRemoveOrphans(true);
it.saveDefaults();
it.load(true);
});
@@ -26,6 +28,7 @@ public SizesConfiguration loadSizesConfiguration(File sizesConfigurationFile) {
return ConfigManager.create(SizesConfiguration.class, (it) -> {
it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
it.withBindFile(sizesConfigurationFile);
+ it.withRemoveOrphans(true);
it.saveDefaults();
it.load(true);
});
@@ -35,6 +38,7 @@ public MessagesConfiguration loadMessagesConfiguration(File messagesConfiguratio
return ConfigManager.create(MessagesConfiguration.class, (it) -> {
it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
it.withBindFile(messagesConfigurationFile);
+ it.withRemoveOrphans(true);
it.saveDefaults();
it.load(true);
});
@@ -53,8 +57,13 @@ public CommandsConfiguration loadCommandsConfiguration(File commandsConfiguratio
return ConfigManager.create(CommandsConfiguration.class, (it) -> {
it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
it.withBindFile(commandsConfigurationFile);
+ it.withLogger(VirtualRealty.getInstance().getLogger());
+ it.withRemoveOrphans(true);
it.saveDefaults();
it.load(true);
+ it.migrate(
+ new C0001_Remove_Old_Plot_Sub_Commands()
+ );
});
}
@@ -62,6 +71,7 @@ public PermissionsConfiguration updatePluginConfiguration(File pluginConfigurati
return ConfigManager.create(PermissionsConfiguration.class, (it) -> {
it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
it.withBindFile(pluginConfigurationFile);
+ it.withRemoveOrphans(true);
it.saveDefaults();
it.update();
});
@@ -94,4 +104,13 @@ public PermissionsConfiguration updatePermissionsConfiguration(File permissionsC
});
}
+ public CommandsConfiguration updateCommandsConfiguration(File commandsConfigurationFile) {
+ return ConfigManager.create(CommandsConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(commandsConfigurationFile);
+ it.withRemoveOrphans(true);
+ it.update();
+ });
+ }
+
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java b/src/main/java/com/modnmetl/virtualrealty/util/data/DataCompressor.java
similarity index 95%
rename from src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java
rename to src/main/java/com/modnmetl/virtualrealty/util/data/DataCompressor.java
index 4f4ed5e..62d4fe1 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/data/DataCompressor.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.utils.data;
+package com.modnmetl.virtualrealty.util.data;
import java.io.*;
import java.util.zip.*;
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java b/src/main/java/com/modnmetl/virtualrealty/util/data/ItemBuilder.java
similarity index 99%
rename from src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java
rename to src/main/java/com/modnmetl/virtualrealty/util/data/ItemBuilder.java
index 3c28086..dc7b4b7 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/data/ItemBuilder.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.utils.data;
+package com.modnmetl.virtualrealty.util.data;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/data/OldSchematicUtil.java
similarity index 91%
rename from src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java
rename to src/main/java/com/modnmetl/virtualrealty/util/data/OldSchematicUtil.java
index d5164a1..27db04a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/data/OldSchematicUtil.java
@@ -1,12 +1,10 @@
-package com.modnmetl.virtualrealty.utils.data;
+package com.modnmetl.virtualrealty.util.data;
-import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
+import com.modnmetl.virtualrealty.util.multiversion.VMaterial;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.utils.data.DataCompressor;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
import lombok.SneakyThrows;
-import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -26,7 +24,7 @@ public static void paste(int plotID, Location l) {
long time = System.currentTimeMillis();
String[] blocks = load(plotID);
if (blocks == null) return;
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
Location location = new Location(plot.getCreatedWorld(), plot.getBorderBottomLeftCorner().getBlockX(), plot.getBorderBottomLeftCorner().getBlockY(), plot.getBorderBottomLeftCorner().getBlockZ());
Location location2 = new Location(plot.getCreatedWorld(), plot.getBorderTopRightCorner().getBlockX(), plot.getBorderTopRightCorner().getBlockY(), plot.getBorderTopRightCorner().getBlockZ());
Block pos1Block = location.getBlock();
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/data/SchematicUtil.java
similarity index 54%
rename from src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java
rename to src/main/java/com/modnmetl/virtualrealty/util/data/SchematicUtil.java
index df452d1..8c92cf0 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/data/SchematicUtil.java
@@ -1,9 +1,11 @@
-package com.modnmetl.virtualrealty.utils.data;
+package com.modnmetl.virtualrealty.util.data;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.managers.PlotManager;
-import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
+import com.modnmetl.virtualrealty.manager.PlotManager;
+import com.modnmetl.virtualrealty.model.plot.Plot;
+import com.modnmetl.virtualrealty.model.region.VirtualBlock;
+import com.modnmetl.virtualrealty.model.region.VirtualLocation;
+import com.modnmetl.virtualrealty.util.multiversion.VMaterial;
import lombok.SneakyThrows;
import org.apache.commons.lang.SerializationUtils;
import org.bukkit.Bukkit;
@@ -11,6 +13,7 @@
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
+import org.bukkit.scheduler.BukkitRunnable;
import java.io.*;
import java.lang.reflect.Method;
@@ -52,7 +55,7 @@ public static LinkedList getStructure(Block block, Block block2) {
public static void paste(int plotID) {
List blocks = load(plotID);
if (blocks == null) return;
- Plot plot = PlotManager.getPlot(plotID);
+ Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) return;
long time = System.currentTimeMillis();
Location location = plot.getBorderBottomLeftCorner().toLocation(plot.getCreatedWorld());
@@ -67,48 +70,99 @@ public static void paste(int plotID) {
int maxY = Math.max(pos1Block.getY(), pos2Block.getY());
World world = location.getWorld();
if (world == null) return;
- int i = 0;
- for (int x = minX; x <= maxX; x++) {
- for (int z = minZ; z <= maxZ; z++) {
- for (int y = maxY; y > minY; y--) {
- Block block = world.getBlockAt(x, y, z);
+ List virtualLocations = new ArrayList<>();
+ Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> {
+ for (int x = minX; x <= maxX; x++) {
+ for (int z = minZ; z <= maxZ; z++) {
+ for (int y = maxY; y > minY; y--) {
+ virtualLocations.add(new VirtualLocation(x,y,z));
+ }
+ }
+ }
+ Bukkit.getScheduler().scheduleSyncDelayedTask(VirtualRealty.getInstance(), () -> {
+ int i = 0;
+ for (VirtualLocation virtualLocation : virtualLocations) {
+ Block block = world.getBlockAt(virtualLocation.getX(), virtualLocation.getY(), virtualLocation.getZ());
if (block.getType() == Material.AIR) continue;
block.setType(Material.AIR);
i++;
}
- }
+ VirtualRealty.debug("Pasted " + i + " air blocks in: " + (System.currentTimeMillis() - time) + " ms");
+ Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> {
+ List> chunks = chunkArrayList(blocks, 15000);
+ Bukkit.getScheduler().scheduleSyncDelayedTask(VirtualRealty.getInstance(), () -> {
+ for (int j = 0; j < chunks.size(); j++) {
+ int finalJ = j;
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ List virtualBlocks = chunks.get(finalJ);
+ for (VirtualBlock block : virtualBlocks) {
+ Location blockLocation = new Location(plot.getCreatedWorld(), block.getX(), block.getY(), block.getZ());
+ Block oldBlock = blockLocation.getBlock();
+ if (VirtualRealty.legacyVersion) {
+ try {
+ oldBlock.setType(VMaterial.getMaterial(block.getMaterial()));
+ Method m = Block.class.getDeclaredMethod("setData", byte.class);
+ m.setAccessible(true);
+ m.invoke(oldBlock, block.getData());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ oldBlock.setBlockData(
+ Bukkit.createBlockData("minecraft:" + block.getBlockData()),
+ false
+ );
+ }
+ }
+ VirtualRealty.debug("Pasted chunk #" + finalJ);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 2L * finalJ);
+ }
+ VirtualRealty.debug("Pasted " + blocks.size() + " blocks in: " + (System.currentTimeMillis() - time) + " ms");
+ VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms");
+ });
+ });
+ });
+ });
+ }
+
+ private static ArrayList> chunkArrayList(List arrayToChunk, int chunkSize) {
+ ArrayList> chunkList = new ArrayList<>();
+ int guide = arrayToChunk.size();
+ int index = 0;
+ int tale = chunkSize;
+ while (tale < arrayToChunk.size()){
+ chunkList.add(arrayToChunk.subList(index, tale));
+ guide = guide - chunkSize;
+ index = index + chunkSize;
+ tale = tale + chunkSize;
}
- VirtualRealty.debug("Pasted " + i + " air blocks in: " + (System.currentTimeMillis() - time) + " ms");
- for (VirtualBlock block : blocks) {
- Location blockLocation = new Location(plot.getCreatedWorld(), block.getX(), block.getY(), block.getZ());
- Block oldBlock = blockLocation.getBlock();
- if (VirtualRealty.legacyVersion) {
- try {
- oldBlock.setType(VMaterial.getMaterial(block.getMaterial()));
- Method m = Block.class.getDeclaredMethod("setData", byte.class);
- m.setAccessible(true);
- m.invoke(oldBlock, block.getData());
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else {
- oldBlock.setBlockData(Bukkit.createBlockData("minecraft:" + block.getBlockData()), false);
- }
+ if (guide >0) {
+ chunkList.add(arrayToChunk.subList(index, index + guide));
}
- VirtualRealty.debug("Pasted " + blocks.size() + " blocks in: " + (System.currentTimeMillis() - time) + " ms");
+ return chunkList;
}
@SneakyThrows
- public static void save(int plotID, LinkedList blocks) {
+ public static void save(int plotID, Block block1, Block block2) {
long time = System.currentTimeMillis();
- File f = new File(VirtualRealty.plotsSchemaFolder, (VirtualRealty.legacyVersion ? LEGACY_REGION_PREFIX : REGION_PREFIX) + plotID + REGION_SUFFIX);
- long serialization = System.currentTimeMillis();
- byte[] data = SerializationUtils.serialize(blocks);
- VirtualRealty.debug("Serialized in: " + (System.currentTimeMillis() - serialization) + " ms");
- long compression = System.currentTimeMillis();
- new DataCompressor().compressData(data, f);
- VirtualRealty.debug("Compressed in: " + (System.currentTimeMillis() - compression) + " ms");
- VirtualRealty.debug("Region saved in: " + (System.currentTimeMillis() - time) + " ms");
+ LinkedList blocks = SchematicUtil.getStructure(block1, block2);
+ Bukkit.getScheduler().runTaskAsynchronously(VirtualRealty.getInstance(), () -> {
+ File f = new File(VirtualRealty.plotsSchemaFolder, (VirtualRealty.legacyVersion ? LEGACY_REGION_PREFIX : REGION_PREFIX) + plotID + REGION_SUFFIX);
+ long serialization = System.currentTimeMillis();
+ byte[] data = SerializationUtils.serialize(blocks);
+ VirtualRealty.debug("Serialized in: " + (System.currentTimeMillis() - serialization) + " ms");
+ long compression = System.currentTimeMillis();
+ try {
+ new DataCompressor().compressData(data, f);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ VirtualRealty.debug("Compressed in: " + (System.currentTimeMillis() - compression) + " ms");
+ VirtualRealty.debug("Region saved in: " + (System.currentTimeMillis() - time) + " ms");
+ });
}
@SneakyThrows
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java b/src/main/java/com/modnmetl/virtualrealty/util/data/SkullUtil.java
similarity index 90%
rename from src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java
rename to src/main/java/com/modnmetl/virtualrealty/util/data/SkullUtil.java
index 3d11ce8..d8daf09 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/data/SkullUtil.java
@@ -1,7 +1,6 @@
-package com.modnmetl.virtualrealty.utils.data;
+package com.modnmetl.virtualrealty.util.data;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.bukkit.Material;
@@ -10,6 +9,7 @@
import java.lang.reflect.Field;
import java.util.Base64;
+import java.util.Objects;
import java.util.UUID;
public class SkullUtil {
@@ -17,7 +17,7 @@ public class SkullUtil {
public static ItemStack getSkull(String url) {
ItemStack skull;
if (VirtualRealty.legacyVersion) {
- skull = new ItemStack(VMaterial.getMaterial("SKULL_ITEM"), 1, (short) 3);
+ skull = new ItemStack(Objects.requireNonNull(Material.getMaterial("SKULL_ITEM")), 1, (short) 3);
} else {
skull = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
}
@@ -47,7 +47,7 @@ public static ItemStack getSkull(String url) {
public static ItemStack getSkull(String url, UUID uuid) {
ItemStack skull;
if (VirtualRealty.legacyVersion) {
- skull = new ItemStack(VMaterial.getMaterial("SKULL_ITEM"), 1, (short) 3);
+ skull = new ItemStack(Objects.requireNonNull(Material.getMaterial("SKULL_ITEM")), 1, (short) 3);
} else {
skull = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java b/src/main/java/com/modnmetl/virtualrealty/util/loader/CustomClassLoader.java
similarity index 81%
rename from src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java
rename to src/main/java/com/modnmetl/virtualrealty/util/loader/CustomClassLoader.java
index 98f6e71..a19807b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/loader/CustomClassLoader.java
@@ -1,4 +1,4 @@
-package com.modnmetl.virtualrealty.utils.loader;
+package com.modnmetl.virtualrealty.util.loader;
import java.net.URL;
import java.net.URLClassLoader;
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java b/src/main/java/com/modnmetl/virtualrealty/util/loader/Loader.java
similarity index 96%
rename from src/main/java/com/modnmetl/virtualrealty/utils/Loader.java
rename to src/main/java/com/modnmetl/virtualrealty/util/loader/Loader.java
index b2815ec..b7801c6 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/loader/Loader.java
@@ -1,12 +1,9 @@
-package com.modnmetl.virtualrealty.utils;
+package com.modnmetl.virtualrealty.util.loader;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.utils.loader.CustomClassLoader;
-import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
-import sun.net.www.protocol.ftp.FtpURLConnection;
import java.io.*;
import java.net.*;
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java b/src/main/java/com/modnmetl/virtualrealty/util/multiversion/VMaterial.java
similarity index 93%
rename from src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java
rename to src/main/java/com/modnmetl/virtualrealty/util/multiversion/VMaterial.java
index d39b011..c9d48c9 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java
+++ b/src/main/java/com/modnmetl/virtualrealty/util/multiversion/VMaterial.java
@@ -1,13 +1,13 @@
-package com.modnmetl.virtualrealty.utils.multiversion;
+package com.modnmetl.virtualrealty.util.multiversion;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.exceptions.MaterialMatchException;
+import com.modnmetl.virtualrealty.exception.MaterialMatchException;
import org.bukkit.Material;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-public class VMaterial {
+public final class VMaterial {
public static Material getMaterial(int materialID) throws MaterialMatchException {
if (VirtualRealty.legacyVersion) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java
deleted file mode 100644
index 1c711c3..0000000
--- a/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.modnmetl.virtualrealty.utils.multiversion;
-
-import net.md_5.bungee.api.chat.BaseComponent;
-import net.md_5.bungee.api.chat.TextComponent;
-import org.bukkit.command.CommandSender;
-
-public class Chat {
-
- private final BaseComponent text;
-
- public Chat(BaseComponent text) {
- this.text = text;
- }
-
- public Chat(String text) {
- this.text = new TextComponent(text);
- }
-
- public void sendTo(CommandSender sender) {
- sender.spigot().sendMessage(text);
- }
-
-
-}