diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4788b4b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,113 @@
+# User-specific stuff
+.idea/
+
+*.iml
+*.ipr
+*.iws
+
+# IntelliJ
+out/
+
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+*~
+
+# temporary files which can be created if a process still has a handle open of a deleted file
+.fuse_hidden*
+
+# KDE directory preferences
+.directory
+
+# Linux trash folder which might appear on any partition or disk
+.Trash-*
+
+# .nfs files are created when an open file is removed but is still being accessed
+.nfs*
+
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+# Windows thumbnail cache files
+Thumbs.db
+Thumbs.db:encryptable
+ehthumbs.db
+ehthumbs_vista.db
+
+# Dump file
+*.stackdump
+
+# Folder config file
+[Dd]esktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# Windows shortcuts
+*.lnk
+
+target/
+
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+.flattened-pom.xml
+
+# Common working directory
+run/
diff --git a/VirtualRealty-Free.iml b/VirtualRealty-Free.iml
deleted file mode 100644
index 88b5798..0000000
--- a/VirtualRealty-Free.iml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
- PAPER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c8a3389..10932cb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,192 +1,189 @@
-
-
- 4.0.0
-
- me.plytki
- VirtualRealty
- 1.7.1
- jar
-
- VirtualRealty
-
- A plot creation and management plugin for Minecraft
-
- 1.8
- UTF-8
-
-
-
-
-
- maven-compiler-plugin
- 3.8.1
-
- ${java.version}
- ${java.version}
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.2.4
-
-
- package
-
- shade
-
-
- false
-
-
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.2.1
-
-
-
- org.bstats
- me.plytki.virtualrealty.utils
-
- org.apache.commons.io
- me.plytki.virtualrealty.utils
-
-
- org.h2
- me.plytki.virtualrealty.utils.h2
-
-
-
-
-
- package
-
- shade
-
-
-
-
- *:*
-
- META-INF/**
-
-
-
-
-
-
-
-
-
-
- src/main/resources
- true
-
-
-
-
-
-
- papermc-repo
- https://papermc.io/repo/repository/maven-public/
-
-
- sonatype
- https://oss.sonatype.org/content/groups/public/
-
-
- panda-repository
- https://repo.panda-lang.org/
-
-
- okaeri-repo
- https://storehouse.okaeri.eu/repository/maven-public/
-
-
- dynmap-repo
- http://repo.mikeprimm.com/
-
-
- placeholderapi
- http://repo.extendedclip.com/content/repositories/placeholderapi/
-
-
-
-
-
- org.jetbrains
- annotations
- 21.0.1
- provided
-
-
- org.spigot
- spigot
- 1.13.2
- provided
-
-
- org.bukkit
- craftbukkit
- 1.13.2-R0.1-SNAPSHOT
- provided
-
-
- com.h2database
- h2
- 1.4.200
- compile
-
-
- org.bstats
- bstats-bukkit
- 2.2.1
- compile
-
-
- eu.okaeri
- okaeri-configs-yaml-bukkit
- 3.1.0
-
-
- eu.okaeri
- okaeri-configs-serdes-commons
- 3.1.0
-
-
- eu.okaeri
- okaeri-configs-validator-okaeri
- 3.1.0
-
-
- commons-io
- commons-io
- 2.11.0
- compile
-
-
- org.apache.commons
- commons-lang3
- 3.12.0
- compile
-
-
- org.dynmap
- dynmap-api
- 2.0
- provided
-
-
- me.clip
- placeholderapi
- 2.10.9
- provided
-
-
-
-
+
+
+ 4.0.0
+
+ com.modnmetl
+ virtualrealty
+ 2.0.0
+ jar
+
+ A plot creation and management plugin for Minecraft
+
+
+ 1.8
+ UTF-8
+
+
+
+
+
+ maven-compiler-plugin
+ 3.8.1
+
+ ${java.version}
+ ${java.version}
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.4
+
+
+
+ org.bstats
+ com.modnmetl.virtualrealty.utils.bstats
+
+
+ org.apache.commons.io
+ com.modnmetl.virtualrealty.utils.apache
+
+
+
+
+
+ package
+
+ shade
+
+
+
+
+ *:*
+
+ META-INF/**
+ LICENSE
+
+
+
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ papermc-repo
+ https://papermc.io/repo/repository/maven-public/
+
+
+ sonatype
+ https://oss.sonatype.org/content/groups/public/
+
+
+ okaeri-repo
+ https://storehouse.okaeri.eu/repository/maven-public/
+
+
+ dynmap-repo
+ https://repo.mikeprimm.com/
+
+
+ placeholderapi
+ https://repo.extendedclip.com/content/repositories/placeholderapi/
+
+
+ codemc-repo
+ https://repo.codemc.org/repository/maven-public/
+ default
+
+
+
+
+
+ org.jetbrains
+ annotations
+ 22.0.0
+ provided
+
+
+ org.spigot
+ spigot
+ 1.13.2
+ provided
+
+
+ org.bukkit
+ craftbukkit
+ 1.13.2-R0.1-SNAPSHOT
+ provided
+
+
+ org.bstats
+ bstats-bukkit
+ 3.0.0
+ compile
+
+
+ eu.okaeri
+ okaeri-configs-yaml-bukkit
+ 4.0.0-beta9
+ compile
+
+
+ eu.okaeri
+ okaeri-configs-serdes-bukkit
+ 4.0.0-beta9
+ compile
+
+
+ eu.okaeri
+ okaeri-configs-validator-okaeri
+ 4.0.0-beta9
+ compile
+
+
+ commons-io
+ commons-io
+ 2.11.0
+ compile
+
+
+ org.dynmap
+ dynmap-api
+ 2.0
+ provided
+
+
+ me.clip
+ placeholderapi
+ 2.10.9
+ provided
+
+
+ com.modnmetl
+ virtualrealty-premium
+ ${project.version}
+ provided
+
+
+ org.projectlombok
+ lombok
+ 1.18.22
+ provided
+
+
+ de.tr7zw
+ item-nbt-api-plugin
+ 2.9.2
+ compile
+
+
+ com.zaxxer
+ HikariCP
+ 5.0.1
+ compile
+
+
+
+
diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
new file mode 100644
index 0000000..3928e86
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
@@ -0,0 +1,508 @@
+package com.modnmetl.virtualrealty;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import com.modnmetl.virtualrealty.commands.CommandManager;
+import com.modnmetl.virtualrealty.commands.SubCommand;
+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.managers.PlotManager;
+import com.modnmetl.virtualrealty.managers.PlotMemberManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.registry.VirtualPlaceholders;
+import com.modnmetl.virtualrealty.sql.Database;
+import com.modnmetl.virtualrealty.utils.configuration.ConfigurationFactory;
+import com.modnmetl.virtualrealty.utils.loader.CustomClassLoader;
+import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
+import com.modnmetl.virtualrealty.utils.UpdateChecker;
+import com.zaxxer.hikari.HikariDataSource;
+import de.tr7zw.nbtapi.utils.VersionChecker;
+import org.apache.commons.io.FileUtils;
+import org.bstats.bukkit.Metrics;
+import org.bstats.charts.AdvancedPie;
+import org.bstats.charts.SimplePie;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.permissions.Permission;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.scheduler.BukkitTask;
+import org.dynmap.DynmapAPI;
+import org.dynmap.markers.MarkerIcon;
+import org.dynmap.markers.MarkerSet;
+
+import javax.sql.DataSource;
+import java.io.*;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.sql.SQLException;
+import java.util.*;
+import java.util.logging.Level;
+
+public final class VirtualRealty extends JavaPlugin {
+
+ //CORE
+ public Locale locale = Locale.getDefault();
+ private static VirtualRealty instance;
+ private static ClassLoader loader;
+ public static final String PREFIX = "§a§lVR §8§l» §7";
+ public static LinkedList tasks = new LinkedList<>();
+ private static final LinkedList preVersions = new LinkedList<>();
+ public static boolean legacyVersion = false;
+ public static ServerVersion currentServerVersion = ServerVersion.MODERN;
+ public static final Permission GLOBAL_PERMISSION = new Permission("virtualrealty");
+ private static Object premium;
+ public static boolean upToDate;
+ public static String latestVersion;
+
+ //FILES
+ public static File plotsFolder;
+ public static File plotsSchemaFolder;
+ public PluginConfiguration pluginConfiguration;
+ public SizesConfiguration sizesConfiguration;
+ public MessagesConfiguration messagesConfiguration;
+ public PermissionsConfiguration permissionsConfiguration;
+ private final File pluginConfigurationFile = new File(this.getDataFolder(), "config.yml");
+ private final File sizesConfigurationFile = new File(this.getDataFolder(), "sizes.yml");
+ private final File permissionsConfigurationFile = new File(this.getDataFolder(), "permissions.yml");
+ private final File languagesDirectory = new File(this.getDataFolder(), "messages");
+ private final File databaseFolder = new File(this.getDataFolder().getAbsolutePath(), File.separator + "data" + File.separator);
+ private final File databaseFile = new File(databaseFolder, "data.db");
+ private File loaderFile;
+
+ //DYNMAP API
+ public static boolean isDynmapPresent = false;
+ public static DynmapAPI dapi = null;
+ public static MarkerSet markerset = null;
+ public static MarkerIcon markerIcon = null;
+
+ @Override
+ public void onEnable() {
+ instance = this;
+ loader = getClassLoader();
+ VersionChecker.hideOk = true;
+ if (checkLegacyVersions()) {
+ legacyVersion = true;
+ currentServerVersion = ServerVersion.LEGACY;
+ }
+ databaseFolder.mkdirs();
+ plotsFolder = new File(getInstance().getDataFolder().getAbsolutePath(), "plots");
+ plotsFolder.mkdirs();
+ plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain");
+ plotsSchemaFolder.mkdirs();
+ reloadConfigs();
+ this.locale = new Locale(pluginConfiguration.locale.split("_")[0], pluginConfiguration.locale.split("_")[1]);
+ configureMessages();
+ if (ServerVersion.valueOf(pluginConfiguration.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(" » ------------------------------------------------------------------------------------------------ « ");
+ this.getPluginLoader().disablePlugin(this);
+ return;
+ }
+ if (ServerVersion.valueOf(pluginConfiguration.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(" » ------------------------------------------------------------------------------------------------ « ");
+ 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!");
+ }
+ }
+ if (!pluginConfiguration.license.key.isEmpty() && !pluginConfiguration.license.email.isEmpty()) {
+ try {
+ runLoader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion());
+ } catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
+ getLogger().log(Level.WARNING, "Loading of premium features failed.");
+ }
+ }
+ registerMetrics();
+ loadSizesConfiguration();
+ try {
+ connectToDatabase();
+ } catch (SQLException e) {
+ getLogger().log(Level.WARNING, "Failed to connect to the database.");
+ this.getPluginLoader().disablePlugin(this);
+ return;
+ }
+ PlotManager.loadPlots();
+ PlotMemberManager.loadMembers();
+ if (pluginConfiguration.dynmapMarkers) {
+ registerDynmap();
+ }
+ registerCommands();
+ registerListeners();
+ if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
+ new VirtualPlaceholders(this).register();
+ debug("Registered new placeholders");
+ }
+ debug("Server version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion());
+ }
+
+ @Override
+ public void onDisable() {
+ try {
+ Method method = Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, getCustomClassLoader()).getMethod("onDisable");
+ method.setAccessible(true);
+ method.invoke(premium);
+ } catch (Exception ignored) {
+ }
+ PlotManager.getPlots().forEach(Plot::update);
+ tasks.forEach(BukkitTask::cancel);
+ try {
+ DataSource dataSource;
+ if (getDatabase() != null && (dataSource = getDatabase().getDataSource()) != null && dataSource.getConnection() != null) {
+ if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.MYSQL) {
+ ((HikariDataSource) dataSource).close();
+ } else {
+ dataSource.getConnection().close();
+ }
+ }
+ } catch (SQLException ignored) {
+ }
+ ConfigurationFactory configurationFactory = new ConfigurationFactory();
+ configurationFactory.updatePluginConfiguration(pluginConfigurationFile);
+ FileUtils.deleteQuietly(loaderFile);
+ }
+
+
+ public static void debug(String debugMessage) {
+ if (VirtualRealty.getPluginConfiguration().debugMode)
+ VirtualRealty.getInstance().getLogger().warning("DEBUG > " + debugMessage);
+ }
+
+ private void runLoader(String licenseKey, String licenseEmail, String pluginVersion) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
+ URL url = new URL("https://api.modnmetl.com/auth/key");
+
+ debug("Injecting premium..");
+ HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
+ httpConn.setRequestMethod("POST");
+ httpConn.setDoOutput(true);
+ httpConn.setRequestProperty("Content-Type", "application/json");
+
+ Gson gson = new Gson();
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("id", "62110bdbf58570001812deb8");
+ jsonObject.addProperty("key", licenseKey);
+ jsonObject.addProperty("email", licenseEmail);
+ jsonObject.addProperty("version", pluginVersion);
+ String data = gson.toJson(jsonObject);
+
+ byte[] out = data.getBytes(StandardCharsets.UTF_8);
+ OutputStream stream = httpConn.getOutputStream();
+ stream.write(out);
+
+ int responseCode = httpConn.getResponseCode();
+ if (responseCode != HttpURLConnection.HTTP_OK) {
+ debug("Authentication error | " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage());
+ return;
+ }
+ try (InputStream in = httpConn.getInputStream()) {
+ loaderFile = File.createTempFile(String.valueOf(Arrays.asList(new Random().nextInt(9), new Random().nextInt(9), new Random().nextInt(9))), ".tmp");
+ FileUtils.deleteQuietly(loaderFile);
+ Files.copy(in, Paths.get(loaderFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
+ }
+ URL jarUrl = loaderFile.toURI().toURL();
+ loader = new CustomClassLoader(new URL[]{jarUrl}, getClassLoader());
+ httpConn.disconnect();
+ try {
+ Class> clazz = Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, loader);
+ premium = clazz.newInstance();
+ Class.forName("com.modnmetl.virtualrealty.utils.PanelUtil", true, loader);
+ } catch (Exception ignored) {
+ debug("Premium injection failed");
+ return;
+ }
+ debug("Premium injected");
+ }
+
+ public void configureMessages() {
+ File messagesConfigurationFile = new File(languagesDirectory, "messages_" + locale.toString() + ".yml");
+ ConfigurationFactory configFactory = new ConfigurationFactory();
+ configFactory.loadMessagesConfiguration(messagesConfigurationFile);
+ }
+
+ public void reloadConfigs() {
+ try {
+ ConfigurationFactory configFactory = new ConfigurationFactory();
+ pluginConfiguration = configFactory.loadPluginConfiguration(pluginConfigurationFile);
+ File messagesConfigurationFile = new File(languagesDirectory, "messages_" + pluginConfiguration.locale + ".yml");
+ sizesConfiguration = configFactory.loadSizesConfiguration(sizesConfigurationFile);
+ permissionsConfiguration = configFactory.loadPermissionsConfiguration(permissionsConfigurationFile);
+ messagesConfiguration = configFactory.loadMessagesConfiguration(messagesConfigurationFile);
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ }
+
+ public void registerDynmap() {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("dynmap");
+ if (plugin == null) return;
+ isDynmapPresent = true;
+ if (plugin.isEnabled()) {
+ dapi = (DynmapAPI) plugin;
+ if (dapi.markerAPIInitialized()) {
+ markerset = dapi.getMarkerAPI().getMarkerSet("virtualrealty.plots");
+ if (markerset == null)
+ markerset = dapi.getMarkerAPI().createMarkerSet("virutalrealty.plots", "Plots", dapi.getMarkerAPI().getMarkerIcons(), false);
+ for (MarkerSet markerSet : dapi.getMarkerAPI().getMarkerSets()) {
+ if (markerSet.getMarkerSetLabel().equalsIgnoreCase("Plots")) {
+ markerset = markerSet;
+ }
+ }
+ try {
+ if (dapi.getMarkerAPI().getMarkerIcon("virtualrealty_main_icon") == null) {
+ InputStream in = this.getClass().getResourceAsStream("/ploticon.png");
+ if (in != null && in.available() > 0) {
+ markerIcon = dapi.getMarkerAPI().createMarkerIcon("virtualrealty_main_icon", "Plots", in);
+ }
+ } else {
+ markerIcon = dapi.getMarkerAPI().getMarkerIcon("virtualrealty_main_icon");
+ }
+ } catch (IOException ignored) {
+ }
+ VirtualRealty.debug("Registering plots markers..");
+ for (Plot plot : PlotManager.getPlots()) {
+ PlotManager.resetPlotMarker(plot);
+ }
+ VirtualRealty.debug("Registered plots markers");
+ this.cancel();
+ }
+ }
+ }
+ }.runTaskTimer(this, 20, 20 * 5);
+ }
+
+ private void registerCommands() {
+ Objects.requireNonNull(this.getCommand("plot")).setExecutor(new PlotCommand());
+ Objects.requireNonNull(this.getCommand("virtualrealty")).setExecutor(new VirtualRealtyCommand());
+ Objects.requireNonNull(this.getCommand("plot")).setTabCompleter(new CommandManager());
+ Objects.requireNonNull(this.getCommand("virtualrealty")).setTabCompleter(new CommandManager());
+ SubCommand.registerSubCommands(new String[]{"visual", "item"}, VirtualRealtyCommand.class);
+ SubCommand.registerSubCommands(new String[]{"panel", "draft", "stake"}, PlotCommand.class);
+ SubCommand.registerSubCommands(new String[]{"assign", "create", "info", "list", "reload", "remove", "set", "tp", "unassign"}, VirtualRealtyCommand.class);
+ SubCommand.registerSubCommands(new String[]{"add", "gm", "info", "kick", "list", "tp"}, PlotCommand.class);
+ }
+
+ private void registerListeners() {
+ new BorderProtectionListener(this);
+ new PlotProtectionListener(this);
+ new WorldProtectionListener(this);
+ new PlotEntranceListener(this);
+ new PlayerActionListener(this);
+ try {
+ Class> panelListener = Class.forName("com.modnmetl.virtualrealty.listeners.premium.PanelListener", true, loader);
+ Class> draftListener = Class.forName("com.modnmetl.virtualrealty.listeners.premium.DraftListener", true, loader);
+ Class> stakeListener = Class.forName("com.modnmetl.virtualrealty.listeners.premium.StakeConfirmationListener", true, loader);
+ panelListener.getConstructors()[0].newInstance(this);
+ draftListener.getConstructors()[0].newInstance(this);
+ stakeListener.getConstructors()[0].newInstance(this);
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException ignored) {}
+ debug("Registered listeners");
+ }
+
+ private void registerMetrics() {
+ Metrics metrics = new Metrics(this, 14066);
+ metrics.addCustomChart(new SimplePie("used_database", () -> pluginConfiguration.dataModel.name()));
+ metrics.addCustomChart(new AdvancedPie("created_plots", () -> {
+ Map valueMap = new HashMap<>();
+ int smallPlots = 0;
+ int mediumPlots = 0;
+ int largePlots = 0;
+ int customPlots = 0;
+ int areas = 0;
+ for (Plot plot : PlotManager.getPlots()) {
+ switch (plot.getPlotSize()) {
+ case SMALL: {
+ smallPlots++;
+ break;
+ }
+ case MEDIUM: {
+ mediumPlots++;
+ break;
+ }
+ case LARGE: {
+ largePlots++;
+ break;
+ }
+ case CUSTOM: {
+ customPlots++;
+ break;
+ }
+ case AREA: {
+ areas++;
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected value: " + plot.getPlotSize());
+ }
+ }
+ valueMap.put("SMALL", smallPlots);
+ valueMap.put("MEDIUM", mediumPlots);
+ valueMap.put("LARGE", largePlots);
+ valueMap.put("CUSTOM", customPlots);
+ valueMap.put("AREA", areas);
+ return valueMap;
+ }));
+ debug("Registered metrics");
+ }
+
+ private void connectToDatabase() throws SQLException {
+ Database database = null;
+ if (pluginConfiguration.dataModel == PluginConfiguration.DataModel.SQLITE) {
+ database = new Database(databaseFile);
+ }
+ if (pluginConfiguration.dataModel == PluginConfiguration.DataModel.MYSQL) {
+ database = new Database(
+ VirtualRealty.getPluginConfiguration().mysql.hostname,
+ VirtualRealty.getPluginConfiguration().mysql.port,
+ VirtualRealty.getPluginConfiguration().mysql.user,
+ VirtualRealty.getPluginConfiguration().mysql.password,
+ VirtualRealty.getPluginConfiguration().mysql.database
+ );
+ }
+ Database.setInstance(database);
+ debug("Connected to database");
+ }
+
+ public void loadSizesConfiguration() {
+ for (PlotSize plotSize : PlotSize.values()) {
+ if (plotSize == PlotSize.CUSTOM) continue;
+ SizesConfiguration.PlotSizes.Size classSize = null;
+ switch (plotSize) {
+ case SMALL: {
+ classSize = sizesConfiguration.plotSizes.SMALL;
+ break;
+ }
+ case MEDIUM: {
+ classSize = sizesConfiguration.plotSizes.MEDIUM;
+ break;
+ }
+ case LARGE: {
+ classSize = sizesConfiguration.plotSizes.LARGE;
+ break;
+ }
+ case AREA: {
+ plotSize.setLength(sizesConfiguration.plotSizes.AREA.length);
+ plotSize.setWidth(sizesConfiguration.plotSizes.AREA.width);
+ plotSize.setHeight(sizesConfiguration.plotSizes.AREA.height);
+ return;
+ }
+ }
+ Material floorMaterial;
+ try {
+ floorMaterial = VMaterial.catchMaterial(classSize.floorMaterial.toUpperCase());
+ } catch (MaterialMatchException e) {
+ floorMaterial = VirtualRealty.legacyVersion ? Material.GRASS : Material.GRASS_BLOCK;
+ e.printStackTrace();
+ }
+ Material borderMaterial;
+ try {
+ borderMaterial = VMaterial.catchMaterial(classSize.borderMaterial.toUpperCase());
+ } catch (MaterialMatchException e) {
+ borderMaterial = VirtualRealty.legacyVersion ? Material.getMaterial("STEP") : Material.STONE_BRICK_SLAB;
+ e.printStackTrace();
+ }
+ plotSize.setFloorMaterial(floorMaterial);
+ plotSize.setFloorData(classSize.floorData);
+ plotSize.setBorderMaterial(borderMaterial);
+ plotSize.setBorderData(classSize.borderData);
+ plotSize.setLength(classSize.length);
+ plotSize.setWidth(classSize.width);
+ plotSize.setHeight(classSize.height);
+ }
+ debug("Loaded sizes config");
+ }
+
+ public static VirtualRealty getInstance() {
+ return instance;
+ }
+
+ public static ClassLoader getCustomClassLoader() {
+ return loader;
+ }
+
+ public static PluginConfiguration getPluginConfiguration() {
+ return VirtualRealty.getInstance().pluginConfiguration;
+ }
+
+ public static File getPluginConfigurationFile() {
+ return VirtualRealty.getInstance().pluginConfigurationFile;
+ }
+
+ public static SizesConfiguration getSizesConfiguration() {
+ return VirtualRealty.getInstance().sizesConfiguration;
+ }
+
+ public static File getSizesConfigurationFile() {
+ return VirtualRealty.getInstance().sizesConfigurationFile;
+ }
+
+ public static MessagesConfiguration getMessages() {
+ return getInstance().messagesConfiguration;
+ }
+
+ public static PermissionsConfiguration getPermissions() {
+ return getInstance().permissionsConfiguration;
+ }
+
+ public boolean checkLegacyVersions() {
+ setPostVersions();
+ for (String preVersion : preVersions) {
+ if (Bukkit.getBukkitVersion().toLowerCase().contains(preVersion.toLowerCase())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static Locale getLocale() {
+ return getInstance().locale;
+ }
+
+ public static Database getDatabase() {
+ return Database.getInstance();
+ }
+
+ private void setPostVersions() {
+ preVersions.add("1.12");
+ preVersions.add("1.11");
+ preVersions.add("1.10");
+ preVersions.add("1.9");
+ preVersions.add("1.8");
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
new file mode 100644
index 0000000..49cf771
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
@@ -0,0 +1,371 @@
+package com.modnmetl.virtualrealty.commands;
+
+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.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.utils.EnumUtils;
+import lombok.SneakyThrows;
+import net.minecraft.server.v1_13_R2.ItemNetherStar;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.*;
+
+public class CommandManager implements TabCompleter {
+
+ public static final HashMap, SortedSet> SUBCOMMANDS = new HashMap<>();
+
+ public static void addSubCommand(String subCommand, Class> mainCommandClass) {
+ if (!SUBCOMMANDS.containsKey(mainCommandClass)) {
+ SUBCOMMANDS.put(mainCommandClass, new TreeSet<>());
+ }
+ SUBCOMMANDS.get(mainCommandClass).add(subCommand);
+ }
+
+ @SneakyThrows
+ @Override
+ public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
+ LinkedList tabCompleter = new LinkedList<>();
+ if (command.getName().equalsIgnoreCase("virtualrealty")) {
+ if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName())) return null;
+ if (args.length <= 1) {
+ for (String subcommand : SUBCOMMANDS.get(VirtualRealtyCommand.class)) {
+ if (args[0].isEmpty()) {
+ tabCompleter.add(subcommand);
+ } else if (subcommand.startsWith(args[0])) {
+ tabCompleter.add(subcommand);
+ }
+ }
+ }
+ switch (args[0].toUpperCase(Locale.ROOT)) {
+ case "CREATE": {
+ if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
+ if (args.length > 1) {
+ if (args.length == 2) {
+ for (PlotSize value : PlotSize.values()) {
+ if (value == PlotSize.CUSTOM) continue;
+ if (args[1].isEmpty()) {
+ tabCompleter.add(value.name().toLowerCase());
+ } else if (value.name().toLowerCase().startsWith(args[1].toLowerCase())) {
+ tabCompleter.add(value.name().toLowerCase());
+ }
+ }
+ }
+ boolean isNatural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
+ args = Arrays.stream(args).filter(s1 -> !s1.equalsIgnoreCase("--natural")).toArray(String[]::new);
+ if (isNatural) return null;
+ if (args.length > 2) {
+ boolean predefinedValue = EnumUtils.isValidEnum(PlotSize.class, args[1].toUpperCase());
+ if ((predefinedValue && args.length < 5) || (!predefinedValue && args.length > 4 && args.length < 7)) {
+ for (Material value : Material.values()) {
+ if (!value.isSolid()) continue;
+ if (args[args.length - 1].isEmpty()) {
+ tabCompleter.add(value.name().toLowerCase());
+ } else if (value.name().toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
+ tabCompleter.add(value.name().toLowerCase());
+ }
+ }
+ }
+ }
+ }
+ return tabCompleter;
+ }
+ case "SET": {
+ if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
+ if (args.length == 2) {
+ for (Plot plot : PlotManager.getPlots()) {
+ if (args[1].isEmpty()) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ }
+ }
+ return tabCompleter;
+ }
+ if (args.length == 3) {
+ List arguments = Arrays.asList("owner", "floor", "border", "expiry");
+ for (String argument : arguments) {
+ if (args[2].isEmpty()) {
+ tabCompleter.add(argument.toLowerCase());
+ } else if (argument.toLowerCase().startsWith(args[2].toLowerCase())) {
+ tabCompleter.add(argument.toLowerCase());
+ }
+ }
+ return tabCompleter;
+ }
+ if (args.length == 4) {
+ switch (args[2].toUpperCase()) {
+ case "FLOOR":
+ case "BORDER": {
+ for (Material value : Material.values()) {
+ if (!value.isSolid()) continue;
+ if (args[3].isEmpty()) {
+ tabCompleter.add(value.name().toLowerCase());
+ } else if (value.name().toLowerCase().startsWith(args[3].toLowerCase())) {
+ tabCompleter.add(value.name().toLowerCase());
+ }
+ }
+ return tabCompleter;
+ }
+ case "OWNER": {
+ for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
+ if (args[3].isEmpty()) {
+ tabCompleter.add(onlinePlayer.getName());
+ } else if (onlinePlayer.getName().toLowerCase().startsWith(args[3].toLowerCase())) {
+ tabCompleter.add(onlinePlayer.getName());
+ }
+ }
+ return tabCompleter;
+ }
+ case "EXPIRY": {
+ String validFormat = "31/12/2999";
+ String argument = args[3].toLowerCase();
+ if (argument.isEmpty()) {
+ tabCompleter.add(validFormat);
+ } else {
+ String display = null;
+ String[] providedStrings = argument.split("/");
+ if (providedStrings.length == 1) {
+ display = validFormat.substring(2);
+ }
+ if (providedStrings.length == 2) {
+ display = validFormat.substring(5);
+ }
+ if (providedStrings.length == 3 && providedStrings[2].length() < 4) {
+ display = validFormat.substring(6 + providedStrings[2].length());
+ }
+ if (display != null) {
+ if (argument.length() <= validFormat.length()) {
+ tabCompleter.add(display);
+ }
+ }
+ }
+ return tabCompleter;
+ }
+ }
+ }
+ if (args.length == 5) {
+ if (args[2].equalsIgnoreCase("expiry")) {
+ String validFormat = "00:00";
+ String argument = args[4].toLowerCase();
+ if (argument.isEmpty()) {
+ tabCompleter.add(validFormat);
+ } else {
+ String display = null;
+ String[] providedStrings = argument.split(":");
+ if (providedStrings.length == 1) {
+ display = validFormat.substring(2);
+ }
+ if (display != null) {
+ if (argument.length() <= validFormat.length()) {
+ tabCompleter.add(display);
+ }
+ }
+ }
+ return tabCompleter;
+ }
+ }
+ return tabCompleter;
+ }
+ case "ASSIGN":
+ case "UNASSIGN": {
+ if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
+ if (args.length == 2) {
+ for (Plot plot : PlotManager.getPlots()) {
+ if (args[1].isEmpty()) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ }
+ }
+ return tabCompleter;
+ }
+ if (args.length == 3) {
+ for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
+ if (args[2].isEmpty()) {
+ tabCompleter.add(onlinePlayer.getName());
+ } else if (onlinePlayer.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
+ tabCompleter.add(onlinePlayer.getName());
+ }
+ }
+ return tabCompleter;
+ }
+ return tabCompleter;
+ }
+ case "INFO":
+ case "REMOVE":
+ case "TP": {
+ if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
+ if (args.length == 2) {
+ for (Plot plot : PlotManager.getPlots()) {
+ if (args[1].isEmpty()) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(args[1].toLowerCase())) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ }
+ }
+ return tabCompleter;
+ }
+ }
+ case "ITEM": {
+ if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
+ if (args.length > 1) {
+ boolean isNatural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
+ args = Arrays.stream(args).filter(s1 -> !s1.equalsIgnoreCase("--natural")).toArray(String[]::new);
+ int backwardsArgs = 3 + (isNatural ? 2 : 0);
+ if (args.length == 2) {
+ for (PlotSize value : PlotSize.values()) {
+ if (args[1].isEmpty()) {
+ tabCompleter.add(value.name().toLowerCase());
+ } else if (value.name().toLowerCase().startsWith(args[1].toLowerCase())) {
+ tabCompleter.add(value.name().toLowerCase());
+ }
+ }
+ }
+ if (args.length > 2) {
+ if (!EnumUtils.isValidEnum(PlotSize.class, args[1].toUpperCase())) return null;
+ PlotSize plotSize = PlotSize.valueOf(args[1].toUpperCase());
+ int length;
+ int height;
+ int width;
+ switch (plotSize) {
+ case AREA:
+ case CUSTOM: {
+ backwardsArgs = (isNatural ? 2 : 0);
+ if (args.length == 3 && args[2].isEmpty()) {
+ tabCompleter.add(String.valueOf(plotSize.getLength()));
+ return tabCompleter;
+ }
+ if (args.length == 4 && args[3].isEmpty()) {
+ tabCompleter.add(String.valueOf(plotSize.getHeight()));
+ return tabCompleter;
+ }
+ if (args.length == 5 && args[4].isEmpty()) {
+ tabCompleter.add(String.valueOf(plotSize.getWidth()));
+ return tabCompleter;
+ }
+ if (args.length > 5) {
+ length = Integer.parseInt(args[2]);
+ height = Integer.parseInt(args[3]);
+ width = Integer.parseInt(args[4]);
+ }
+ }
+ }
+ if (args.length == 6-backwardsArgs) {
+ tabCompleter.add("default");
+ for (Material value : Material.values()) {
+ if (!value.isSolid()) continue;
+ if (args[5 - backwardsArgs].isEmpty()) {
+ tabCompleter.add(value.name().toLowerCase());
+ } else if (value.name().toLowerCase().startsWith(args[5 - backwardsArgs].toLowerCase())) {
+ tabCompleter.add(value.name().toLowerCase());
+ }
+ }
+ }
+ if (args.length == 7-backwardsArgs) {
+ tabCompleter.add("default");
+ for (Material value : Material.values()) {
+ if (!value.isSolid()) continue;
+ if (args[6 - backwardsArgs].isEmpty()) {
+ tabCompleter.add(value.name().toLowerCase());
+ } else if (value.name().toLowerCase().startsWith(args[6 - backwardsArgs].toLowerCase())) {
+ tabCompleter.add(value.name().toLowerCase());
+ }
+ }
+ }
+ if (args.length == 8-backwardsArgs) {
+ if (args[7-backwardsArgs].isEmpty()) {
+ tabCompleter.add("180");
+ return tabCompleter;
+ }
+ }
+ if (args.length == 9-backwardsArgs) {
+ if (args[8-backwardsArgs].isEmpty()) {
+ tabCompleter.add("1");
+ return tabCompleter;
+ }
+ }
+ if (args.length == 10-backwardsArgs) {
+ for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
+ if (args[9-backwardsArgs].isEmpty()) {
+ tabCompleter.add(onlinePlayer.getName());
+ } else if (onlinePlayer.getName().toLowerCase().startsWith(args[9-backwardsArgs].toLowerCase())) {
+ tabCompleter.add(onlinePlayer.getName());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return tabCompleter;
+ } else if (command.getName().equalsIgnoreCase("plot")) {
+ if (!(sender instanceof Player)) return null;
+ Player player = ((Player) sender);
+ if (args.length <= 1) {
+ for (String subcommand : SUBCOMMANDS.get(PlotCommand.class)) {
+ if (args[0].isEmpty()) {
+ tabCompleter.add(subcommand);
+ } else if (subcommand.startsWith(args[0])) {
+ tabCompleter.add(subcommand);
+ }
+ }
+ }
+ @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) -> {
+ if (finalArgs[1].isEmpty()) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ } else if (String.valueOf(plot.getID()).toLowerCase().startsWith(finalArgs[0].toLowerCase())) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ }
+ });
+ return tabCompleter;
+ }
+ if (args.length == 3) {
+ for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
+ if (args[2].isEmpty()) {
+ tabCompleter.add(onlinePlayer.getName());
+ } else if (onlinePlayer.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
+ tabCompleter.add(onlinePlayer.getName());
+ }
+ }
+ return tabCompleter;
+ }
+ }
+ case "TP": {
+ if (args.length == 2) {
+ PlotManager.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())) {
+ tabCompleter.add(String.valueOf(plot.getID()));
+ }
+ });
+ return tabCompleter;
+ }
+ }
+ }
+ return tabCompleter;
+ }
+ return null;
+ }
+
+
+ public boolean assertPermission(CommandSender sender, String permission) {
+ return !sender.hasPermission(permission);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
new file mode 100644
index 0000000..1342d70
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
@@ -0,0 +1,65 @@
+package com.modnmetl.virtualrealty.commands;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException;
+import lombok.SneakyThrows;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+
+public abstract class SubCommand {
+
+ private final CommandSender commandSender;
+ private final LinkedList helpList;
+
+ @SneakyThrows
+ public SubCommand(CommandSender sender, Command command, String label, String[] args, LinkedList helpList) throws FailedCommandException {
+ this.helpList = helpList;
+ this.commandSender = sender;
+ exec(sender, command, label, args);
+ }
+
+ public abstract void exec(CommandSender sender, Command command, String label, String[] args) throws Exception;
+
+ public void assertPlayer() throws FailedCommandException {
+ if (!(commandSender instanceof Player)) {
+ commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cmdOnlyPlayers);
+ throw new FailedCommandException();
+ }
+ }
+
+ public void assertPermission(String permission) throws InsufficientPermissionsException {
+ if (!commandSender.hasPermission(permission)) {
+ if (commandSender.isOp()) {
+ commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", permission));
+ } else {
+ commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", permission));
+ }
+ throw new InsufficientPermissionsException();
+ }
+ }
+
+ public void printHelp() throws FailedCommandException {
+ for (String s : helpList) {
+ commandSender.sendMessage(s);
+ }
+ throw new FailedCommandException();
+ }
+
+ public static void registerSubCommands(String[] subCommand, Class> mainCommandClass) {
+ for (String s : subCommand) {
+ try {
+ Method method = CommandManager.class.getMethod("addSubCommand", String.class, Class.class);
+ method.setAccessible(true);
+ method.invoke(null, s, mainCommandClass);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
new file mode 100644
index 0000000..3495249
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
@@ -0,0 +1,76 @@
+package com.modnmetl.virtualrealty.commands.plot;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
+import java.util.logging.Level;
+
+public class PlotCommand implements CommandExecutor {
+
+ public static final LinkedList HELP_LIST = new LinkedList<>();
+
+ static {
+ HELP_LIST.add(" ");
+ HELP_LIST.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP_LIST.add(" §a/plot panel §8- §7Opens your plots panel");
+ HELP_LIST.add(" §a/plot draft §8- §7Shows layout of potential new plot");
+ HELP_LIST.add(" §a/plot stake §8- §7Creates the plot shown with draft");
+ HELP_LIST.add(" §a/plot info §8- §7Shows plot info");
+ HELP_LIST.add(" §a/plot gm §8- §7Changes gamemode");
+ HELP_LIST.add(" §a/plot add §8- §7Adds a member");
+ HELP_LIST.add(" §a/plot kick §8- §7Kicks a member");
+ HELP_LIST.add(" §a/plot list §8- §7Shows your plots");
+ HELP_LIST.add(" §a/plot tp §8- §7Teleports to the plot");
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ boolean displayError = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--error"));
+ args = Arrays.stream(args).filter(s1 -> !s1.equalsIgnoreCase("--error")).toArray(String[]::new);
+ if ((args.length > 0 && args[0].equalsIgnoreCase("help")) || args.length == 0) {
+ printHelp(sender);
+ return false;
+ }
+ if (args[0].equalsIgnoreCase("panel") || args[0].equalsIgnoreCase("draft") || args[0].equalsIgnoreCase("stake")) {
+ try {
+ Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getCustomClassLoader());
+ } catch (Exception e) {
+ sender.sendMessage("§aThis function is available with a valid license key");
+ sender.sendMessage("§aPlease visit §fhttps://modnmetl.com/ §ato purchase one");
+ return false;
+ }
+ }
+ try {
+ Class> clazz = Class.forName("com.modnmetl.virtualrealty.commands.plot.subcommand." + String.valueOf(args[0].toCharArray()[0]).toUpperCase(Locale.ROOT) + args[0].substring(1) + "SubCommand", true, VirtualRealty.getCustomClassLoader());
+ clazz.getConstructors()[0].newInstance(sender, command, label, args);
+ } catch (Exception e) {
+ if(!(e instanceof InvocationTargetException)) {
+ printHelp(sender);
+ return false;
+ }
+
+ if (displayError) {
+ 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.");
+ 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.");
+ }
+ }
+ return false;
+ }
+
+ private static void printHelp(CommandSender sender) {
+ for (String message : HELP_LIST) {
+ sender.sendMessage(message);
+ }
+ }
+
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..d91cdec
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java
@@ -0,0 +1,90 @@
+package com.modnmetl.virtualrealty.commands.plot.subcommand;
+
+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.PlotMember;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.time.LocalDateTime;
+import java.util.LinkedList;
+
+public class AddSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/plot add §8<§7plot§8> §8<§7player§8>");
+ }
+
+ public AddSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ assertPlayer();
+ Player player = ((Player) sender);
+ if (args.length < 3) {
+ printHelp();
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[2]);
+ if (offlinePlayer.getFirstPlayed() == 0) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ if (!plot.hasMembershipAccess(player.getUniqueId())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot);
+ return;
+ }
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plotMember != null) {
+ if (!plotMember.hasManagementPermission(ManagementPermission.ADD_MEMBER)) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ return;
+ }
+ } else {
+ if (plot.getPlotOwner().getUniqueId() != player.getUniqueId()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ return;
+ }
+ }
+ if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantAddYourself);
+ return;
+ }
+ if (plot.getMember(offlinePlayer.getUniqueId()) != null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().alreadyInMembers);
+ return;
+ }
+ plot.addMember(offlinePlayer.getUniqueId());
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerAdd.replaceAll("%player%", offlinePlayer.getName()));
+ }
+
+}
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
new file mode 100644
index 0000000..c8b89d8
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java
@@ -0,0 +1,90 @@
+package com.modnmetl.virtualrealty.commands.plot.subcommand;
+
+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.PlotMember;
+import org.bukkit.GameMode;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.LinkedList;
+
+public class GmSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/plot gm §8<§7gamemode§8>");
+ }
+
+ public GmSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ assertPlayer();
+ Player player = ((Player) sender);
+ if (args.length < 2) {
+ printHelp();
+ return;
+ }
+ if (VirtualRealty.getPluginConfiguration().lockPlotGamemode) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeFeatureDisabled);
+ return;
+ }
+ GameMode gameMode;
+ int gameModeID;
+ try {
+ gameMode = GameMode.valueOf(args[1]);
+ gameModeID = gameMode.getValue();
+ } catch (IllegalArgumentException e) {
+ try {
+ gameModeID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException ex) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().incorrectGamemode);
+ return;
+ }
+ }
+ GameMode defaultGamemode = VirtualRealty.getInstance().getServer().getDefaultGameMode();
+ GameMode configGamemode = VirtualRealty.getPluginConfiguration().getDefaultPlotGamemode();
+ if (!(gameModeID != configGamemode.getValue() && gameModeID != defaultGamemode.getValue())) {
+ gameMode = GameMode.getByValue(Integer.parseInt(args[1]));
+ } else {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeDisabled);
+ return;
+ }
+ Plot plot = PlotManager.getBorderedPlot(player.getLocation());
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode);
+ return;
+ }
+ if (!plot.hasMembershipAccess(player.getUniqueId())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode);
+ return;
+ }
+ if (plot.isOwnershipExpired()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (player.getGameMode().equals(gameMode)) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeAlreadySelected);
+ return;
+ }
+ if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(player.getUniqueId())) {
+ plot.setSelectedGameMode(gameMode);
+ } else {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ plotMember.setSelectedGameMode(gameMode);
+ }
+ player.setGameMode(gameMode);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeSwitched);
+ }
+
+}
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
new file mode 100644
index 0000000..d72cae3
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java
@@ -0,0 +1,56 @@
+package com.modnmetl.virtualrealty.commands.plot.subcommand;
+
+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 org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.LinkedList;
+
+public class InfoSubCommand extends SubCommand {
+
+ public InfoSubCommand(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);
+ Plot plot = PlotManager.getPlot(player.getLocation());
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot);
+ return;
+ }
+ printInfo(sender, plot);
+ }
+
+ 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"));
+ if (plot.getMembers().size() != 0) {
+ sender.sendMessage(" §7Members §8§l↴");
+ for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) {
+ sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName());
+ }
+ }
+ 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());
+ }
+
+}
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
new file mode 100644
index 0000000..c54b81b
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java
@@ -0,0 +1,87 @@
+package com.modnmetl.virtualrealty.commands.plot.subcommand;
+
+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.PlotMember;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.time.LocalDateTime;
+import java.util.LinkedList;
+
+public class KickSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/plot kick §8<§7plot§8> §8<§7player§8>");
+ }
+
+ public KickSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ assertPlayer();
+ Player player = ((Player) sender);
+ if (args.length < 3) {
+ printHelp();
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[2]);
+ if (offlinePlayer.getName() == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ if (!plot.hasMembershipAccess(player.getUniqueId())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot);
+ return;
+ }
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plotMember != null) {
+ if (!plotMember.hasManagementPermission(ManagementPermission.KICK_MEMBER)) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ return;
+ }
+ } else {
+ if (plot.getPlotOwner().getUniqueId() != player.getUniqueId()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noAccess);
+ return;
+ }
+ }
+ if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plot.getOwnedBy().equals(offlinePlayer.getUniqueId())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantKickYourself);
+ return;
+ }
+
+ plot.removeMember(plotMember);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerKick.replaceAll("%player%", offlinePlayer.getName()));
+ }
+
+}
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
new file mode 100644
index 0000000..83d21da
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java
@@ -0,0 +1,99 @@
+package com.modnmetl.virtualrealty.commands.plot.subcommand;
+
+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 net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.TextComponent;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.LinkedList;
+
+public class ListSubCommand extends SubCommand {
+
+ public ListSubCommand(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);
+ boolean hasPlot = false;
+ for (Plot plot : PlotManager.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()) {
+ if (plot.getMember(player.getUniqueId()) != null) {
+ isMember = true;
+ break;
+ }
+ }
+ if (!hasPlot && !isMember) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlayerPlotsFound);
+ return;
+ }
+ sender.sendMessage(" ");
+ sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ sender.sendMessage(" ");
+ 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()) {
+ if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) {
+ LocalDateTime localDateTime = plot.getOwnedUntilDate();
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
+ StringBuilder ownedBy = new StringBuilder();
+ ownedBy.append((plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : VirtualRealty.getMessages().available));
+ boolean isOwned = !ownedBy.toString().equals(VirtualRealty.getMessages().available);
+ for (int i = ownedBy.length(); i < 16; i++) {
+ ownedBy.append(" ");
+ }
+ StringBuilder size = new StringBuilder(plot.getPlotSize().name());
+ for (int i = size.length(); i < 6; i++) {
+ size.append(" ");
+ }
+ BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + (isOwned ? " " : "") + dateTimeFormatter.format(localDateTime) + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString());
+ sender.sendMessage(textComponent.toLegacyText());
+ }
+ }
+ sender.sendMessage("§7§m ");
+ }
+ if (isMember) {
+ sender.sendMessage(" ");
+ sender.sendMessage("§7 §fMember of §8§l↴");
+ sender.sendMessage(" ");
+ sender.sendMessage("§7§m ");
+ sender.sendMessage("§7| §a§l§oID§7 | §a§l§oOwned By§7 | §a§l§oSize§7 | §a§l§oPlot Center§7 |");
+ for (Plot plot : PlotManager.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));
+ boolean isOwned = !ownedBy.toString().equals(VirtualRealty.getMessages().available);
+ for (int i = ownedBy.length(); i < 16; i++) {
+ ownedBy.append(" ");
+ }
+ StringBuilder size = new StringBuilder(plot.getPlotSize().name());
+ for (int i = size.length(); i < 6; i++) {
+ size.append(" ");
+ }
+ BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + (isOwned ? " " : "") + ownedBy + "§8 §f" + size + "§8 §f" + plot.getCenter().toSimpleString());
+ sender.sendMessage(textComponent.toLegacyText());
+ }
+ }
+ sender.sendMessage("§7§m ");
+ }
+ }
+
+}
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
new file mode 100644
index 0000000..6dd15fd
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java
@@ -0,0 +1,62 @@
+package com.modnmetl.virtualrealty.commands.plot.subcommand;
+
+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 org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.LinkedList;
+import java.util.Objects;
+
+public class TpSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/plot tp §8<§7plot§8>");
+ }
+
+ public TpSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ assertPlayer();
+ Player player = ((Player) sender);
+ if (args.length < 2) {
+ printHelp();
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ if (!plot.hasMembershipAccess(player.getUniqueId())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notYourPlot);
+ return;
+ }
+ if (plot.isOwnershipExpired()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ plot.teleportPlayer(player);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
new file mode 100644
index 0000000..803eb60
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
@@ -0,0 +1,85 @@
+package com.modnmetl.virtualrealty.commands.vrplot;
+
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException;
+import org.bukkit.command.*;
+import org.bukkit.permissions.Permission;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
+import java.util.logging.Level;
+
+public class VirtualRealtyCommand implements CommandExecutor {
+
+ public static final Permission COMMAND_PERMISSION = new Permission(VirtualRealty.GLOBAL_PERMISSION.getName() + ".vrplot");
+
+ public static final LinkedList HELP_LIST = new LinkedList<>();
+
+ static {
+ HELP_LIST.add(" ");
+ HELP_LIST.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP_LIST.add(" §a/vrplot create §8- §7Creates a plot");
+ HELP_LIST.add(" §a/vrplot remove §8- §7Removes a plot");
+ HELP_LIST.add(" §a/vrplot set §8- §7Sets a variable for the plot");
+ HELP_LIST.add(" §a/vrplot assign §8- §7Assigns a plot to player");
+ HELP_LIST.add(" §a/vrplot unassign §8- §7Sets assigned to and assigned by to null");
+ HELP_LIST.add(" §a/vrplot info §8- §7Prints info about plot");
+ HELP_LIST.add(" §a/vrplot list §8- §7Prints all plots");
+ HELP_LIST.add(" §a/vrplot item §8- §7Creates plot item");
+ HELP_LIST.add(" §a/vrplot visual §8- §7Displays visual grid of the plot");
+ HELP_LIST.add(" §a/vrplot tp §8- §7Teleports to the plot");
+ HELP_LIST.add(" §a/vrplot reload §8- §7Reloads plugin");
+ }
+
+ @Override
+ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
+ boolean displayError = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--error"));
+ args = Arrays.stream(args).filter(s1 -> !s1.equalsIgnoreCase("--error")).toArray(String[]::new);
+ if (!sender.hasPermission(COMMAND_PERMISSION)) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", COMMAND_PERMISSION.getName()));
+ return false;
+ }
+ if ((args.length > 0 && args[0].equalsIgnoreCase("help")) || args.length == 0) {
+ printHelp(sender);
+ return false;
+ }
+ if (args[0].equalsIgnoreCase("visual") || args[0].equalsIgnoreCase("item")) {
+ try {
+ Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getCustomClassLoader());
+ } catch (Exception e) {
+ sender.sendMessage("§aThis function is available with a valid license key");
+ sender.sendMessage("§aPlease visit §fhttps://modnmetl.com/ §ato purchase one");
+ return false;
+ }
+ }
+ try {
+ Class> clazz = Class.forName("com.modnmetl.virtualrealty.commands.vrplot.subcommand." + String.valueOf(args[0].toCharArray()[0]).toUpperCase(Locale.ROOT) + args[0].substring(1) + "SubCommand", true, VirtualRealty.getCustomClassLoader());
+ clazz.getConstructors()[0].newInstance(sender, command, label, args);
+ } catch (Exception e) {
+ if(!(e instanceof InvocationTargetException)) {
+ printHelp(sender);
+ return false;
+ }
+ if (displayError) {
+ e.printStackTrace();
+ } else {
+ if (e.getCause() instanceof FailedCommandException) return false;
+ if (e.getCause() instanceof InsufficientPermissionsException) return false;
+ sender.sendMessage("§cAn error occurred while executing the command.");
+ sender.sendMessage("§cCheck console for details.");
+ 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.");
+ }
+ }
+ return false;
+ }
+
+ private static void printHelp(CommandSender sender) {
+ for (String message : HELP_LIST) {
+ sender.sendMessage(message);
+ }
+ }
+
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..125855d
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java
@@ -0,0 +1,83 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+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 org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.LinkedList;
+import java.util.UUID;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class AssignSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/vrplot assign §8<§7plot§8> §8<§7username§8>");
+ }
+
+ public AssignSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (args.length < 2) {
+ for (String helpMessage : HELP) {
+ sender.sendMessage(helpMessage);
+ }
+ return;
+ }
+ int plotID;
+ OfflinePlayer offlinePlayer;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ try {
+ if (UUIDUtils.isValidUUID(args[2])) {
+ offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(args[2]));
+ } else {
+ offlinePlayer = Bukkit.getOfflinePlayer(args[2]);
+ }
+ if (offlinePlayer.getName() == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ return;
+ }
+ } catch (NullPointerException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ if (sender instanceof Player) {
+ plot.setAssignedBy(((Player) sender).getUniqueId().toString());
+ } else if (sender instanceof ConsoleCommandSender) {
+ plot.setAssignedBy("CONSOLE");
+ } else {
+ 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()));
+ 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
new file mode 100644
index 0000000..631e88b
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java
@@ -0,0 +1,220 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+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 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.Location;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class CreateSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/vrplot create §8<§7small/medium/large/area§8> §8<§7floor (optional)§8> §8<§7border (optional)§8> §8<§7--natural(optional)§8>");
+ HELP.add(" §a/vrplot create §8<§7length§8> §8<§7height§8> §8<§7width§8> §8<§7floor (optional)§8> §8<§7border (optional)§8> §8<§7--natural(optional)§8>");
+ }
+
+ public CreateSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
+ assertPlayer();
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (args.length < 2) {
+ printHelp();
+ return;
+ }
+ Player player = ((Player) sender);
+ Location location = player.getLocation();
+ location.add(0, -1, 0);
+ if (Arrays.stream(PlotSize.values()).anyMatch(plotSize -> plotSize.name().equalsIgnoreCase(args[1])) && !args[1].equalsIgnoreCase(PlotSize.CUSTOM.name())) {
+ PlotSize plotSize = null;
+ try {
+ plotSize = PlotSize.valueOf(args[1].toUpperCase());
+ } catch (IllegalArgumentException ignored) {}
+ if (plotSize != null) {
+ Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth());
+ if (PlotManager.isColliding(cuboid) || PlotManager.getPlot(player.getLocation()) != null) {
+ 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 (plotSize != PlotSize.AREA) {
+ 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();
+ }
+ }.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 > 500 || width > 500 || height > 500) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().LHWHardLimit);
+ return;
+ }
+ Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width);
+ if (PlotManager.isColliding(cuboid) || PlotManager.getPlot(player.getLocation()) != null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting);
+ } else {
+ 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) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial);
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetFloorMaterial);
+ 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) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial);
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetBorderMaterial);
+ return;
+ }
+ if (args[5].split(":").length == 2) {
+ borderData = Byte.parseByte(args[5].split(":")[1]);
+ }
+ }
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
+ long timeStart = System.currentTimeMillis();
+ Plot plot = PlotManager.createPlot(location, PlotSize.CUSTOM, length, height, width, natural);
+ if (!natural) {
+ if (floorMaterial != null) {
+ plot.setFloorMaterial(floorMaterial, floorData);
+ }
+ if (borderMaterial != null) {
+ plot.setBorderMaterial(borderMaterial, borderData);
+ }
+ }
+ long timeEnd = System.currentTimeMillis();
+ BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
+ BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
+ BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
+ textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
+ textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
+ textComponent.addExtra(textComponent2);
+ textComponent.addExtra(textComponent3);
+ 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();
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 20);
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
new file mode 100644
index 0000000..c51a3d9
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
@@ -0,0 +1,110 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+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 org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.LinkedList;
+import java.util.UUID;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class InfoSubCommand extends SubCommand {
+
+ public InfoSubCommand(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 Exception {
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (args.length < 2) {
+ assertPlayer();
+ Plot plot = PlotManager.getPlot(((Player) sender).getLocation());
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot);
+ return;
+ }
+ printInfo(sender, plot);
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ if (PlotManager.getPlots().isEmpty()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots);
+ return;
+ }
+ if (plotID < PlotManager.getPlotMinID()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().minPlotID.replaceAll("%min_id%", String.valueOf(PlotManager.getPlotMinID())));
+ return;
+ }
+ if (plotID > PlotManager.getPlotMaxID()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().maxPlotID.replaceAll("%max_id%", String.valueOf(PlotManager.getPlotMaxID())));
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ printInfo(sender, plot);
+ }
+
+ private void printInfo(CommandSender sender, Plot plot) {
+ LocalDateTime localDateTime = plot.getOwnedUntilDate();
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
+ String assignedBy = VirtualRealty.getMessages().notAssigned;
+ if (plot.getAssignedBy() != null) {
+ switch (plot.getAssignedBy().toUpperCase()) {
+ case "CONSOLE": {
+ assignedBy = VirtualRealty.getMessages().assignedByConsole;
+ break;
+ }
+ case "SHOP_PURCHASE": {
+ assignedBy = VirtualRealty.getMessages().assignedByShopPurchase;
+ break;
+ }
+ default: {
+ OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(plot.getAssignedBy()));
+ assignedBy = (offlinePlayer.isOnline() ? "§a" : "§c") + offlinePlayer.getName();
+ }
+ }
+ }
+ sender.sendMessage(" ");
+ sender.sendMessage(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ sender.sendMessage(" §7Plot ID §8§l‣ §f" + plot.getID());
+ sender.sendMessage(" §7Owned By §8§l‣ §a" + (plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : "§cAvailable"));
+ if (plot.getMembers().size() != 0) {
+ sender.sendMessage(" §7Members §8§l↴");
+ for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) {
+ sender.sendMessage(" §8§l⁍ §" + (offlinePlayer.isOnline() ? "a" : "c") + offlinePlayer.getName());
+ }
+ }
+ sender.sendMessage(" §7Assigned By §8§l‣ §a" + assignedBy);
+ sender.sendMessage(" §7Owned Until §8§l‣ §f" + dateTimeFormatter.format(localDateTime));
+ sender.sendMessage(" §7Size §8§l‣ §f" + plot.getPlotSize());
+ sender.sendMessage(" §7Length §8§l‣ §f" + plot.getLength());
+ sender.sendMessage(" §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());
+ }
+
+}
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
new file mode 100644
index 0000000..a04fa23
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java
@@ -0,0 +1,62 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+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 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.command.Command;
+import org.bukkit.command.CommandSender;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.LinkedList;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class ListSubCommand extends SubCommand {
+
+ public ListSubCommand(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 Exception {
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (PlotManager.getPlots().isEmpty()) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots);
+ 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()) {
+ LocalDateTime localDateTime = plot.getOwnedUntilDate();
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
+ StringBuilder ownedBy = new StringBuilder();
+ ownedBy.append((plot.getOwnedBy() != null ? (Bukkit.getOfflinePlayer(plot.getOwnedBy()).isOnline() ? "§a" : "§c") + Bukkit.getOfflinePlayer(plot.getOwnedBy()).getName() : VirtualRealty.getMessages().available));
+ boolean isOwned = !ownedBy.toString().equals(VirtualRealty.getMessages().available);
+ for (int i = ownedBy.length(); i < 16; i++) {
+ ownedBy.append(" ");
+ }
+ StringBuilder size = new StringBuilder(plot.getPlotSize().name());
+ for (int i = size.length(); i < 6; i++) {
+ size.append(" ");
+ }
+ BaseComponent textComponent = new TextComponent("§f" + plot.getID() + "§8 §f" + 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);
+ }
+ sender.sendMessage("§7§m ");
+ }
+
+}
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
new file mode 100644
index 0000000..fdc275f
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java
@@ -0,0 +1,47 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+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 org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+import java.util.LinkedList;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class ReloadSubCommand extends SubCommand {
+
+ public ReloadSubCommand(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 Exception {
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ try {
+ VirtualRealty.getInstance().reloadConfigs();
+ if (VirtualRealty.getPluginConfiguration().dynmapMarkers) {
+ if (VirtualRealty.markerset != null) {
+ VirtualRealty.markerset.deleteMarkerSet();
+ }
+ VirtualRealty.getInstance().registerDynmap();
+ for (Plot plot : PlotManager.getPlots()) {
+ PlotManager.resetPlotMarker(plot);
+ }
+ } else {
+ if (VirtualRealty.markerset != null) {
+ VirtualRealty.markerset.deleteMarkerSet();
+ }
+ }
+ PlotManager.loadPlots();
+ VirtualRealty.getInstance().loadSizesConfiguration();
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().reloadComplete);
+ }
+
+}
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
new file mode 100644
index 0000000..aa7e2f3
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java
@@ -0,0 +1,52 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+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 org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+import java.util.LinkedList;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class RemoveSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/vrplot remove §8<§7plot§8>");
+ }
+
+ public RemoveSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (args.length < 2) {
+ printHelp();
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ plot.remove();
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().removedPlot);
+ }
+
+}
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
new file mode 100644
index 0000000..1b8ad67
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java
@@ -0,0 +1,243 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.commands.SubCommand;
+import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand;
+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 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.RemoteConsoleCommandSender;
+
+import java.time.LocalDateTime;
+import java.util.*;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class SetSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/vrplot set §8<§7plot§8> §aowner §8<§7username§8>");
+ HELP.add(" §a/vrplot set §8<§7plot§8> §afloor §8<§7material§8>");
+ HELP.add(" §a/vrplot set §8<§7plot§8> §aborder §8<§7material§8>");
+ HELP.add(" §a/vrplot set §8<§7plot§8> §aexpiry §8<§7dd/mm/YYYY§8> §8<§7HH:mm (optional)§8>");
+ }
+
+ public SetSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (args.length < 3) {
+ printHelp();
+ return;
+ }
+ switch (args[2].toUpperCase()) {
+ case "OWNER": {
+ assertPermission(COMMAND_PERMISSION.getName() + args[0].toLowerCase() + "." + args[2].toLowerCase());
+ if (args.length < 4) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyUsername);
+ return;
+ }
+ int plotID;
+ OfflinePlayer offlinePlayer;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ try {
+ if (UUIDUtils.isValidUUID(args[3])) {
+ offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(args[3]));
+ } else {
+ offlinePlayer = Bukkit.getOfflinePlayer(args[3]);
+ }
+ if (offlinePlayer.getName() == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ return;
+ }
+ } catch (NullPointerException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().playerNotFoundWithUsername);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ if (args.length >= 5) {
+ String dateFormat = args[4];
+ String timeFormat;
+ int year;
+ int month;
+ int dayOfMonth;
+ int hour = 0;
+ int minute = 0;
+ LocalDateTime localDateTime;
+ try {
+ year = Integer.parseInt(dateFormat.split("/")[2]);
+ month = Integer.parseInt(dateFormat.split("/")[1]);
+ dayOfMonth = Integer.parseInt(dateFormat.split("/")[0]);
+ if (args.length >= 6) {
+ timeFormat = args[5];
+ hour = Integer.parseInt(timeFormat.split(":")[0]);
+ minute = Integer.parseInt(timeFormat.split(":")[1]);
+ }
+ localDateTime = LocalDateTime.of(year, month, dayOfMonth, hour, minute);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().invalidDateProvided);
+ return;
+ }
+ plot.setOwnedUntilDate(localDateTime);
+ }
+ if (sender instanceof RemoteConsoleCommandSender && args.length >= 7 && args[6].equalsIgnoreCase("assign")) {
+ plot.setAssignedBy("SHOP_PURCHASE");
+ }
+ plot.setOwnedBy(offlinePlayer.getUniqueId());
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().assignedTo.replaceAll("%assigned_to%", offlinePlayer.getName()));
+ plot.update();
+ return;
+ }
+ case "FLOOR": {
+ assertPermission(COMMAND_PERMISSION.getName() + args[0].toLowerCase() + "." + args[2].toLowerCase());
+ if (args.length < 4) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyMaterialName);
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ Material material;
+ try {
+ material = Material.matchMaterial(args[3].split(":")[0].toUpperCase());
+ if (material == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial);
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ byte data = 0;
+ if (args[3].split(":").length == 2) {
+ data = Byte.parseByte(args[3].split(":")[1]);
+ }
+ plot.setFloorMaterial(material, data);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().newFloorMaterialSet);
+ plot.update();
+ return;
+ }
+ case "BORDER": {
+ assertPermission(COMMAND_PERMISSION.getName() + args[0].toLowerCase() + "." + args[2].toLowerCase());
+ if (args.length < 4) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyMaterialName);
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ Material material;
+ try {
+ material = VMaterial.getMaterial(args[3].split(":")[0].toUpperCase());
+ if (material == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial);
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantGetMaterial);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ byte data = 0;
+ if (args[3].split(":").length == 2) {
+ data = Byte.parseByte(args[3].split(":")[1]);
+ }
+ plot.setBorderMaterial(material, data);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().newBorderMaterialSet);
+ plot.update();
+ return;
+ }
+ case "EXPIRY": {
+ assertPermission(COMMAND_PERMISSION.getName() + args[0].toLowerCase() + "." + args[2].toLowerCase());
+ if (args.length < 4) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().specifyExpiryDate);
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ String dateFormat = args[3];
+ String timeFormat;
+ int year;
+ int month;
+ int dayOfMonth;
+ int hour = 0;
+ int minute = 0;
+ LocalDateTime localDateTime;
+ try {
+ year = Integer.parseInt(dateFormat.split("/")[2]);
+ month = Integer.parseInt(dateFormat.split("/")[1]);
+ dayOfMonth = Integer.parseInt(dateFormat.split("/")[0]);
+ if (args.length == 5) {
+ timeFormat = args[4];
+ hour = Integer.parseInt(timeFormat.split(":")[0]);
+ minute = Integer.parseInt(timeFormat.split(":")[1]);
+ }
+ localDateTime = LocalDateTime.of(year, month, dayOfMonth, hour, minute);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().invalidDateProvided);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ plot.setOwnedUntilDate(localDateTime);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownedUntilUpdated);
+ plot.update();
+ return;
+ }
+ default: {
+ for (String helpMessage : HELP) {
+ sender.sendMessage(helpMessage);
+ }
+ }
+ }
+ }
+
+}
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
new file mode 100644
index 0000000..73ce292
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java
@@ -0,0 +1,56 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+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 org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.LinkedList;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class TpSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/vrplot tp §8<§7plot§8>");
+ }
+
+ public TpSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
+ assertPlayer();
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (args.length < 2) {
+ printHelp();
+ return;
+ }
+ Player player = ((Player) sender);
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ plot.teleportPlayer(player);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().teleportedToPlot);
+ }
+
+}
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
new file mode 100644
index 0000000..bd9907e
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java
@@ -0,0 +1,55 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.commands.SubCommand;
+import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand;
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+import java.util.LinkedList;
+
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
+public class UnassignSubCommand extends SubCommand {
+
+ public static final LinkedList HELP = new LinkedList<>();
+
+ static {
+ HELP.add(" ");
+ HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
+ HELP.add(" §a/vrplot unassign §8<§7plot§8>");
+ }
+
+ public UnassignSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, HELP);
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
+ assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ if (args.length < 2) {
+ printHelp();
+ return;
+ }
+ int plotID;
+ try {
+ plotID = Integer.parseInt(args[1]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlotFound);
+ return;
+ }
+ plot.setAssignedBy(null);
+ plot.setOwnedBy(null);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().unassigned);
+ plot.update();
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
similarity index 57%
rename from src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java
rename to src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
index cdfa228..773fff9 100644
--- a/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
@@ -1,69 +1,124 @@
-package me.plytki.virtualrealty.configs;
+package com.modnmetl.virtualrealty.configs;
import eu.okaeri.configs.OkaeriConfig;
+import eu.okaeri.configs.annotation.Header;
+import eu.okaeri.configs.annotation.NameModifier;
+import eu.okaeri.configs.annotation.NameStrategy;
+import eu.okaeri.configs.annotation.Names;
+import java.util.Arrays;
+import java.util.List;
+
+@Header("-------------------------------------------------------------- #")
+@Header(" #")
+@Header(" Messages #")
+@Header(" #")
+@Header("-------------------------------------------------------------- #")
+@Names(strategy = NameStrategy.IDENTITY)
public class MessagesConfiguration extends OkaeriConfig {
+ //Core
+ public String reloadComplete = "§aReload complete!";
+ public String cmdOnlyPlayers = "§cCommand only for players!";
+ public String noAccess = "§cYou don't have access to this feature!";
+
+ //Markers
+ public String available = "§cAvailable";
+ public String assignedByConsole = "§eConsole";
+ public String assignedByShopPurchase = "§eShop Purchase";
+ public String notAssigned = "§cNot assigned";
+ public String creationPlotComponent1 = "§aPlot ";
+ public String creationPlotComponent2 = "§8#§7%plot_id%";
+ public String creationPlotComponent3 = " §acreated! §8(§7%creation_time% ms§8)";
+
+ //Checks
+ public String insufficientPermissionsShort = "§cInsufficient permissions!";
+ public String insufficientPermissions = "§cInsufficient permissions! §8(§7%permission%§8)";
public String useNaturalNumbersOnly = "§cUse only natural numbers!";
+ public String incorrectGamemode = "§cIncorrect gamemode value!";
+ public String sizeNotRecognised = "§cSize not recognized!";
+ public String LHWHardLimit = "§cL, W and H hard-limit is 500!";
+ public String specifyUsername = "§cSpecify username!";
+ public String playerNotFoundWithUsername = "§cCouldn't find player with specified username!";
+ public String invalidDateProvided = "§cInvalid date format provided!";
+ public String specifyMaterialName = "§cSpecify material name!";
+ public String specifyExpiryDate = "§cSpecify expiry date!";
+ public String minPlotID = "§cMinimum plot ID is %min_id%!";
+ public String maxPlotID = "§cMaximum plot ID is %max_id%!";
+
+ //Permissions
+ public String cantDoAnyDMG = "§cYou can't do any damage here!";
+ public String cantInteract = "§cYou can't interact here!";
+ public String cantBuildHere = "§cYou can't build here!";
+ public String cantRideOnPlot = "§cYou can't ride on someones plot!";
+
+ //Plot
public String noPlotFound = "§cCouldn't get plot with specified ID!";
public String notYourPlot = "§cIt's not your plot!";
public String ownershipExpired = "§cYour ownership has expired!";
public String teleportedToPlot = "§aYou have been teleported to the plot!";
public String gamemodeFeatureDisabled = "§cGamemode feature is disabled!";
- public String incorrectGamemode = "§cIncorrect gamemode value!";
public String gamemodeDisabled = "§cThis gamemode is disabled!";
public String cantSwitchGamemode = "§cYou can't switch gamemode here!";
- public String notStandingOnPlot = "§cYou aren't standing on any plot!";
- public String assignedByConsole = "§eConsole";
- public String assignedByShopPurchase = "§eShop Purchase";
public String noPlots = "§cThere are no plots!";
- public String available = "§cAvailable";
- public String reloadCompleted = "§aReload completed!";
+ public String noPlayerPlotsFound = "§cYou don't own any plot!";
public String cantCreateOnExisting = "§cYou can't create new plot over an existing plot!";
public String cantGetFloorMaterial = "§cCouldn't get floor material with specified name!";
public String cantGetBorderMaterial = "§cCouldn't get border material with specified name!";
public String cantGetMaterial = "§cCouldn't get material with specified name!";
public String notCollidingCreating = "§aNot colliding. Creating plot..";
public String clickToShowDetailedInfo = "§a§oClick to show detailed information about the plot! §8(§7ID: §f%plot_id%§8)";
- public String sizeNotRecognised = "§cSize not recognized!";
- public String LWHHardLimit = "§cL, W and H hard-limit is 500!";
- public String removedPlot = "§aSuccessfully removed plot!";
- public String specifyUsername = "§cSpecify username!";
- public String playerNotFoundWithUsername = "§cCouldn't find player with specified username!";
- public String invalidDateProvided = "§cInvalid date format provided!";
+ public String removedPlot = "§aPlot successfully removed!";
public String assignedTo = "§aPlot has been assigned to §f%assigned_to%!";
- public String specifyMaterialName = "§cSpecify material name!";
- public String specifyExpiryDate = "§cSpecify expiry date!";
public String newFloorMaterialSet = "§aNew floor material has been set!";
public String newBorderMaterialSet = "§aNew border material has been set!";
public String ownedUntilUpdated = "§aOwned until date has been updated!";
public String assignedToBy = "§aPlot has been assigned to §f%assigned_to% §aby §f%assigned_by%!";
- public String notAssigned = "§cNot assigned";
public String unassigned = "§aPlot has been unassigned!";
- public String minPlotID = "§cMinimum plot ID is %min_id%!";
- public String maxPlotID = "§cMaximum plot ID is %max_id%!";
- public String cmdOnlyPlayers = "§cCommand only for players!";
-
- public String enteredAvailablePlot = "§2You have entered an available plot!";
- public String enteredOwnedPlot = "§7You have entered §2%owner%'s §7plot!";
- public String leftAvailablePlot = "§cYou have left an available plot!";
- public String leftOwnedPlot = "§7You have left §2%owner%'s §7plot!";
- public String cantInteract = "§cYou can't interact here!";
- public String cantBuildHere = "§cYou can't build here!";
- public String cantRideOnPlot = "§cYou can't ride on someones plot!";
-
- public String creationPlotComponent1 = "§aPlot ";
- public String creationPlotComponent2 = "§8#§7%plot_id%";
- public String creationPlotComponent3 = " §acreated! §8(§7%creation_time% ms§8)";
-
public String cantAddYourself = "§cYou can't add yourself to the plot!";
public String cantKickYourself = "§cYou can't kick yourself from the plot!";
public String alreadyInMembers = "§cThis player is already one of the plot members!";
- public String notInMembers = "§cThis player is not one of the plot members!";
- public String cantDoAnyDMG = "§cYou can't do any damage here!";
+ public String standingOnPlot = "§cYou are standing on a plot!";
+ public String notStandingOnPlot = "§cYou aren't standing on any plot!";
public String playerKick = "§aPlayer §7%player% §ahas been kicked out of your plot!";
public String playerAdd = "§aPlayer §7%player% §ahas been added to your plot!";
public String gamemodeSwitched = "§aYour gamemode has changed!";
public String gamemodeAlreadySelected = "§cThis gamemode is already selected!";
+ public String noPlotMembers = "§cThis plot has no members.";
+
+ //Entrance
+ public String enteredAvailablePlot = "§2You have entered an available plot!";
+ public String enteredOwnedPlot = "§7You have entered §2%owner%'s §7plot!";
+ public String leftAvailablePlot = "§cYou have left an available plot!";
+ public String leftOwnedPlot = "§7You have left §2%owner%'s §7plot!";
+ public String enteredProtectedArea = "§6You have entered a protected area!";
+ public String leftProtectedArea = "§6You have left a protected area!";
+
+ //Draft
+ 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 draftModeCancelled = "§cDraft cancelled. Collision with another plot.";
+ public String draftModeCancelledCollision = "§cDraft cancelled. Collision with another plot.";
+ public String draftModeDisabledDueToDeath = "§cDraft mode has been disabled due to death.";
+ public List draftModeEnabled = Arrays.asList(
+ " ",
+ " §8§l«§8§m §8[§aDraft Mode§8]§m §8§l»",
+ " ",
+ " §8§l» §7Type §a/plot stake §7to place plot.",
+ " §8§l» §7If you want to leave draft mode type §a/plot draft",
+ " "
+ );
+
+ public String stakeCancelled = "§cStake cancelled.";
+ public List stakeConfirmation = Arrays.asList(
+ "§7You are about to stake your claim to the plot shown, once done you cannot undo.",
+ "§7Type §aYES §7to proceed."
+ );
+
+ //Other
+ public String visualBoundaryDisplayed = "§aThe visual boundary was displayed.";
+ public String visualBoundaryActive = "§cThe visual boundary is already active for this region.";
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java
new file mode 100644
index 0000000..1c432d5
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/PermissionsConfiguration.java
@@ -0,0 +1,51 @@
+package com.modnmetl.virtualrealty.configs;
+
+import com.modnmetl.virtualrealty.enums.permissions.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;
+
+@Header("-------------------------------------------------------------- #")
+@Header(" #")
+@Header(" Permissions #")
+@Header(" #")
+@Header("-------------------------------------------------------------- #")
+@Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE)
+public class PermissionsConfiguration extends OkaeriConfig {
+
+ @Comment("Available permissions ↓")
+ @Comment(" - BREAK")
+ @Comment(" - PLACE")
+ @Comment(" - CHEST_ACCESS")
+ @Comment(" - ARMOR_STAND")
+ @Comment(" - ENTITY_DAMAGE")
+ @Comment(" - SWITCH")
+ @Comment(" - ITEM_USE")
+ @Comment(" ")
+ @Comment("Set permissions for players who are not members of the plot.")
+ private final List defaultNonMembers = new LinkedList<>();
+
+ public List getDefaultNonMemberPlotPerms() {
+ return defaultNonMembers;
+ }
+
+ @Comment("Set permissions for players who are members of the plot.")
+ private final List defaultMembers = Arrays.asList(RegionPermission.values());
+
+ public List getDefaultMemberPerms() {
+ return defaultMembers;
+ }
+
+ @Comment("Set permissions for all players to the world")
+ public final List worldProtection = Arrays.asList(RegionPermission.values());
+
+ public List getWorldProtection() {
+ return worldProtection;
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java
new file mode 100644
index 0000000..8af198f
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/PluginConfiguration.java
@@ -0,0 +1,140 @@
+package com.modnmetl.virtualrealty.configs;
+
+import com.modnmetl.virtualrealty.enums.dynmap.HighlightType;
+import com.modnmetl.virtualrealty.enums.ServerVersion;
+import eu.okaeri.configs.OkaeriConfig;
+import eu.okaeri.configs.annotation.*;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import lombok.NoArgsConstructor;
+import org.bukkit.GameMode;
+
+@Header("-------------------------------------------------------------- #")
+@Header(" #")
+@Header(" Virtual Realty #")
+@Header(" #")
+@Header("-------------------------------------------------------------- #")
+@Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE)
+public class PluginConfiguration extends OkaeriConfig {
+
+ @Comment("Changing this value will break your plugin!")
+ @CustomKey("initial-version")
+ public String initServerVersion = VirtualRealty.legacyVersion ? ServerVersion.LEGACY.toString() : ServerVersion.MODERN.toString();
+
+ @Comment("Debug mode")
+ public boolean debugMode = false;
+
+ @Comment("Here you put your license details")
+ public License license = new License();
+
+ @Names(strategy = NameStrategy.IDENTITY)
+ public static class License extends OkaeriConfig {
+
+ public String key = "";
+ public String email = "";
+
+ }
+
+ @Comment("Set player gamemode to change when they enter their plot")
+ public boolean enablePlotGamemode = false;
+
+ @Comment("Set your wanted language (locale)")
+ public String locale = "en_GB";
+
+ @Comment("Set which gamemode players change to when they enter their plot")
+ @CustomKey("default-plot-gamemode")
+ public String plotGamemode = "SURVIVAL";
+
+ @Comment("Lock gamemode to plot default when player enters their plot (disables '/plot gm' command)")
+ public boolean lockPlotGamemode = false;
+
+ 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");
+ return GameMode.SURVIVAL;
+ }
+ }
+
+ @Comment("Enables dynmap plots highlighting")
+ @CustomKey("enable-dynmap-markers")
+ public boolean dynmapMarkers = false;
+
+ @Comment("Choose which type of plots should be highlighted on Dynmap page | Choose from: { ALL, AVAILABLE, OWNED }")
+ public HighlightType dynmapType = HighlightType.ALL;
+
+ @CustomKey("dynmap-markers")
+ public MarkerColor dynmapMarkersColor = new MarkerColor();
+
+ @Names(strategy = NameStrategy.IDENTITY)
+ public static class MarkerColor extends OkaeriConfig {
+
+ public Available available = new Available();
+ public Owned owned = new MarkerColor.Owned();
+
+ @Names(strategy = NameStrategy.IDENTITY)
+ public static class Available extends OkaeriConfig {
+
+ public String color = "#80eb34";
+ public double opacity = .3;
+
+ public int getHexColor() {
+ return Integer.decode("0x" + color.replaceAll("#", ""));
+ }
+
+ }
+
+ @Names(strategy = NameStrategy.IDENTITY)
+ public static class Owned extends OkaeriConfig {
+
+ public String color = "#ffbf00";
+ public double opacity = .45;
+
+ public int getHexColor() {
+ return Integer.decode("0x" + color.replaceAll("#", ""));
+ }
+
+ }
+
+ }
+
+ @Comment("Enables plots enter/leave sounds")
+ @CustomKey("plot-sounds")
+ public boolean plotSound = true;
+
+ @Comment("Type of data recording")
+ @Comment("SQLITE - Local database")
+ @Comment("MYSQL - External database")
+ @CustomKey("data-model")
+ public DataModel dataModel = DataModel.SQLITE;
+
+ @Comment("Data required to connect to the database")
+ @Comment("The plotsTableName section is the name of the VR data table in the database")
+ @Comment("It is best to change these names only if you really need to (e.g. there is a conflict with another plugin)")
+ @Comment("To rename tables when you already have some VR data in the database:")
+ @Comment("1. Turn off the server")
+ @Comment("2. Change data in VR config")
+ @Comment("3. Rename database tables using phpMyAdmin for example")
+ @CustomKey("mysql")
+ public MySQL mysql = new MySQL();
+
+ public enum DataModel {
+ SQLITE,
+ MYSQL
+ }
+
+ @Names(strategy = NameStrategy.IDENTITY)
+ @NoArgsConstructor
+ public static class MySQL extends OkaeriConfig {
+
+ public String hostname = "localhost";
+ public int port = 3306;
+ public String database = "db";
+ public String user = "root";
+ public String password = "passwd";
+ public String plotsTableName = "vr_plots";
+ public String plotMembersTableName = "vr_plot_members";
+
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/configs/SizesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java
similarity index 54%
rename from src/main/java/me/plytki/virtualrealty/configs/SizesConfiguration.java
rename to src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java
index 1751108..1df10df 100644
--- a/src/main/java/me/plytki/virtualrealty/configs/SizesConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/SizesConfiguration.java
@@ -1,27 +1,18 @@
-package me.plytki.virtualrealty.configs;
+package com.modnmetl.virtualrealty.configs;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.*;
-import me.plytki.virtualrealty.VirtualRealty;
-import me.plytki.virtualrealty.enums.PlotSize;
-import org.bukkit.Material;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.enums.PlotSize;
+import lombok.NoArgsConstructor;
-import java.time.Instant;
-
-@Header("################################################################")
-@Header("# #")
-@Header("# Plot Sizes #")
-@Header("# #")
-@Header("################################################################")
+@Header("--------------------------------------------------------------#")
+@Header(" #")
+@Header(" Plot Sizes #")
+@Header(" #")
+@Header("--------------------------------------------------------------#")
public class SizesConfiguration extends OkaeriConfig {
- @Comment(" ")
- @Comment("-------------------------")
- @Comment("Don't change this value!")
- @CustomKey("config-version")
- public final String configVersion = VirtualRealty.getInstance().getDescription().getVersion();
- @Comment("-------------------------")
-
@Comment(" ")
@Comment("(<1.13) Legacy Materials: https://helpch.at/docs/1.8/org/bukkit/Material.html")
@Comment("(>1.12) Post-Legacy Materials: https://helpch.at/docs/1.13/org/bukkit/Material.html")
@@ -31,47 +22,29 @@ public class SizesConfiguration extends OkaeriConfig {
public PlotSizes plotSizes = new PlotSizes();
@Names(strategy = NameStrategy.IDENTITY)
+ @NoArgsConstructor
public static class PlotSizes extends OkaeriConfig {
- @Variable("VR_SIZE_SMALL")
public Size SMALL = new Size(PlotSize.SMALL);
- @Variable("VR_SIZE_MEDIUM")
public Size MEDIUM = new Size(PlotSize.MEDIUM);
- @Variable("VR_SIZE_LARGE")
public Size LARGE = new Size(PlotSize.LARGE);
+ public CustomSize AREA = new CustomSize();
- public PlotSizes() {
- }
-
- public PlotSizes(Size small, Size medium, Size large) {
- this.SMALL = small;
- this.MEDIUM = medium;
- this.LARGE = large;
- }
+ @NoArgsConstructor
public static class Size extends OkaeriConfig {
- @Variable("VR_SIZE_FLOORMATERIAL")
@CustomKey("floor-material")
public String floorMaterial;
- @Variable("VR_SIZE_FLOORDATA")
@CustomKey("floor-data")
public byte floorData;
- @Variable("VR_SIZE_BORDERMATERIAL")
@CustomKey("border-material")
public String borderMaterial;
- @Variable("VR_SIZE_BORDERDATA")
@CustomKey("border-data")
public byte borderData;
- @Variable("VR_SIZE_LENGTH")
public int length;
- @Variable("VR_SIZE_WIDTH")
- public int width;
- @Variable("VR_SIZE_HEIGHT")
public int height;
-
- public Size() {
- }
+ public int width;
public Size(PlotSize plotSize) {
this.floorMaterial = plotSize.getFloorMaterial().name();
@@ -84,6 +57,16 @@ public Size(PlotSize plotSize) {
}
}
+
+ @NoArgsConstructor
+ public static class CustomSize extends OkaeriConfig {
+
+ public int length = PlotSize.AREA.getLength();
+ public int height = PlotSize.AREA.getHeight();
+ public int width = PlotSize.AREA.getWidth();
+
+ }
+
}
}
diff --git a/src/main/java/me/plytki/virtualrealty/enums/Direction.java b/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java
similarity index 92%
rename from src/main/java/me/plytki/virtualrealty/enums/Direction.java
rename to src/main/java/com/modnmetl/virtualrealty/enums/Direction.java
index a3d0c11..772a253 100644
--- a/src/main/java/me/plytki/virtualrealty/enums/Direction.java
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/Direction.java
@@ -1,45 +1,45 @@
-package me.plytki.virtualrealty.enums;
-
-public enum Direction {
-
- SOUTH(315, 45),
- WEST(45, 135),
- NORTH(135, 225),
- EAST(225, 315);
-
- private final float minYaw;
- private final float maxYaw;
-
- Direction(float minYaw, float maxYaw) {
- this.minYaw = minYaw;
- this.maxYaw = maxYaw;
- }
-
- public static Direction byYaw(float yaw) {
- float absoluteYaw = Math.abs(yaw);
- Direction direction = null;
- if(absoluteYaw > 315 || absoluteYaw <= 45) {
- //south
- direction = SOUTH;
- } else if(absoluteYaw > 45 && absoluteYaw <= 135) {
- //west
- direction = yaw > 0 ? WEST : EAST;
- } else if(absoluteYaw > 135 && absoluteYaw <= 225) {
- //north
- direction = NORTH;
- } else if(absoluteYaw > 225 && absoluteYaw <= 315) {
- //east
- direction = yaw > 0 ? EAST : WEST;
- }
- return direction;
- }
-
- public float getMaxYaw() {
- return maxYaw;
- }
-
- public float getMinYaw() {
- return minYaw;
- }
-
-}
+package com.modnmetl.virtualrealty.enums;
+
+public enum Direction {
+
+ SOUTH(315, 45),
+ WEST(45, 135),
+ NORTH(135, 225),
+ EAST(225, 315);
+
+ private final float minYaw;
+ private final float maxYaw;
+
+ Direction(float minYaw, float maxYaw) {
+ this.minYaw = minYaw;
+ this.maxYaw = maxYaw;
+ }
+
+ public static Direction byYaw(float yaw) {
+ float absoluteYaw = Math.abs(yaw);
+ Direction direction = null;
+ if(absoluteYaw > 315 || absoluteYaw <= 45) {
+ //south
+ direction = SOUTH;
+ } else if(absoluteYaw > 45 && absoluteYaw <= 135) {
+ //west
+ direction = yaw > 0 ? WEST : EAST;
+ } else if(absoluteYaw > 135 && absoluteYaw <= 225) {
+ //north
+ direction = NORTH;
+ } else if(absoluteYaw > 225 && absoluteYaw <= 315) {
+ //east
+ direction = yaw > 0 ? EAST : WEST;
+ }
+ return direction;
+ }
+
+ public float getMaxYaw() {
+ return maxYaw;
+ }
+
+ public float getMinYaw() {
+ return minYaw;
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/enums/HighlightType.java b/src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java
similarity index 61%
rename from src/main/java/me/plytki/virtualrealty/enums/HighlightType.java
rename to src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java
index dc8f244..d9e3bb9 100644
--- a/src/main/java/me/plytki/virtualrealty/enums/HighlightType.java
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/HighlightType.java
@@ -1,4 +1,4 @@
-package me.plytki.virtualrealty.enums;
+package com.modnmetl.virtualrealty.enums;
public enum HighlightType {
diff --git a/src/main/java/me/plytki/virtualrealty/enums/Permission.java b/src/main/java/com/modnmetl/virtualrealty/enums/Permission.java
similarity index 91%
rename from src/main/java/me/plytki/virtualrealty/enums/Permission.java
rename to src/main/java/com/modnmetl/virtualrealty/enums/Permission.java
index 3f0c433..e84f66c 100644
--- a/src/main/java/me/plytki/virtualrealty/enums/Permission.java
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/Permission.java
@@ -1,4 +1,4 @@
-package me.plytki.virtualrealty.enums;
+package com.modnmetl.virtualrealty.enums;
public enum Permission {
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java b/src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java
new file mode 100644
index 0000000..d35eadf
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/PlotSize.java
@@ -0,0 +1,65 @@
+package com.modnmetl.virtualrealty.enums;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import lombok.Data;
+import lombok.Getter;
+import org.bukkit.Material;
+
+@Getter
+public enum PlotSize {
+
+ SMALL(10, 10, 10, Material.matchMaterial(VirtualRealty.legacyVersion ? "GRASS" : "GRASS_BLOCK"), (byte)0, Material.matchMaterial(VirtualRealty.legacyVersion ? "STEP" : "STONE_BRICK_SLAB"), VirtualRealty.legacyVersion ? (byte)5 : (byte)0),
+ MEDIUM(25, 25, 25, Material.matchMaterial(VirtualRealty.legacyVersion ? "GRASS" : "GRASS_BLOCK"), (byte)0, Material.matchMaterial(VirtualRealty.legacyVersion ? "STEP" : "STONE_BRICK_SLAB"), VirtualRealty.legacyVersion ? (byte)5 : (byte)0),
+ LARGE(50, 50, 50, Material.matchMaterial(VirtualRealty.legacyVersion ? "GRASS" : "GRASS_BLOCK"), (byte)0, Material.matchMaterial(VirtualRealty.legacyVersion ? "STEP" : "STONE_BRICK_SLAB"), VirtualRealty.legacyVersion ? (byte)5 : (byte)0),
+ CUSTOM(0, 0, 0, Material.matchMaterial(VirtualRealty.legacyVersion ? "GRASS" : "GRASS_BLOCK"), (byte)0, Material.matchMaterial(VirtualRealty.legacyVersion ? "STEP" : "STONE_BRICK_SLAB"), VirtualRealty.legacyVersion ? (byte)5 : (byte)0),
+ AREA(0, 0, 0, Material.AIR, (byte)0, Material.AIR, (byte)0);
+
+ private int length;
+ private int height;
+ private int width;
+
+ private Material floorMaterial;
+ private byte floorData;
+ private Material borderMaterial;
+ private byte borderData;
+
+ PlotSize(int length, int height, int width, Material floorMaterial, byte floorData, Material borderMaterial, byte borderData) {
+ this.length = length;
+ this.height = height;
+ this.width = width;
+ this.floorMaterial = floorMaterial;
+ this.floorData = floorData;
+ this.borderMaterial = borderMaterial;
+ this.borderData = borderData;
+ }
+
+ public void setLength(int length) {
+ this.length = length;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+
+ public void setFloorMaterial(Material floorMaterial) {
+ this.floorMaterial = floorMaterial;
+ }
+
+ public void setFloorData(byte floorData) {
+ this.floorData = floorData;
+ }
+
+ public void setBorderMaterial(Material borderMaterial) {
+ this.borderMaterial = borderMaterial;
+ }
+
+ public void setBorderData(byte borderData) {
+ this.borderData = borderData;
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java b/src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java
new file mode 100644
index 0000000..951ab5a
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/ServerVersion.java
@@ -0,0 +1,8 @@
+package com.modnmetl.virtualrealty.enums;
+
+public enum ServerVersion {
+
+ LEGACY,
+ MODERN
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java b/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java
new file mode 100644
index 0000000..31ca896
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/dynmap/HighlightType.java
@@ -0,0 +1,9 @@
+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
new file mode 100644
index 0000000..5b8a7c9
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/items/VItem.java
@@ -0,0 +1,8 @@
+package com.modnmetl.virtualrealty.enums.items;
+
+public enum VItem {
+
+ CLAIM,
+ DRAFT
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java b/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java
new file mode 100644
index 0000000..b0a9157
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/materials/InteractMaterial.java
@@ -0,0 +1,144 @@
+package com.modnmetl.virtualrealty.enums.materials;
+
+public enum InteractMaterial {
+
+ WOODEN_DOOR,
+ IRON_DOOR_BLOCK,
+ WARPED_FENCE_GATE,
+ CRIMSON_FENCE_GATE,
+ WARPED_DOOR,
+ CRIMSON_DOOR,
+
+ ACACIA_DOOR,
+ ACACIA_FENCE_GATE,
+ ACACIA_BUTTON,
+ ACACIA_TRAPDOOR,
+ ANVIL,
+ ARMOR_STAND,
+ BARREL,
+ BEACON,
+ BED_BLOCK,
+ BELL,
+ BIRCH_BOAT,
+ BIRCH_BUTTON,
+ BIRCH_DOOR,
+ BIRCH_FENCE_GATE,
+ BIRCH_TRAPDOOR,
+ BLACK_BED,
+ BLACK_SHULKER_BOX,
+ BLAST_FURNACE,
+ BLUE_BED,
+ BLUE_SHULKER_BOX,
+ BREWING_STAND,
+ BROWN_BED,
+ BROWN_SHULKER_BOX,
+ CAMPFIRE,
+ CAULDRON,
+ CHEST,
+ CHEST_MINECART,
+ CHIPPED_ANVIL,
+ COMMAND,
+ COMMAND_BLOCK,
+ COMMAND_BLOCK_MINECART,
+ COMPARATOR,
+ COMPOSTER,
+ CRAFTING_TABLE,
+ CYAN_BED,
+ CYAN_SHULKER_BOX,
+ DAMAGED_ANVIL,
+ DARK_OAK_BOAT,
+ DARK_OAK_BUTTON,
+ DARK_OAK_FENCE_GATE,
+ DARK_OAK_TRAPDOOR,
+ DARK_OAK_DOOR,
+ DAYLIGHT_DETECTOR,
+ DAYLIGHT_DETECTOR_INVERTED,
+ DIODE,
+ DIODE_BLOCK_OFF,
+ DIODE_BLOCK_ON,
+ DISPENSER,
+ DOOR,
+ DRAGON_EGG,
+ DROPPER,
+ ENCHANTING_TABLE,
+ ENCHANTMENT_TABLE,
+ END_CRYSTAL,
+ END_PORTAL_FRAME,
+ ENDER_PORTAL_FRAME,
+ ENDER_CHEST,
+ EXPLOSIVE_MINECART,
+ FARMLAND,
+ FLETCHING_TABLE,
+ FLOWER_POT,
+ FURNACE,
+ FURNACE_MINECART,
+ GRAY_BED,
+ GRAY_SHULKER_BOX,
+ GREEN_BED,
+ GREEN_SHULKER_BOX,
+ HOPPER,
+ HOPPER_MINECART,
+ IRON_DOOR,
+ IRON_TRAPDOOR,
+ ITEM_FRAME,
+ JUKEBOX,
+ JUNGLE_BUTTON,
+ JUNGLE_BOAT,
+ JUNGLE_DOOR,
+ JUNGLE_FENCE_GATE,
+ LEVER,
+ LIGHT_BLUE_BED,
+ LIGHT_BLUE_SHULKER_BOX,
+ LIGHT_GRAY_BED,
+ LIGHT_GRAY_SHULKER_BOX,
+ LIME_BED,
+ LIME_SHULKER_BOX,
+ MAGENTA_BED,
+ MAGENTA_SHULKER_BOX,
+ MINECART,
+ NOTE_BLOCK,
+ OAK_BOAT,
+ OAK_BUTTON,
+ OAK_DOOR,
+ OAK_FENCE_GATE,
+ ORANGE_BED,
+ ORANGE_SHULKER_BOX,
+ PINK_BED,
+ PINK_SHULKER_BOX,
+ POWERED_MINECART,
+ PURPLE_BED,
+ PURPLE_SHULKER_BOX,
+ RED_BED,
+ RED_SHULKER_BOX,
+ REDSTONE_ORE,
+ REDSTONE_COMPARATOR_OFF,
+ REDSTONE_COMPARATOR_ON,
+ REPEATING_COMMAND_BLOCK,
+ REPEATER,
+ POWERED_REPEATER,
+ UNPOWERED_REPEATER,
+ REDSTONE_TORCH,
+ SADDLE,
+ SHULKER_BOX,
+ SIGN,
+ SIGN_POST,
+ SMITHING_TABLE,
+ SMOKER,
+ SPRUCE_BOAT,
+ SPRUCE_BUTTON,
+ SPRUCE_DOOR,
+ SPRUCE_FENCE_GATE,
+ STONECUTTER,
+ STONE_BUTTON,
+ STORAGE_MINECART,
+ TNT_MINECART,
+ TNT,
+ TRAP_DOOR,
+ TRAPPED_CHEST,
+ WHITE_BED,
+ WHITE_SHULKER_BOX,
+ WOOD_BUTTON,
+ YELLOW_BED,
+ YELOW_SHULKER_BOX;
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java b/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java
new file mode 100644
index 0000000..2e15752
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/materials/SwitchMaterial.java
@@ -0,0 +1,30 @@
+package com.modnmetl.virtualrealty.enums.materials;
+
+public enum SwitchMaterial {
+
+ WOOD_PLATE,
+ STONE_PLATE,
+ IRON_PLATE,
+ GOLD_PLATE,
+
+ STONE_BUTTON,
+ WOOD_BUTTON,
+ OAK_BUTTON,
+ ACACIA_BUTTON,
+ DARK_OAK_BUTTON,
+ WARPED_BUTTON,
+
+ TRIPWIRE,
+ COMPARATOR,
+ DIODE,
+ DIODE_BLOCK_OFF,
+ DIODE_BLOCK_ON,
+ REDSTONE_COMPARATOR_OFF,
+ REDSTONE_COMPARATOR_ON,
+ REPEATER,
+ POWERED_REPEATER,
+ UNPOWERED_REPEATER,
+ REDSTONE_TORCH,
+ LEVER
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java b/src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java
new file mode 100644
index 0000000..2267a22
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/permissions/ManagementPermission.java
@@ -0,0 +1,37 @@
+package com.modnmetl.virtualrealty.enums.permissions;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.utils.data.ItemBuilder;
+import lombok.Getter;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemFlag;
+
+@Getter
+public enum ManagementPermission {
+
+ ADD_MEMBER(0, "Add Members", new ItemBuilder(Material.DIAMOND_AXE).addItemFlag(ItemFlag.HIDE_ATTRIBUTES)),
+ KICK_MEMBER(1, "Kick Members", new ItemBuilder(Material.STONE_AXE).addItemFlag(ItemFlag.HIDE_ATTRIBUTES)),
+ PLOT_PERMISSIONS(2, "Plot Management", new ItemBuilder(VirtualRealty.legacyVersion ? Material.getMaterial("BOOK_AND_QUILL") : Material.WRITABLE_BOOK));
+
+ private final int slot;
+ private final String name;
+ private final ItemBuilder item;
+
+ ManagementPermission(int slot, String name, ItemBuilder item) {
+ this.slot = slot;
+ this.name = name;
+ this.item = item;
+ }
+
+ public static ManagementPermission getPermission(int i) {
+ for (ManagementPermission value : values()) {
+ if (value.getSlot() == i) return value;
+ }
+ return null;
+ }
+
+ public String getConfigName() {
+ return name().replaceAll("_", " ");
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java b/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java
new file mode 100644
index 0000000..6742998
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/enums/permissions/RegionPermission.java
@@ -0,0 +1,41 @@
+package com.modnmetl.virtualrealty.enums.permissions;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.utils.data.ItemBuilder;
+import lombok.Getter;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemFlag;
+
+@Getter
+public enum RegionPermission {
+
+ BREAK(0, "Break Blocks", new ItemBuilder(Material.STONE_PICKAXE).addItemFlag(ItemFlag.HIDE_ATTRIBUTES)),
+ PLACE(1, "Place Blocks", new ItemBuilder(VirtualRealty.legacyVersion ? Material.GRASS : Material.GRASS_BLOCK)),
+ CHEST_ACCESS(2, "Chest-Access", new ItemBuilder(Material.CHEST)),
+ ARMOR_STAND(3, "Armor Stand", new ItemBuilder(Material.ARMOR_STAND)),
+ ENTITY_DAMAGE(4, "Entity Damage", new ItemBuilder(Material.IRON_SWORD).addItemFlag(ItemFlag.HIDE_ATTRIBUTES)),
+ SWITCH(5, "Switch", new ItemBuilder(Material.LEVER)),
+ ITEM_USE(6, "Item Use", new ItemBuilder(Material.FLINT_AND_STEEL));
+
+ private final int slot;
+ private final String name;
+ private final ItemBuilder item;
+
+ RegionPermission(int slot, String name, ItemBuilder item) {
+ this.slot = slot;
+ this.name = name;
+ this.item = item;
+ }
+
+ public static RegionPermission getPermission(int i) {
+ for (RegionPermission value : values()) {
+ if (value.getSlot() == i) return value;
+ }
+ return null;
+ }
+
+ public String getConfigName() {
+ return name().replaceAll("_", " ");
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java b/src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java
new file mode 100644
index 0000000..b221512
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/exceptions/FailedCommandException.java
@@ -0,0 +1,9 @@
+package com.modnmetl.virtualrealty.exceptions;
+
+public class FailedCommandException extends Exception {
+
+ public FailedCommandException() {
+ super();
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java b/src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java
new file mode 100644
index 0000000..b56fdac
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/exceptions/InsufficientPermissionsException.java
@@ -0,0 +1,9 @@
+package com.modnmetl.virtualrealty.exceptions;
+
+public class InsufficientPermissionsException extends Exception {
+
+ public InsufficientPermissionsException() {
+ super();
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/exceptions/MaterialMatchException.java b/src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java
similarity index 75%
rename from src/main/java/me/plytki/virtualrealty/exceptions/MaterialMatchException.java
rename to src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java
index bfe84ec..a95b1cb 100644
--- a/src/main/java/me/plytki/virtualrealty/exceptions/MaterialMatchException.java
+++ b/src/main/java/com/modnmetl/virtualrealty/exceptions/MaterialMatchException.java
@@ -1,4 +1,4 @@
-package me.plytki.virtualrealty.exceptions;
+package com.modnmetl.virtualrealty.exceptions;
public class MaterialMatchException extends Exception {
@@ -6,4 +6,4 @@ public MaterialMatchException(String exception) {
super(exception);
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
similarity index 66%
rename from src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
index 4979ac1..cadefd3 100644
--- a/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
@@ -1,9 +1,10 @@
-package me.plytki.virtualrealty.listeners.plot;
+package com.modnmetl.virtualrealty.listeners;
-import me.plytki.virtualrealty.VirtualRealty;
-import me.plytki.virtualrealty.listeners.VirtualListener;
-import me.plytki.virtualrealty.managers.PlotManager;
-import me.plytki.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.enums.PlotSize;
+import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.objects.PlotMember;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -16,12 +17,13 @@
import java.util.AbstractMap;
import java.util.HashMap;
+import java.util.Map;
-public class PlotListener extends VirtualListener {
+public class PlotEntranceListener extends VirtualListener {
- public HashMap> enteredPlot = new HashMap<>();
+ public HashMap> enteredPlot = new HashMap<>();
- public PlotListener(VirtualRealty plugin) {
+ public PlotEntranceListener(VirtualRealty plugin) {
super(plugin);
}
@@ -41,29 +43,31 @@ public void onPlotMove(PlayerMoveEvent e) {
if (!enteredPlot.containsKey(player)) {
enteredPlot.put(player, new AbstractMap.SimpleEntry<>(plot, true));
Plot newPlot = enteredPlot.get(player).getKey();
- if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) {
- if (newPlot.getOwnedBy() != null && newPlot.getOwnedBy().equals(player.getUniqueId())) {
- if (newPlot.getSelectedGameMode() != VirtualRealty.getInstance().getServer().getDefaultGameMode() || newPlot.getSelectedGameMode() != VirtualRealty.getPluginConfiguration().getGameMode()) {
- newPlot.setSelectedGameMode(VirtualRealty.getPluginConfiguration().getGameMode());
+ if (VirtualRealty.getPluginConfiguration().enablePlotGamemode) {
+ if (newPlot.hasMembershipAccess(player.getUniqueId())) {
+ if (newPlot.getOwnedBy() != null && newPlot.getOwnedBy().equals(player.getUniqueId())) {
+ player.setGameMode(newPlot.getSelectedGameMode());
+ } else if (newPlot.getMember(player.getUniqueId()) != null) {
+ PlotMember plotMember = newPlot.getMember(player.getUniqueId());
+ player.setGameMode(plotMember.getSelectedGameMode());
}
- player.setGameMode(newPlot.getSelectedGameMode());
- } else if (newPlot.getMembers().contains(player.getUniqueId())) {
- player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode());
}
}
if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) {
if (VirtualRealty.getPluginConfiguration().plotSound) {
player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_OPEN, 0.4f, 0.8f);
}
- }
- if (!(VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8") || VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8"))) {
- player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(enterPlotString));
+ if (enteredPlot.get(player).getKey().getPlotSize() == PlotSize.AREA) {
+ player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(VirtualRealty.getMessages().enteredProtectedArea));
+ } else {
+ player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(enterPlotString));
+ }
}
} else {
if (!enteredPlot.get(player).getValue()) {
enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(plot, true));
- if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) {
- player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode());
+ if (VirtualRealty.getPluginConfiguration().enablePlotGamemode) {
+ player.setGameMode(VirtualRealty.getPluginConfiguration().getDefaultPlotGamemode());
}
}
}
@@ -75,8 +79,8 @@ public void onPlotMove(PlayerMoveEvent e) {
if (enteredPlot.get(player).getKey().getOwnedBy() != null) {
offlinePlayer = Bukkit.getOfflinePlayer(enteredPlot.get(player).getKey().getOwnedBy());
leavePlotString = VirtualRealty.getMessages().leftOwnedPlot.replaceAll("%owner%", offlinePlayer.getName()).replaceAll("%plot_id%", enteredPlot.get(player).getKey().getID() + "");
- if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) {
- if (enteredPlot.get(player).getKey().hasPlotMembership(player)) {
+ if (VirtualRealty.getPluginConfiguration().enablePlotGamemode) {
+ if (enteredPlot.get(player).getKey().hasMembershipAccess(player.getUniqueId())) {
player.setGameMode(Bukkit.getServer().getDefaultGameMode());
}
}
@@ -85,7 +89,9 @@ public void onPlotMove(PlayerMoveEvent e) {
if (VirtualRealty.getPluginConfiguration().plotSound) {
player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, 0.3f, 1f);
}
- if (!(VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8") || VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8"))) {
+ if (enteredPlot.get(player).getKey().getPlotSize() == PlotSize.AREA) {
+ player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(VirtualRealty.getMessages().leftProtectedArea));
+ } else {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(leavePlotString));
}
}
diff --git a/src/main/java/me/plytki/virtualrealty/listeners/VirtualListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java
similarity index 74%
rename from src/main/java/me/plytki/virtualrealty/listeners/VirtualListener.java
rename to src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java
index e612009..8a90af1 100644
--- a/src/main/java/me/plytki/virtualrealty/listeners/VirtualListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/VirtualListener.java
@@ -1,6 +1,6 @@
-package me.plytki.virtualrealty.listeners;
+package com.modnmetl.virtualrealty.listeners;
-import me.plytki.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.VirtualRealty;
import org.bukkit.event.Listener;
public class VirtualListener implements Listener {
@@ -9,9 +9,6 @@ public class VirtualListener implements Listener {
public VirtualListener(VirtualRealty plugin) {
this.plugin = plugin;
- }
-
- public void registerEvents() {
this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java
new file mode 100644
index 0000000..fff76ca
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java
@@ -0,0 +1,30 @@
+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.player.PlayerJoinEvent;
+
+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;
+ 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("§f§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);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java
new file mode 100644
index 0000000..20e1e0d
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/BorderProtectionListener.java
@@ -0,0 +1,40 @@
+package com.modnmetl.virtualrealty.listeners.protection;
+
+import com.modnmetl.virtualrealty.listeners.VirtualListener;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.block.BlockPlaceEvent;
+
+public class BorderProtectionListener extends VirtualListener {
+
+ public BorderProtectionListener(VirtualRealty plugin) {
+ super(plugin);
+ }
+
+ @EventHandler
+ public void onBorderBreak(BlockBreakEvent e) {
+ Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation());
+ if (plot == null) return;
+ if (e.getPlayer().isOp()) return;
+ if (plot.getBorderBlocks().contains(e.getBlock())) {
+ e.setCancelled(true);
+ e.getPlayer().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ }
+
+ @EventHandler
+ public void onBorderPlace(BlockPlaceEvent e) {
+ Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation());
+ if (plot == null) return;
+ if (e.getPlayer().isOp()) return;
+ if (plot.getBorderBlocks().contains(e.getBlock())) {
+ e.setCancelled(true);
+ e.getPlayer().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java
new file mode 100644
index 0000000..1d1ef52
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java
@@ -0,0 +1,612 @@
+package com.modnmetl.virtualrealty.listeners.protection;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.enums.materials.InteractMaterial;
+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.PlotMember;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockState;
+import org.bukkit.block.data.type.Switch;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.*;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.block.*;
+import org.bukkit.event.entity.*;
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
+import org.bukkit.event.player.*;
+import org.bukkit.event.vehicle.VehicleDestroyEvent;
+import org.bukkit.event.world.StructureGrowEvent;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.permissions.Permission;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.Objects;
+
+public class PlotProtectionListener extends VirtualListener {
+
+ public static final Permission PLOT_BUILD = new Permission("virtualrealty.build.plot");
+
+ public static final LinkedList INTERACTABLE = new LinkedList<>();
+ public static final LinkedList SWITCHABLE = new LinkedList<>();
+
+ static {
+ for (InteractMaterial value : InteractMaterial.values()) {
+ Material material = Material.getMaterial(value.toString());
+ if (Objects.nonNull(material)) {
+ INTERACTABLE.add(material);
+ }
+ }
+ for (SwitchMaterial value : SwitchMaterial.values()) {
+ Material material = Material.getMaterial(value.toString());
+ if (Objects.nonNull(material)) {
+ SWITCHABLE.add(material);
+ }
+ }
+ }
+
+ public PlotProtectionListener(VirtualRealty plugin) {
+ super(plugin);
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onBlockInteract(PlayerInteractEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ if (e.getClickedBlock() == null) return;
+ if (e.getClickedBlock().getType() == Material.CHEST) return;
+ if (!(e.getAction() == Action.PHYSICAL || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
+ if (player.isSneaking() && e.isBlockInHand()) return;
+ if (!(INTERACTABLE.contains(e.getClickedBlock().getType()) || SWITCHABLE.contains(e.getClickedBlock().getType()))) return;
+ if (!VirtualRealty.legacyVersion) {
+ if (e.getHand() == EquipmentSlot.OFF_HAND) return;
+ if (!e.getClickedBlock().getType().isInteractable()) return;
+ }
+ Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if ((!VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch) || SWITCHABLE.contains(e.getClickedBlock().getType())) {
+ if (!plotMember.hasPermission(RegionPermission.SWITCH)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ return;
+ }
+ if (INTERACTABLE.contains(e.getClickedBlock().getType())) {
+ if (!plotMember.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ } else {
+ if ((!VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch) || SWITCHABLE.contains(e.getClickedBlock().getType())) {
+ if (!plot.hasPermission(RegionPermission.SWITCH)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ return;
+ }
+ if (INTERACTABLE.contains(e.getClickedBlock().getType())) {
+ if (!plot.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onChestEvent(PlayerInteractEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ if (e.getClickedBlock() == null) return;
+ if (e.getClickedBlock().getType() != Material.CHEST) return;
+ if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
+ if (player.isSneaking() && e.isBlockInHand()) return;
+ Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.CHEST_ACCESS)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.CHEST_ACCESS)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onLiquidPlace(PlayerBucketEmptyEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ Plot plot = PlotManager.getBorderedPlot(e.getBlockClicked().getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onLiquidTake(PlayerBucketFillEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ Plot plot = PlotManager.getBorderedPlot(e.getBlockClicked().getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onBlockPlace(BlockPlaceEvent e) {
+ Player player = e.getPlayer();
+ Plot plot = PlotManager.getBorderedPlot(e.getBlockPlaced().getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.PLACE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.PLACE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onBlockBreak(BlockBreakEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ Plot plot = PlotManager.getBorderedPlot(e.getBlock().getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.BREAK)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.BREAK)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onPistonRetract(BlockPistonRetractEvent e) {
+ if (e.isCancelled()) return;
+ Block piston = e.getBlock();
+ Plot fromPlot = PlotManager.getPlot(piston.getLocation());
+ e.getBlocks().forEach(block -> {
+ Location toLocation = block.getLocation();
+ Plot toPlot = PlotManager.getPlot(toLocation);
+ Plot toBorderedPlot = PlotManager.getBorderedPlot(toLocation);
+ if (fromPlot != null) {
+ if (toPlot == null) {
+ e.setCancelled(true);
+ }
+ } else {
+ if (toBorderedPlot != null) {
+ e.setCancelled(true);
+ }
+ }
+ });
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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);
+ if (borderedPlot != null) {
+ if (plot == null) {
+ e.setCancelled(true);
+ } else if (plot.getID() != borderedPlot.getID()) {
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onIgniteEvent(BlockIgniteEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ if (player == null) return;
+ if (e.getIgnitingBlock() == null) return;
+ Plot plot = PlotManager.getBorderedPlot(e.getIgnitingBlock().getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ }
+
+ @EventHandler
+ 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());
+ if (toPlot != null && fromPlot == null) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onTreeGrow(StructureGrowEvent e) {
+ if (e.isCancelled()) return;
+ 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);
+ if (fromPlot != null) {
+ if (toPlot != null) {
+ if (fromPlot.getID() != toPlot.getID()) {
+ e.getBlocks().remove(block);
+ }
+ } else {
+ e.getBlocks().remove(block);
+ }
+ } else if (toPlot != null) {
+ e.getBlocks().remove(block);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onDragonEggMove(BlockFromToEvent e) {
+ if (e.isCancelled()) return;
+ Material block = e.getBlock().getType();
+ if (block == Material.DRAGON_EGG || block == Material.LAVA || block == Material.WATER) {
+ Location fromLocation = e.getBlock().getLocation();
+ Location toLocation = e.getToBlock().getLocation();
+ Plot fromPlot = PlotManager.getPlot(fromLocation);
+ Plot toPlot = PlotManager.getPlot(toLocation);
+ if (toPlot != null) {
+ if (fromPlot == null) {
+ e.setCancelled(true);
+ } else if (fromPlot.getID() != toPlot.getID()) {
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onProjectileLaunch(ProjectileLaunchEvent e) {
+ if (e.isCancelled()) return;
+ 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());
+ if (plot == null) return;
+ if (hasPermission(shooter, PLOT_BUILD)) return;
+ if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player) e.getEntity().getShooter()).getUniqueId()))
+ return;
+ if (plot.hasMembershipAccess(shooter.getUniqueId())) return;
+ e.getEntity().remove();
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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());
+ if (plot == null) return;
+ if (hasPermission(shooter, PLOT_BUILD)) return;
+ if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(((Player) e.getEntity().getShooter()).getUniqueId()))
+ return;
+ if (plot.hasMembershipAccess(shooter.getUniqueId())) return;
+ e.getEntity().remove();
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onArmorStandChange(PlayerArmorStandManipulateEvent e) {
+ if (e.isCancelled()) return;
+ Plot plot = PlotManager.getPlot(e.getPlayer().getLocation());
+ Player player = e.getPlayer();
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ARMOR_STAND)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ARMOR_STAND)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onItemFrameRotate(PlayerInteractEntityEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ Plot plot = PlotManager.getPlot(player.getLocation());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ }
+
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onEntityExplode(EntityExplodeEvent e) {
+ for (Block block : new ArrayList<>(e.blockList())) {
+ Plot plot = PlotManager.getBorderedPlot(block.getLocation());
+ if (plot != null)
+ e.blockList().remove(block);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onBlockExplode(BlockExplodeEvent e) {
+ for (Block block : new ArrayList<>(e.blockList())) {
+ Plot plot = PlotManager.getBorderedPlot(block.getLocation());
+ if (plot != null)
+ e.blockList().remove(block);
+ }
+ }
+
+ @EventHandler
+ public void onFireSpread(BlockSpreadEvent e) {
+ Plot plot = PlotManager.getBorderedPlot(e.getNewState().getLocation());
+ if (plot != null)
+ 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());
+ if (toPlot == null) return;
+ if (fromPlot != null) {
+ if (toPlot.getID() != fromPlot.getID()) {
+ e.setCancelled(true);
+ }
+ } else {
+ e.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) {
+ if (e.isCancelled()) return;
+ 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());
+ if (plot == null) return;
+ if (hasPermission(player, PLOT_BUILD)) return;
+ if (plot.hasMembershipAccess(player.getUniqueId())) {
+ PlotMember plotMember = plot.getMember(player.getUniqueId());
+ if (plot.isOwnershipExpired()) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
+ return;
+ }
+ if (plotMember == null) return;
+ if (!plotMember.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ } else {
+ if (!plot.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ }
+ }
+
+ public boolean hasPermission(CommandSender sender, Permission permission) {
+ return sender.hasPermission(permission);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java
new file mode 100644
index 0000000..1108722
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java
@@ -0,0 +1,205 @@
+package com.modnmetl.virtualrealty.listeners.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 org.bukkit.Material;
+import org.bukkit.block.BlockFace;
+import org.bukkit.block.data.type.Switch;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.Projectile;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.block.*;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
+import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
+import org.bukkit.event.player.PlayerInteractEntityEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.permissions.Permission;
+import org.bukkit.util.Vector;
+
+public class WorldProtectionListener extends VirtualListener {
+
+ public static final Permission WORLD_BUILD = new Permission("virtualrealty.build.world");
+
+ public WorldProtectionListener(VirtualRealty plugin) {
+ super(plugin);
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void onBlockInteract(PlayerInteractEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ if (e.getClickedBlock() == null) return;
+ if (e.getClickedBlock().getType() == Material.CHEST) return;
+ if (!(e.getAction() == Action.PHYSICAL || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
+ if (player.isSneaking() && e.isBlockInHand()) return;
+ if (!(PlotProtectionListener.INTERACTABLE.contains(e.getClickedBlock().getType()) || PlotProtectionListener.SWITCHABLE.contains(e.getClickedBlock().getType())))
+ return;
+ if (!VirtualRealty.legacyVersion) {
+ if (e.getHand() == EquipmentSlot.OFF_HAND) return;
+ if (!e.getClickedBlock().getType().isInteractable()) return;
+ }
+ Plot plot = PlotManager.getPlot(e.getClickedBlock().getLocation());
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ try {
+ if ((!VirtualRealty.legacyVersion && e.getClickedBlock().getBlockData() instanceof Switch) || PlotProtectionListener.SWITCHABLE.contains(e.getClickedBlock().getType())) {
+ Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", false, VirtualRealty.getCustomClassLoader());
+ if (!WorldUtil.hasPermission(RegionPermission.SWITCH)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ return;
+ }
+ if (PlotProtectionListener.INTERACTABLE.contains(e.getClickedBlock().getType())) {
+ Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", false, VirtualRealty.getCustomClassLoader());
+ if (!WorldUtil.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+ } catch (Exception ignored) {}
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onChestClick(PlayerInteractEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ if (e.getClickedBlock() == null) return;
+ 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());
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.CHEST_ACCESS)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onBlockPlace(BlockPlaceEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ Plot plot = PlotManager.getPlot(e.getBlockPlaced().getLocation());
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.PLACE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onBlockBreak(BlockBreakEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ Plot plot = PlotManager.getPlot(e.getBlock().getLocation());
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.BREAK)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantBuildHere);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onIgniteEvent(BlockIgniteEvent e) {
+ if (e.isCancelled()) return;
+ Player player = e.getPlayer();
+ if (player == null) return;
+ if (e.getIgnitingBlock() == null) return;
+ Plot plot = PlotManager.getBorderedPlot(e.getIgnitingBlock().getLocation());
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onArmorStandChange(PlayerArmorStandManipulateEvent e) {
+ if (e.isCancelled()) return;
+ Plot plot = PlotManager.getPlot(e.getPlayer().getLocation());
+ Player player = e.getPlayer();
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.ARMOR_STAND)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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());
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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());
+ if (plot != null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.ITEM_USE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
+ }
+ }
+
+
+ @EventHandler(priority = EventPriority.LOW)
+ 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());
+ if (plot == null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW)
+ public void onEntityProjectileDamage(EntityDamageByEntityEvent e) {
+ if (e.isCancelled()) return;
+ 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());
+ if (plot == null) return;
+ if (hasPermission(player, WORLD_BUILD)) return;
+ if (!WorldUtil.hasPermission(RegionPermission.ENTITY_DAMAGE)) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantDoAnyDMG);
+ }
+ }
+
+ public boolean hasPermission(CommandSender sender, Permission permission) {
+ return sender.hasPermission(permission);
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
similarity index 65%
rename from src/main/java/me/plytki/virtualrealty/managers/PlotManager.java
rename to src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
index 2ba6ba5..d90bd83 100644
--- a/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
@@ -1,186 +1,202 @@
-package me.plytki.virtualrealty.managers;
-
-import me.plytki.virtualrealty.VirtualRealty;
-import me.plytki.virtualrealty.enums.HighlightType;
-import me.plytki.virtualrealty.enums.PlotSize;
-import me.plytki.virtualrealty.objects.Cuboid;
-import me.plytki.virtualrealty.objects.Plot;
-import me.plytki.virtualrealty.objects.math.BlockVector2;
-import me.plytki.virtualrealty.objects.math.BlockVector3;
-import me.plytki.virtualrealty.sql.SQL;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.dynmap.markers.AreaMarker;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.*;
-
-public class PlotManager {
-
- private static final String markerString = "Plot #%s
Owned By: Available";
- private static final String markerOwnedString = "Plot #%s
Owned By: %s
Owned Until: %s";
-
- public static Set areaMarkers = new HashSet<>();
- public static Set plots = new LinkedHashSet<>();
-
- public static void loadPlots() {
- plots.clear();
- try {
- ResultSet rs = SQL.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) {
- Plot plot = new Plot(creationLocation, plotSize.getFloorMaterial(), plotSize.getBorderMaterial(), plotSize);
- plots.add(plot);
- plot.insert();
- return plot;
- }
-
- public static Plot createPlot(Location creationLocation, int length, int width, int height) {
- Plot plot = new Plot(creationLocation, Material.matchMaterial(VirtualRealty.isLegacy ? "GRASS" : "GRASS_BLOCK"), Material.matchMaterial(VirtualRealty.isLegacy ? "STEP" : "STONE_BRICK_SLAB"), length, width, height);
- plots.add(plot);
- plot.insert();
- return plot;
- }
-
- public static Plot getPlot(int ID) {
- for (Plot plot : plots) {
- if(plot.getID() == ID) {
- return plot;
- }
- }
- return null;
- }
-
- public static int getPlotMinID() {
- return plots.isEmpty() ? null : plots.stream().findFirst().get().getID();
- }
-
- public static int getPlotMaxID() {
- Plot[] plotArray = PlotManager.plots.toArray(new Plot[PlotManager.plots.size()]);
- Plot lastPlot = plotArray[plotArray.length - 1];
- return lastPlot.getID();
- }
-
- public static List getPlayerPlots(UUID owner) {
- List playerPlots = new ArrayList<>();
- for (Plot plot : plots) {
- 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.contains(newVector)) {
- return plot;
- }
- }
- return null;
- }
-
- 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.contains(newVector);
- }
-
- 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.contains(newVector)) {
- 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.contains(newVector);
- }
-
- public static boolean isColliding(Cuboid newPlot) {
- for (Plot plot : plots) {
- Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), plot.getCreatedLocation().getWorld());
- for (BlockVector2 vector2 : region.getWalls()) {
- if (vector2.containedWithin(newPlot.getMinimumPoint(), newPlot.getMaximumPoint())) {
- return true;
- }
- }
- }
- return false;
- }
-
- private static AreaMarker getAreaMarker(String areaMarkerName) {
- for (AreaMarker areaMarker : VirtualRealty.markerset.getAreaMarkers()) {
- if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) {
- return areaMarker;
- }
- }
- return null;
- }
-
- public static void resetPlotMarker(Plot plot) {
- if (!VirtualRealty.isDynmapPresent) return;
- LocalDateTime localDateTime = plot.getOwnedUntilDate();
- DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
- String ownedBy;
- double opacity;
- int color;
- if (plot.getOwnedBy() == null) {
- ownedBy = "Available";
- color = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.available.getHexColor();
- opacity = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.available.opacity;
- } else {
- ownedBy = plot.getPlotOwner().getName();
- color = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.owned.getHexColor();
- opacity = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.owned.opacity;
- }
- if (VirtualRealty.getPluginConfiguration().dynmapType == HighlightType.OWNED && plot.getOwnedBy() == null) return;
- if (VirtualRealty.getPluginConfiguration().dynmapType == HighlightType.AVAILABLE && plot.getOwnedBy() != null) return;
- AreaMarker marker = getAreaMarker("virtualrealty.plots." + plot.getID());
- if (marker == null) {
- marker = VirtualRealty.markerset.createAreaMarker("virtualrealty.plots." + plot.getID(),
-
- plot.getOwnedBy() == null ? String.format(markerString, plot.getID()) : String.format(markerOwnedString, plot.getID(), ownedBy, dateTimeFormatter.format(localDateTime)), true,
-
- plot.getCreatedWorld(), new double[]{plot.getXMin(), plot.getXMax()}, new double[]{plot.getZMin(), plot.getZMax()}, true);
-
- areaMarkers.add(marker);
- } else {
- marker.setLabel(
-
- plot.getOwnedBy() == null ? String.format(markerString, plot.getID()) : String.format(markerOwnedString, plot.getID(), ownedBy, dateTimeFormatter.format(localDateTime)), true);
-
- }
- marker.setFillStyle(opacity, color);
- marker.setLineStyle(2, 0.8, 0x474747);
- marker.setMarkerSet(VirtualRealty.markerset);
- }
-
- public static void removeDynMapMarker(Plot plot) {
- if (!VirtualRealty.isDynmapPresent || VirtualRealty.dapi == null || VirtualRealty.markerset == null) return;
- AreaMarker marker = VirtualRealty.markerset.findAreaMarker("virtualrealty.plots." + plot.getID());
- areaMarkers.remove(marker);
- marker.deleteMarker();
- }
-
+package com.modnmetl.virtualrealty.managers;
+
+import com.modnmetl.virtualrealty.enums.dynmap.HighlightType;
+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 org.dynmap.markers.AreaMarker;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+
+public class PlotManager {
+
+ private static final String MARKER_STRING = "Plot #%s
Owned By: Available";
+ private static final String MARKER_OWNED_STRING = "Plot #%s
Owned By: %s
Owned Until: %s";
+
+ public static Set areaMarkers = new HashSet<>();
+ @Getter
+ private static 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 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.contains(newVector)) {
+ 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.contains(newVector);
+ }
+
+ 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.contains(newVector)) {
+ 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.contains(newVector);
+ }
+
+ public static boolean isColliding(Cuboid newPlot) {
+ for (Plot plot : plots) {
+ Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), plot.getCreatedLocation().getWorld());
+ for (BlockVector2 vector2 : region.getWalls()) {
+ if (vector2.containedWithin(newPlot.getMinimumPoint(), newPlot.getMaximumPoint())) {
+ return plot.getCreatedWorldString().equals(newPlot.getWorld().getName());
+ }
+ }
+ }
+ return false;
+ }
+
+ private static AreaMarker getAreaMarker(String areaMarkerName) {
+ for (AreaMarker areaMarker : VirtualRealty.markerset.getAreaMarkers()) {
+ if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) {
+ return areaMarker;
+ }
+ }
+ return null;
+ }
+
+ public static void resetPlotMarker(Plot plot) {
+ if (!VirtualRealty.isDynmapPresent) return;
+ LocalDateTime localDateTime = plot.getOwnedUntilDate();
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
+ String ownedBy;
+ double opacity;
+ int color;
+ if (plot.getOwnedBy() == null) {
+ ownedBy = "Available";
+ color = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.available.getHexColor();
+ opacity = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.available.opacity;
+ } else {
+ ownedBy = plot.getPlotOwner().getName();
+ color = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.owned.getHexColor();
+ opacity = VirtualRealty.getPluginConfiguration().dynmapMarkersColor.owned.opacity;
+ }
+ if (VirtualRealty.getPluginConfiguration().dynmapType == HighlightType.OWNED && plot.getOwnedBy() == null) return;
+ if (VirtualRealty.getPluginConfiguration().dynmapType == HighlightType.AVAILABLE && plot.getOwnedBy() != null) return;
+ AreaMarker marker = getAreaMarker("virtualrealty.plots." + plot.getID());
+ if (marker == null) {
+ marker = VirtualRealty.markerset.createAreaMarker("virtualrealty.plots." + plot.getID(),
+ plot.getOwnedBy() == null ? String.format(MARKER_STRING, plot.getID()) : String.format(MARKER_OWNED_STRING, plot.getID(), ownedBy, dateTimeFormatter.format(localDateTime)), true,
+ plot.getCreatedWorldString(), new double[]{plot.getXMin(), plot.getXMax()}, new double[]{plot.getZMin(), plot.getZMax()}, true);
+ areaMarkers.add(marker);
+ } else {
+ marker.setLabel(
+ plot.getOwnedBy() == null ? String.format(MARKER_STRING, plot.getID()) : String.format(MARKER_OWNED_STRING, plot.getID(), ownedBy, dateTimeFormatter.format(localDateTime)), true);
+ }
+ marker.setFillStyle(opacity, color);
+ marker.setLineStyle(2, 0.8, 0x474747);
+ marker.setMarkerSet(VirtualRealty.markerset);
+ }
+
+ public static void removeDynMapMarker(Plot plot) {
+ if (!VirtualRealty.isDynmapPresent || VirtualRealty.dapi == null || VirtualRealty.markerset == null) return;
+ AreaMarker marker = VirtualRealty.markerset.findAreaMarker("virtualrealty.plots." + plot.getID());
+ areaMarkers.remove(marker);
+ marker.deleteMarker();
+ }
+
}
\ 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
new file mode 100644
index 0000000..71c6d19
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java
@@ -0,0 +1,23 @@
+package com.modnmetl.virtualrealty.managers;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.objects.PlotMember;
+import com.modnmetl.virtualrealty.sql.Database;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class PlotMemberManager {
+
+ public static void loadMembers() {
+ try {
+ ResultSet rs = Database.getInstance().getStatement().executeQuery("SELECT * FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "`");
+ while (rs.next()) {
+ new PlotMember(rs);
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java
new file mode 100644
index 0000000..f809421
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java
@@ -0,0 +1,676 @@
+package com.modnmetl.virtualrealty.objects;
+
+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.PlotManager;
+import com.modnmetl.virtualrealty.objects.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.VirtualRealty;
+import com.modnmetl.virtualrealty.objects.math.BlockVector3;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.SneakyThrows;
+import org.bukkit.*;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.util.*;
+
+@Getter
+@Setter
+public 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");
+ public static final DateTimeFormatter SHORT_PLOT_DATE_FORMAT = DateTimeFormatter.ofPattern("dd-MM-yyyy");
+
+ private int ID;
+ private UUID ownedBy;
+ public final LinkedList members;
+ public final Set nonMemberPermissions;
+ private String assignedBy;
+ private LocalDateTime ownedUntilDate;
+ private PlotSize plotSize;
+ private final int length, width, height;
+ private Material floorMaterial, borderMaterial;
+ private byte floorData, borderData;
+ private final Location createdLocation;
+ private final Direction createdDirection;
+ private BlockVector3 bottomLeftCorner, topRightCorner, borderBottomLeftCorner, borderTopRightCorner;
+ private GameMode selectedGameMode;
+ private final String createdWorld;
+ private Instant modified;
+ 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.ownedBy = null;
+ this.members = new LinkedList<>();
+ this.nonMemberPermissions = new HashSet<>(VirtualRealty.getPermissions().getDefaultNonMemberPlotPerms());
+ this.assignedBy = null;
+ this.ownedUntilDate = MAX_DATE;
+ if (natural) {
+ this.floorMaterial = Material.AIR;
+ this.floorData = 0;
+ this.borderMaterial = Material.AIR;
+ this.borderData = 0;
+ } else {
+ this.floorMaterial = floorMaterial;
+ this.floorData = 0;
+ this.borderMaterial = borderMaterial;
+ this.borderData = 0;
+ }
+ this.createdLocation = location;
+ this.createdDirection = Direction.byYaw(location.getYaw());
+ this.selectedGameMode = VirtualRealty.getPluginConfiguration().getDefaultPlotGamemode();
+ this.createdWorld = location.getWorld().getName();
+ this.modified = Instant.now();
+ this.createdAt = LocalDateTime.now();
+ this.plotSize = plotSize;
+ this.length = length;
+ this.width = width;
+ this.height = height;
+ initialize(natural);
+ if (VirtualRealty.markerset != null) {
+ PlotManager.resetPlotMarker(this);
+ }
+ }
+
+ @SneakyThrows
+ public Plot(ResultSet rs) {
+ this.ID = rs.getInt("ID");
+ this.ownedBy = rs.getString("ownedBy").isEmpty() ? null : UUID.fromString(rs.getString("ownedBy"));
+ this.members = new LinkedList<>();
+ Set plotPermissions = new HashSet<>();
+ if (!rs.getString("nonMemberPermissions").isEmpty()) {
+ for (String s : rs.getString("nonMemberPermissions").split("¦")) {
+ plotPermissions.add(RegionPermission.valueOf(s.toUpperCase()));
+ }
+ }
+ this.nonMemberPermissions = plotPermissions;
+ 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);
+ } else {
+ this.ownedUntilDate = rs.getTimestamp("ownedUntilDate").toLocalDateTime();
+ if (rs.getTimestamp("created") != null)
+ this.createdAt = rs.getTimestamp("created").toLocalDateTime();
+ }
+ this.floorMaterial = Material.getMaterial(rs.getString("floorMaterial").split(":")[0]);
+ this.floorData = rs.getString("floorMaterial").split(":").length == 1 ? 0 : Byte.parseByte(rs.getString("floorMaterial").split(":")[1]);
+ if (rs.getString("borderMaterial") != null) {
+ this.borderMaterial = Material.getMaterial(rs.getString("borderMaterial").split(":")[0]);
+ this.borderData = rs.getString("borderMaterial").split(":").length == 1 ? 0 : Byte.parseByte(rs.getString("borderMaterial").split(":")[1]);
+ }
+ this.plotSize = PlotSize.valueOf(rs.getString("plotSize"));
+ this.length = rs.getInt("length");
+ this.width = rs.getInt("width");
+ this.height = rs.getInt("height");
+ ArrayList location = new ArrayList<>(Arrays.asList(rs.getString("createdLocation").subSequence(0, rs.getString("createdLocation").length() - 1).toString().split(";")));
+ Location createLocation = new Location(Bukkit.getWorld(location.get(0)), Double.parseDouble(location.get(1)), Double.parseDouble(location.get(2)), Double.parseDouble(location.get(3)), Float.parseFloat(location.get(4)), Float.parseFloat(location.get(5)));
+ this.createdLocation = rs.getString("createdLocation").isEmpty() ? null : createLocation;
+ this.createdDirection = Direction.byYaw(createdLocation.getYaw());
+ if (!rs.getString("selectedGameMode").isEmpty() && EnumUtils.isValidEnum(GameMode.class, rs.getString("selectedGameMode"))) {
+ this.selectedGameMode = GameMode.valueOf(rs.getString("selectedGameMode"));
+ } else {
+ this.selectedGameMode = VirtualRealty.getPluginConfiguration().getDefaultPlotGamemode();
+ }
+ this.createdWorld = location.get(0);
+ if (floorMaterial == null) {
+ floorMaterial = plotSize.getFloorMaterial();
+ floorData = plotSize.getFloorData();
+ }
+ if (borderMaterial == null) {
+ borderMaterial = plotSize.getBorderMaterial();
+ borderData = plotSize.getBorderData();
+ }
+ prepareCorners();
+ }
+
+ public String getFloorMaterialName() {
+ if (this.floorMaterial == Material.AIR) return "NONE";
+ return this.floorMaterial.name();
+ }
+
+ public String getBorderMaterialName() {
+ if (this.borderMaterial == Material.AIR) return "NONE";
+ return this.borderMaterial.name();
+ }
+
+ public void teleportPlayer(Player player) {
+ Location loc = new Location(createdLocation.getWorld(), getCenter().getBlockX(), getCenter().getBlockY() + 1, getCenter().getBlockZ());
+ if (!createdLocation.getWorld().getName().endsWith("_nether")) {
+ loc.setY(Objects.requireNonNull(loc.getWorld()).getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY() + 1);
+ }
+ player.teleport(loc);
+ }
+
+ public boolean hasMembershipAccess(UUID uuid) {
+ PlotMember member = getMember(uuid);
+ if (member != null || (ownedBy != null && getPlotOwner().getUniqueId() == uuid)) return true;
+ return false;
+ }
+
+ public void togglePermission(RegionPermission plotPermission) {
+ modified();
+ if (nonMemberPermissions.contains(plotPermission)) {
+ nonMemberPermissions.remove(plotPermission);
+ } else {
+ nonMemberPermissions.add(plotPermission);
+ }
+ }
+
+ public boolean hasPermission(RegionPermission plotPermission) {
+ return nonMemberPermissions.contains(plotPermission);
+ }
+
+ public void addPermission(RegionPermission plotPermission) {
+ nonMemberPermissions.add(plotPermission);
+ }
+
+ public void removePermission(RegionPermission plotPermission) {
+ nonMemberPermissions.remove(plotPermission);
+ }
+
+ public PlotMember getMember(UUID uuid) {
+ for (PlotMember member : members) {
+ if (member.getUuid().equals(uuid)) {
+ return member;
+ }
+ }
+ return null;
+ }
+
+ public void addMember(UUID uuid) {
+ PlotMember plotMember = new PlotMember(uuid, this);
+ members.add(plotMember);
+ plotMember.insert();
+ }
+
+ public void removeMember(PlotMember plotMember) {
+ members.remove(plotMember);
+ plotMember.delete();
+ }
+
+ public boolean isOwnershipExpired() {
+ return ownedUntilDate.isBefore(LocalDateTime.now());
+ }
+
+ public int getXMin() {
+ return Math.min(this.getBorderBottomLeftCorner().getBlockX(), this.borderTopRightCorner.getBlockX());
+ }
+
+ public int getXMax() {
+ return Math.max(this.getBorderBottomLeftCorner().getBlockX(), this.borderTopRightCorner.getBlockX());
+ }
+
+ public int getZMin() {
+ return Math.min(this.getBorderBottomLeftCorner().getBlockZ(), this.borderTopRightCorner.getBlockZ());
+ }
+
+ public int getZMax() {
+ return Math.max(this.getBorderBottomLeftCorner().getBlockZ(), this.borderTopRightCorner.getBlockZ());
+ }
+
+ public void setOwnedBy(UUID ownedBy) {
+ modified();
+ this.ownedBy = ownedBy;
+ PlotMember plotMember = getMember(ownedBy);
+ if (plotMember != null) {
+ removeMember(plotMember);
+ }
+ updateMarker();
+ }
+
+ public void setOwnedUntilDate(LocalDateTime ownedUntilDate) {
+ modified();
+ this.ownedUntilDate = ownedUntilDate;
+ updateMarker();
+ }
+
+ public void setFloorMaterial(Material floorMaterial, byte data) {
+ modified();
+ this.floorMaterial = floorMaterial;
+ this.floorData = 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;
+ this. borderData = data;
+ for (Block borderBlock : getBorderBlocks()) {
+ if (VirtualRealty.legacyVersion) {
+ borderBlock.setType(borderMaterial);
+ try {
+ Method m2 = Block.class.getDeclaredMethod("setData", byte.class);
+ m2.setAccessible(true);
+ m2.invoke(borderBlock, data);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ } else {
+ borderBlock.setType(borderMaterial);
+ }
+ }
+ }
+
+ public BlockVector3 getBorderedCenter() {
+ return new Cuboid(borderBottomLeftCorner, borderTopRightCorner, createdLocation.getWorld()).getCenterVector();
+ }
+
+ public BlockVector3 getCenter() {
+ return new Cuboid(bottomLeftCorner, topRightCorner, createdLocation.getWorld()).getCenterVector();
+ }
+
+ public org.bukkit.World getCreatedWorld() {
+ return Bukkit.getWorld(createdWorld);
+ }
+
+ public String getCreatedWorldString() {
+ return createdWorld;
+ }
+
+ public OfflinePlayer getPlotOwner() {
+ return ownedBy == null ? null : Bukkit.getOfflinePlayer(ownedBy);
+ }
+
+ public Set getPlayerMembers() {
+ Set offlinePlayers = new HashSet<>();
+ for (PlotMember member : members) {
+ OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(member.getUuid());
+ offlinePlayers.add(offlinePlayer);
+ }
+ return offlinePlayers;
+ }
+
+ public void prepareCorners() {
+ Location location = createdLocation;
+ Direction direction = Direction.byYaw(location.getYaw());
+ Location location1;
+ Location location2;
+ Location border1;
+ Location border2;
+ switch(direction) {
+ case SOUTH: {
+ location1 = new Location(location.getWorld(), location.getBlockX(), location.getBlockY() - 10, location.getBlockZ());
+ location2 = new Location(location.getWorld(), location.getBlockX() - width + 1, location.getBlockY() + height, location.getBlockZ() + length - 1);
+ border1 = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() - 1);
+ border2 = new Location(location.getWorld(), location.getBlockX() - width, location.getBlockY() + height, location.getBlockZ() + length);
+ break;
+ }
+ case WEST: {
+ location1 = new Location(location.getWorld(), location.getBlockX(), location.getBlockY() - 10, location.getBlockZ());
+ location2 = new Location(location.getWorld(), location.getBlockX() - length + 1, location.getBlockY() + height, location.getBlockZ() - width + 1);
+ border1 = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() + 1);
+ border2 = new Location(location.getWorld(), location.getBlockX() - length, location.getBlockY() + height, location.getBlockZ() - width);
+ break;
+ }
+ case NORTH: {
+ location1 = new Location(location.getWorld(), location.getBlockX(), location.getBlockY() - 10, location.getBlockZ());
+ location2 = new Location(location.getWorld(), location.getBlockX() + width - 1, location.getBlockY() + height, location.getBlockZ() - length + 1);
+ border1 = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() - 10, location.getBlockZ() + 1);
+ border2 = new Location(location.getWorld(), location.getBlockX() + width, location.getBlockY() + height, location.getBlockZ() - length);
+ break;
+ }
+ case EAST: {
+ location1 = new Location(location.getWorld(), location.getBlockX() + length - 1, location.getBlockY() - 10, location.getBlockZ());
+ location2 = new Location(location.getWorld(), location.getBlockX(), location.getBlockY() + height, location.getBlockZ() + width - 1);
+ border1 = new Location(location.getWorld(), location.getBlockX() + length, location.getBlockY() - 10, location.getBlockZ() - 1);
+ border2 = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() + height, location.getBlockZ() + width);
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected value: " + direction);
+ }
+ this.bottomLeftCorner = BlockVector3.at(location1.getBlockX(), location1.getBlockY(), location1.getBlockZ());
+ this.topRightCorner = BlockVector3.at(location2.getBlockX(), location2.getBlockY(), location2.getBlockZ());
+ this.borderBottomLeftCorner = BlockVector3.at(border1.getBlockX(), border1.getBlockY(), border1.getBlockZ());
+ this.borderTopRightCorner = BlockVector3.at(border2.getBlockX(), border2.getBlockY(), border2.getBlockZ());
+ }
+
+ public void initialize(boolean natural) {
+ long time = System.currentTimeMillis();
+ prepareCorners();
+ if (plotSize == PlotSize.AREA) return;
+ prepareBlocks(createdLocation, natural);
+ VirtualRealty.debug("Plot initialize time: " + (System.currentTimeMillis() - time) + " ms");
+ }
+
+ public Set getBorderBlocks() {
+ Set blocks = new HashSet<>();
+ Location location = this.getCreatedLocation();
+ Direction direction = Direction.byYaw(location.getYaw());
+ int maxX;
+ int maxZ;
+ int minX;
+ int minZ;
+ switch(direction) {
+ case SOUTH: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + length + 1;
+ minX = location.getBlockX() - width + 1;
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ case WEST: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX() - length + 1;
+ minZ = location.getBlockZ() - width;
+ break;
+ }
+ case NORTH: {
+ maxX = location.getBlockX() + width + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - length;
+ break;
+ }
+ case EAST: {
+ maxX = location.getBlockX() + length + 1;
+ maxZ = location.getBlockZ() + width + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected value: " + direction);
+ }
+ for (int x = minX - 1; x < maxX; x++) {
+ for (int z = minZ; z < maxZ; z++) {
+ if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) {
+ blocks.add(location.getWorld().getBlockAt(x, location.getBlockY() + 1, z));
+ }
+ }
+ }
+ return blocks;
+ }
+
+ public Set getFloorBlocks() {
+ Set blocks = new HashSet<>();
+ Location location = this.getCreatedLocation();
+ Direction direction = Direction.byYaw(location.getYaw());
+ int maxX;
+ int maxZ;
+ int minX;
+ int minZ;
+ switch(direction) {
+ case SOUTH: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + length + 1;
+ minX = location.getBlockX() - width + 1;
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ case WEST: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX() - length + 1;
+ minZ = location.getBlockZ() - width;
+ break;
+ }
+ case NORTH: {
+ maxX = location.getBlockX() + width + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - length;
+ break;
+ }
+ case EAST: {
+ maxX = location.getBlockX() + length + 1;
+ maxZ = location.getBlockZ() + width + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected value: " + direction);
+ }
+ for (int x = minX - 1; x < maxX; x++) {
+ for (int z = minZ; z < maxZ; z++) {
+ blocks.add(location.getWorld().getBlockAt(x, location.getBlockY(), z));
+ }
+ }
+ return blocks;
+ }
+
+ public void prepareBlocks(Location location, boolean natural) {
+ Direction direction = Direction.byYaw(location.getYaw());
+ Location location1;
+ Location location2;
+ switch (direction) {
+ 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()));
+ 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()));
+ 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()));
+ 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()));
+ break;
+ }
+ }
+ if (natural) return;
+ for (Block floorBlock : getFloorBlocks()) {
+ for (int y = location.getBlockY() + height; y > location.getBlockY() - 1; y--) {
+ Block airBlock = location.getWorld().getBlockAt(floorBlock.getX(), y, floorBlock.getZ());
+ airBlock.setType(Material.AIR, false);
+ }
+ floorBlock.setType(floorMaterial);
+ if (VirtualRealty.legacyVersion) {
+ try {
+ Method m2 = Block.class.getDeclaredMethod("setData", byte.class);
+ m2.setAccessible(true);
+ m2.invoke(floorBlock, plotSize.getFloorData());
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ int maxX = 0;
+ int maxZ = 0;
+ int minX = 0;
+ int minZ = 0;
+ switch(direction) {
+ case SOUTH: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + length + 1;
+ minX = location.getBlockX() - width + 1;
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ case WEST: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX() - length + 1;
+ minZ = location.getBlockZ() - width;
+ break;
+ }
+ case NORTH: {
+ maxX = location.getBlockX() + width + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - length;
+ break;
+ }
+ case EAST: {
+ maxX = location.getBlockX() + length + 1;
+ maxZ = location.getBlockZ() + width + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ }
+ for (int x = minX - 1; x < maxX; x++) {
+ for (int z = minZ; z < maxZ; z++) {
+ if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) {
+ Block borderBlock = location.getWorld().getBlockAt(x, location.getBlockY() + 1, z);
+ if (VirtualRealty.legacyVersion) {
+ borderBlock.setType(plotSize.getBorderMaterial());
+ try {
+ Method m2 = Block.class.getDeclaredMethod("setData", byte.class);
+ m2.setAccessible(true);
+ m2.invoke(borderBlock, plotSize.getBorderData());
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ } else {
+ borderBlock.setType(plotSize.getBorderMaterial());
+ }
+ }
+ }
+ }
+ }
+
+ public void unloadPlot() {
+ if (SchematicUtil.isOldSerialization(ID)) {
+ Location location = null;
+ switch (createdDirection) {
+ case SOUTH: {
+ location = new Location(createdLocation.getWorld(), createdLocation.getBlockX() - width, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1);
+ break;
+ }
+ case WEST: {
+ location = new Location(createdLocation.getWorld(), createdLocation.getBlockX() - length, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - width);
+ break;
+ }
+ case NORTH: {
+ location = new Location(createdLocation.getWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - length);
+ break;
+ }
+ case EAST: {
+ location = new Location(createdLocation.getWorld(), createdLocation.getBlockX() - 1, createdLocation.getBlockY() - 10, createdLocation.getBlockZ() - 1);
+ break;
+ }
+ }
+ OldSchematicUtil.paste(ID, location);
+ } else {
+ long time = System.currentTimeMillis();
+ SchematicUtil.paste(ID);
+ VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms");
+ }
+ }
+
+ private void modified() {
+ modified = Instant.now();
+ }
+
+ @SneakyThrows
+ public void insert() {
+ String serializedLocation =
+ this.createdLocation.getWorld().getName() + ";" +
+ this.createdLocation.getX() + ";" +
+ this.createdLocation.getY() + ";" +
+ this.createdLocation.getZ() + ";" +
+ this.createdLocation.getYaw() + ";" +
+ this.createdLocation.getPitch() + ";";
+ 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()
+ + "')");
+ }
+
+ @SneakyThrows
+ public void update() {
+ StringBuilder permissions = new StringBuilder();
+ for (RegionPermission permission : this.nonMemberPermissions) {
+ permissions.append(permission.name()).append("¦");
+ }
+ Database.getInstance().getStatement().execute("UPDATE `" +
+ VirtualRealty.getPluginConfiguration().mysql.plotsTableName +
+ "` SET `ownedBy`='" + (this.ownedBy == null ? "" : this.ownedBy.toString()) + "'," +
+ " `nonMemberPermissions`='" + permissions + "'," +
+ " `assignedBy`='" + this.assignedBy + "'," +
+ " `ownedUntilDate`='" + Timestamp.valueOf(this.ownedUntilDate) + "'," +
+ " `floorMaterial`='" + this.floorMaterial + ":" + this.floorData + "'," +
+ " `borderMaterial`='" + this.borderMaterial + ":" + this.borderData + "'," +
+ " `plotSize`='" + this.plotSize + "'," +
+ " `length`='" + this.length + "'," +
+ " `width`='" + this.width + "'," +
+ " `height`='" + this.height + "'," +
+ " `modified`='" + (this.modified != null ? Timestamp.from(this.modified) : Timestamp.from(Instant.now())) + "'," +
+ " `selectedGameMode`='" + this.selectedGameMode.name() + "'" +
+ " WHERE `ID`='" + this.ID + "'");
+ }
+
+ public void remove() {
+ this.unloadPlot();
+ for (PlotMember member : this.getMembers()) {
+ removeMember(member);
+ }
+ PlotManager.removeDynMapMarker(this);
+ try {
+ Database.getInstance().getStatement().execute("DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` WHERE `ID` = '" + ID + "';");
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ SchematicUtil.deletePlotFile(ID);
+ PlotManager.removePlotFromList(this);
+ }
+
+ public Direction getCreatedDirection() {
+ return createdDirection;
+ }
+
+ public void updateMarker() {
+ PlotManager.resetPlotMarker(this);
+ }
+
+ @Override
+ public String toString() {
+ return "{ ID: " + ID + ", ownedBy: " + ownedBy + "}";
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/PlotMember.java b/src/main/java/com/modnmetl/virtualrealty/objects/PlotMember.java
new file mode 100644
index 0000000..b9a2575
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/PlotMember.java
@@ -0,0 +1,140 @@
+package com.modnmetl.virtualrealty.objects;
+
+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.sql.Database;
+import lombok.Data;
+import lombok.Setter;
+import lombok.SneakyThrows;
+import org.bukkit.GameMode;
+
+import java.sql.ResultSet;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+@Data
+public class PlotMember {
+
+ private final UUID uuid;
+ private final Plot plot;
+ private GameMode selectedGameMode;
+ private final Set permissions;
+ private final Set managementPermissions;
+
+ public PlotMember(UUID uuid, Plot plot) {
+ this.uuid = uuid;
+ this.plot = plot;
+ this.selectedGameMode = plot.getSelectedGameMode();
+ this.permissions = new HashSet<>(VirtualRealty.getPermissions().getDefaultMemberPerms());
+ this.managementPermissions = new HashSet<>();
+ }
+
+ @SneakyThrows
+ public PlotMember(ResultSet rs) {
+ this.uuid = UUID.fromString(rs.getString("uuid"));
+ Plot plot = PlotManager.getPlot(rs.getInt("plot"));
+ this.plot = plot;
+ this.selectedGameMode = GameMode.valueOf(rs.getString("selectedGameMode"));
+ Set plotPermissions = new HashSet<>();
+ if (!rs.getString("permissions").isEmpty()) {
+ for (String s : rs.getString("permissions").split("¦")) {
+ plotPermissions.add(RegionPermission.valueOf(s.toUpperCase()));
+ }
+ }
+ this.permissions = plotPermissions;
+ Set managementPermissions = new HashSet<>();
+ if (!rs.getString("managementPermissions").isEmpty()) {
+ for (String s : rs.getString("managementPermissions").split("¦")) {
+ managementPermissions.add(ManagementPermission.valueOf(s.toUpperCase()));
+ }
+ }
+ this.managementPermissions = managementPermissions;
+ if (plot != null)
+ plot.members.add(this);
+ }
+
+ public void togglePermission(RegionPermission plotPermission) {
+ if (permissions.contains(plotPermission)) {
+ permissions.remove(plotPermission);
+ } else {
+ permissions.add(plotPermission);
+ }
+ }
+
+ public boolean hasPermission(RegionPermission plotPermission) {
+ return permissions.contains(plotPermission);
+ }
+
+ public void addPermission(RegionPermission plotPermission) {
+ permissions.add(plotPermission);
+ }
+
+ public void removePermission(RegionPermission plotPermission) {
+ permissions.remove(plotPermission);
+ }
+
+
+ public void toggleManagementPermission(ManagementPermission managementPermission) {
+ if (managementPermissions.contains(managementPermission)) {
+ managementPermissions.remove(managementPermission);
+ } else {
+ managementPermissions.add(managementPermission);
+ }
+ }
+
+ public boolean hasManagementPermission(ManagementPermission managementPermission) {
+ return managementPermissions.contains(managementPermission);
+ }
+
+ public void addManagementPermission(ManagementPermission managementPermission) {
+ managementPermissions.add(managementPermission);
+ }
+
+ public void removeManagementPermission(ManagementPermission managementPermission) {
+ managementPermissions.remove(managementPermission);
+ }
+
+
+ @SneakyThrows
+ public void insert() {
+ StringBuilder permissions = new StringBuilder();
+ for (RegionPermission permission : this.permissions) {
+ permissions.append(permission.name()).append("¦");
+ }
+ StringBuilder managementPermissions = new StringBuilder();
+ 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
+ + "')");
+ }
+
+ @SneakyThrows
+ public void update() {
+ StringBuilder permissions = new StringBuilder();
+ for (RegionPermission permission : this.permissions) {
+ permissions.append(permission.name()).append("¦");
+ }
+ StringBuilder managementPermissions = new StringBuilder();
+ 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() + "'");
+ }
+
+ @SneakyThrows
+ public void delete() {
+ Database.getInstance().getStatement().execute("DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotMembersTableName + "` WHERE `uuid` = '" + this.uuid + "' AND `plot`=" + plot.getID() + ";");
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/objects/math/BlockVector2.java b/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
similarity index 89%
rename from src/main/java/me/plytki/virtualrealty/objects/math/BlockVector2.java
rename to src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
index 7101190..6512d7e 100644
--- a/src/main/java/me/plytki/virtualrealty/objects/math/BlockVector2.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
@@ -1,44 +1,44 @@
-package me.plytki.virtualrealty.objects.math;
-
-import java.util.Vector;
-
-public class BlockVector2 extends Vector {
-
- private int x;
- private int z;
-
- public BlockVector2(int x, int z) {
- this.x = x;
- this.z = z;
- }
-
- public static BlockVector2 at(int x, int z) {
- return new BlockVector2(x, z);
- }
-
- public int getBlockX() {
- return x;
- }
-
- public void setX(int x) {
- this.x = x;
- }
-
- public int getBlockZ() {
- return z;
- }
-
- public void setZ(int z) {
- this.z = z;
- }
-
- public boolean containedWithin(BlockVector2 min, BlockVector2 max) {
- return this.x >= min.x && this.x <= max.x && this.z >= min.z && this.z <= max.z;
- }
-
- @Override
- public String toString() {
- return "(" + x + ", " + z + ")";
- }
-
-}
+package com.modnmetl.virtualrealty.objects.math;
+
+import java.util.Vector;
+
+public class BlockVector2 extends Vector {
+
+ private int x;
+ private int z;
+
+ public BlockVector2(int x, int z) {
+ this.x = x;
+ this.z = z;
+ }
+
+ public static BlockVector2 at(int x, int z) {
+ return new BlockVector2(x, z);
+ }
+
+ public int getBlockX() {
+ return x;
+ }
+
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public int getBlockZ() {
+ return z;
+ }
+
+ public void setZ(int z) {
+ this.z = z;
+ }
+
+ public boolean containedWithin(BlockVector2 min, BlockVector2 max) {
+ return this.x >= min.x && this.x <= max.x && this.z >= min.z && this.z <= max.z;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + z + ")";
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/objects/math/BlockVector3.java b/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java
similarity index 81%
rename from src/main/java/me/plytki/virtualrealty/objects/math/BlockVector3.java
rename to src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java
index 1194dd5..d8acf26 100644
--- a/src/main/java/me/plytki/virtualrealty/objects/math/BlockVector3.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector3.java
@@ -1,59 +1,65 @@
-package me.plytki.virtualrealty.objects.math;
-
-import org.bukkit.Location;
-
-public class BlockVector3 extends BlockVector2 {
-
- private int x;
- private int y;
- private int z;
-
- private BlockVector3(int x, int y, int z) {
- super(x, z);
- this.x = x;
- this.y = y;
- this.z = z;
- }
-
- public static BlockVector3 at(int x, int y, int z) {
- return new BlockVector3(x, y, z);
- }
-
- public static BlockVector3 locationToVector(Location location) {
- return new BlockVector3(location.getBlockX(), location.getBlockY(), location.getBlockZ());
- }
-
- public int getBlockX() {
- return x;
- }
-
- public void setX(int x) {
- this.x = x;
- }
-
- public int getBlockY() {
- return y;
- }
-
- public void setY(int y) {
- this.y = y;
- }
-
- public int getBlockZ() {
- return z;
- }
-
- public void setZ(int z) {
- this.z = z;
- }
-
- @Override
- public String toString() {
- return "(" + x + ", " + y + ", " + z + ")";
- }
-
- public String toSimpleString() {
- return x + ", " + y + ", " + z;
- }
-
-}
+package com.modnmetl.virtualrealty.objects.math;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+
+public class BlockVector3 extends BlockVector2 {
+
+ private int x;
+ private int y;
+ private int z;
+
+ private BlockVector3(int x, int y, int z) {
+ super(x, z);
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public static BlockVector3 at(int x, int y, int z) {
+ return new BlockVector3(x, y, z);
+ }
+
+ public static BlockVector3 toVector(Location location) {
+ return new BlockVector3(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ }
+
+ public Location toLocation(World world) {
+ return new Location(world, x, y, z);
+ }
+
+ public int getBlockX() {
+ return x;
+ }
+
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public int getBlockY() {
+ return y;
+ }
+
+ public void setY(int y) {
+ this.y = y;
+ }
+
+ public int getBlockZ() {
+ return z;
+ }
+
+ public void setZ(int z) {
+ this.z = z;
+ }
+
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + y + ", " + z + ")";
+ }
+
+ public String toSimpleString() {
+ return x + ", " + y + ", " + z;
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/objects/Cuboid.java b/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
similarity index 89%
rename from src/main/java/me/plytki/virtualrealty/objects/Cuboid.java
rename to src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
index 1273672..88d72ba 100644
--- a/src/main/java/me/plytki/virtualrealty/objects/Cuboid.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
@@ -1,187 +1,192 @@
-package me.plytki.virtualrealty.objects;
-
-import me.plytki.virtualrealty.objects.math.BlockVector2;
-import me.plytki.virtualrealty.objects.math.BlockVector3;
-import org.bukkit.Location;
-import org.bukkit.World;
-import org.bukkit.block.Block;
-import org.bukkit.entity.Player;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-public class Cuboid {
-
- private int xMin;
- private int xMax;
- private int yMin;
- private int yMax;
- private int zMin;
- private int zMax;
- private double xMinCentered;
- private double xMaxCentered;
- private double yMinCentered;
- private double yMaxCentered;
- private double zMinCentered;
- private double zMaxCentered;
- private World world;
-
- public Cuboid(Location point1, Location point2) {
- this.xMin = Math.min(point1.getBlockX(), point2.getBlockX());
- this.xMax = Math.max(point1.getBlockX(), point2.getBlockX());
- this.yMin = Math.min(point1.getBlockY(), point2.getBlockY());
- this.yMax = Math.max(point1.getBlockY(), point2.getBlockY());
- this.zMin = Math.min(point1.getBlockZ(), point2.getBlockZ());
- this.zMax = Math.max(point1.getBlockZ(), point2.getBlockZ());
- this.world = point1.getWorld();
- this.xMinCentered = this.xMin + 0.5;
- this.xMaxCentered = this.xMax + 0.5;
- this.yMinCentered = this.yMin + 0.5;
- this.yMaxCentered = this.yMax + 0.5;
- this.zMinCentered = this.zMin + 0.5;
- this.zMaxCentered = this.zMax + 0.5;
- }
-
- public Cuboid(BlockVector3 point1, BlockVector3 point2, World world) {
- this.xMin = Math.min(point1.getBlockX(), point2.getBlockX());
- this.xMax = Math.max(point1.getBlockX(), point2.getBlockX());
- this.yMin = Math.min(point1.getBlockY(), point2.getBlockY());
- this.yMax = Math.max(point1.getBlockY(), point2.getBlockY());
- this.zMin = Math.min(point1.getBlockZ(), point2.getBlockZ());
- this.zMax = Math.max(point1.getBlockZ(), point2.getBlockZ());
- this.world = world;
- this.xMinCentered = this.xMin + 0.5;
- this.xMaxCentered = this.xMax + 0.5;
- this.yMinCentered = this.yMin + 0.5;
- this.yMaxCentered = this.yMax + 0.5;
- this.zMinCentered = this.zMin + 0.5;
- this.zMaxCentered = this.zMax + 0.5;
- }
-
-
- public List blockList() {
- ArrayList bL = new ArrayList<>((xMax - xMin) * (yMax - yMin) * (zMax - zMin));
- for(int x = this.xMin; x <= this.xMax; ++x) {
- for(int y = this.yMin; y <= this.yMax; ++y) {
- for(int z = this.zMin; z <= this.zMax; ++z) {
- Block b = this.world.getBlockAt(x, y, z);
- bL.add(b);
- }
- }
- }
- return bL;
- }
-
- public Location getCenter() {
- return new Location(this.world, (this.xMax - this.xMin) / 2 + this.xMin + 1, (this.yMax - this.yMin) / 2 + this.yMin, (this.zMax - this.zMin) / 2 + this.zMin + 1);
- }
-
- public BlockVector3 getCenterVector() {
- return BlockVector3.at((this.xMax - this.xMin) / 2 + this.xMin + 1, (this.yMax - this.yMin) / 2 + this.yMin, (this.zMax - this.zMin) / 2 + this.zMin + 1);
- }
-
- public double getDistance() {
- return this.getPoint1().distance(this.getPoint2());
- }
-
- public double getDistanceSquared() {
- return this.getPoint1().distanceSquared(this.getPoint2());
- }
-
- public int getHeight() {
- return this.yMax - this.yMin + 1;
- }
-
- public BlockVector3 getMinimumPoint() {
- return BlockVector3.at(this.xMin, this.yMin, this.zMin);
- }
-
- public BlockVector3 getMaximumPoint() {
- return BlockVector3.at(this.xMax, this.yMax, this.zMax);
- }
-
- public Location getPoint1() {
- return new Location(this.world, this.xMin, this.yMin, this.zMin);
- }
-
- public Location getPoint2() {
- return new Location(this.world, this.xMax, this.yMax, this.zMax);
- }
-
- public Location getRandomLocation() {
- Random rand = new Random();
- int x = rand.nextInt(Math.abs(this.xMax - this.xMin) + 1) + this.xMin;
- int y = rand.nextInt(Math.abs(this.yMax - this.yMin) + 1) + this.yMin;
- int z = rand.nextInt(Math.abs(this.zMax - this.zMin) + 1) + this.zMin;
- return new Location(this.world, x, y, z);
- }
-
- public boolean contains(BlockVector3 vector3) {
- return vector3.getBlockX() >= this.xMin && vector3.getBlockX() <= this.xMax && vector3.getBlockY() >= this.yMin && vector3.getBlockY() <= this.yMax && vector3
- .getBlockZ() >= this.zMin && vector3.getBlockZ() <= this.zMax;
- }
-
- public boolean contains(BlockVector3 vector3, World world) {
- return world == this.world && vector3.getBlockX() >= this.xMin && vector3.getBlockX() <= this.xMax && vector3.getBlockY() >= this.yMin && vector3.getBlockY() <= this.yMax && vector3
- .getBlockZ() >= this.zMin && vector3.getBlockZ() <= this.zMax;
- }
-
- public int getTotalBlockSize() {
- return this.getHeight() * this.getXWidth() * this.getZWidth();
- }
-
- public int getXWidth() {
- return this.xMax - this.xMin + 1;
- }
-
- public int getZWidth() {
- return this.zMax - this.zMin + 1;
- }
-
- public boolean isIn(Location loc) {
- return loc.getWorld() == this.world && loc.getBlockX() >= this.xMin && loc.getBlockX() <= this.xMax && loc.getBlockY() >= this.yMin && loc.getBlockY() <= this.yMax && loc
- .getBlockZ() >= this.zMin && loc.getBlockZ() <= this.zMax;
- }
-
- public boolean isIn(Player player) {
- return this.isIn(player.getLocation());
- }
-
- public boolean isInWithMarge(Location loc, double marge) {
- return loc.getWorld() == this.world && loc.getX() >= this.xMinCentered - marge && loc.getX() <= this.xMaxCentered + marge && loc.getY() >= this.yMinCentered - marge && loc
- .getY() <= this.yMaxCentered + marge && loc.getZ() >= this.zMinCentered - marge && loc.getZ() <= this.zMaxCentered + marge;
- }
-
- public boolean isColliding(Cuboid region) {
- List flatRegion1 = new ArrayList<>(this.getFlatRegion());
- List flatRegion2 = new ArrayList<>(region.getFlatRegion());
- for (BlockVector2 vector1 : flatRegion1) {
- for (BlockVector2 vector2 : flatRegion2)
- if (vector1.getBlockX() == vector2.getBlockX() && vector1.getBlockZ() == vector2.getBlockZ()) return true;
- }
- return false;
- }
-
- public List getFlatRegion() {
- List blocksVector = new ArrayList<>();
- for (Block block : blockList()) {
- blocksVector.add(BlockVector2.at(block.getLocation().getBlockX(), block.getLocation().getBlockZ()));
- }
- return blocksVector;
- }
-
- public List getWalls() {
- List walls = new ArrayList<>();
- for (int z = zMin; z <= zMax; z++) {
- walls.add(BlockVector2.at(xMin, z));
- walls.add(BlockVector2.at(xMax, z));
- }
- for (int x = xMin; x < xMax; x++) {
- walls.add(BlockVector2.at(x, zMin));
- walls.add(BlockVector2.at(x, zMax));
- }
- return walls;
- }
-
-}
+package com.modnmetl.virtualrealty.objects.region;
+
+import com.modnmetl.virtualrealty.objects.math.BlockVector2;
+import com.modnmetl.virtualrealty.objects.math.BlockVector3;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+
+public class Cuboid {
+
+ private final int xMin;
+ private final int xMax;
+ private final int yMin;
+ private final int yMax;
+ private final int zMin;
+ private final int zMax;
+ private final double xMinCentered;
+ private final double xMaxCentered;
+ private final double yMinCentered;
+ private final double yMaxCentered;
+ private final double zMinCentered;
+ private final double zMaxCentered;
+ private final World world;
+
+ public Cuboid(Location point1, Location point2) {
+ this.xMin = Math.min(point1.getBlockX(), point2.getBlockX());
+ this.xMax = Math.max(point1.getBlockX(), point2.getBlockX());
+ this.yMin = Math.min(point1.getBlockY(), point2.getBlockY());
+ this.yMax = Math.max(point1.getBlockY(), point2.getBlockY());
+ this.zMin = Math.min(point1.getBlockZ(), point2.getBlockZ());
+ this.zMax = Math.max(point1.getBlockZ(), point2.getBlockZ());
+ this.world = point1.getWorld();
+ this.xMinCentered = this.xMin + 0.5;
+ this.xMaxCentered = this.xMax + 0.5;
+ this.yMinCentered = this.yMin + 0.5;
+ this.yMaxCentered = this.yMax + 0.5;
+ this.zMinCentered = this.zMin + 0.5;
+ this.zMaxCentered = this.zMax + 0.5;
+ }
+
+ public Cuboid(BlockVector3 point1, BlockVector3 point2, World world) {
+ this.xMin = Math.min(point1.getBlockX(), point2.getBlockX());
+ this.xMax = Math.max(point1.getBlockX(), point2.getBlockX());
+ this.yMin = Math.min(point1.getBlockY(), point2.getBlockY());
+ this.yMax = Math.max(point1.getBlockY(), point2.getBlockY());
+ this.zMin = Math.min(point1.getBlockZ(), point2.getBlockZ());
+ this.zMax = Math.max(point1.getBlockZ(), point2.getBlockZ());
+ this.world = world;
+ this.xMinCentered = this.xMin + 0.5;
+ this.xMaxCentered = this.xMax + 0.5;
+ this.yMinCentered = this.yMin + 0.5;
+ this.yMaxCentered = this.yMax + 0.5;
+ this.zMinCentered = this.zMin + 0.5;
+ this.zMaxCentered = this.zMax + 0.5;
+ }
+
+
+ public List blockList() {
+ LinkedList bL = new LinkedList<>();
+ for(int x = this.xMin; x <= this.xMax; ++x) {
+ for(int y = this.yMin; y <= this.yMax; ++y) {
+ for(int z = this.zMin; z <= this.zMax; ++z) {
+ Block b = this.world.getBlockAt(x, y, z);
+ bL.add(b);
+ }
+ }
+ }
+ return bL;
+ }
+
+ public Location getCenter() {
+ return new Location(this.world, (this.xMax - this.xMin) / 2 + this.xMin + 1, (this.yMax - this.yMin) / 2 + this.yMin, (this.zMax - this.zMin) / 2 + this.zMin + 1);
+ }
+
+ public BlockVector3 getCenterVector() {
+ return BlockVector3.at((this.xMax - this.xMin) / 2 + this.xMin + 1, (this.yMax - this.yMin) / 2 + this.yMin, (this.zMax - this.zMin) / 2 + this.zMin + 1);
+ }
+
+ public double getDistance() {
+ return this.getPoint1().distance(this.getPoint2());
+ }
+
+ public double getDistanceSquared() {
+ return this.getPoint1().distanceSquared(this.getPoint2());
+ }
+
+ public int getHeight() {
+ return this.yMax - this.yMin + 1;
+ }
+
+ public BlockVector3 getMinimumPoint() {
+ return BlockVector3.at(this.xMin, this.yMin, this.zMin);
+ }
+
+ public BlockVector3 getMaximumPoint() {
+ return BlockVector3.at(this.xMax, this.yMax, this.zMax);
+ }
+
+ public Location getPoint1() {
+ return new Location(this.world, this.xMin, this.yMin, this.zMin);
+ }
+
+ public Location getPoint2() {
+ return new Location(this.world, this.xMax, this.yMax, this.zMax);
+ }
+
+ public Location getRandomLocation() {
+ Random rand = new Random();
+ int x = rand.nextInt(Math.abs(this.xMax - this.xMin) + 1) + this.xMin;
+ int y = rand.nextInt(Math.abs(this.yMax - this.yMin) + 1) + this.yMin;
+ int z = rand.nextInt(Math.abs(this.zMax - this.zMin) + 1) + this.zMin;
+ return new Location(this.world, x, y, z);
+ }
+
+ public boolean contains(BlockVector3 vector3) {
+ return vector3.getBlockX() >= this.xMin && vector3.getBlockX() <= this.xMax && vector3.getBlockY() >= this.yMin && vector3.getBlockY() <= this.yMax && vector3
+ .getBlockZ() >= this.zMin && vector3.getBlockZ() <= this.zMax;
+ }
+
+ public boolean contains(BlockVector3 vector3, World world) {
+ return world == this.world && vector3.getBlockX() >= this.xMin && vector3.getBlockX() <= this.xMax && vector3.getBlockY() >= this.yMin && vector3.getBlockY() <= this.yMax && vector3
+ .getBlockZ() >= this.zMin && vector3.getBlockZ() <= this.zMax;
+ }
+
+ public int getTotalBlockSize() {
+ return this.getHeight() * this.getXWidth() * this.getZWidth();
+ }
+
+ public int getXWidth() {
+ return this.xMax - this.xMin + 1;
+ }
+
+ public int getZWidth() {
+ return this.zMax - this.zMin + 1;
+ }
+
+ public boolean isIn(Location loc) {
+ return loc.getWorld() == this.world && loc.getBlockX() >= this.xMin && loc.getBlockX() <= this.xMax && loc.getBlockY() >= this.yMin && loc.getBlockY() <= this.yMax && loc
+ .getBlockZ() >= this.zMin && loc.getBlockZ() <= this.zMax;
+ }
+
+ public boolean isIn(Player player) {
+ return this.isIn(player.getLocation());
+ }
+
+ public boolean isInWithMarge(Location loc, double marge) {
+ return loc.getWorld() == this.world && loc.getX() >= this.xMinCentered - marge && loc.getX() <= this.xMaxCentered + marge && loc.getY() >= this.yMinCentered - marge && loc
+ .getY() <= this.yMaxCentered + marge && loc.getZ() >= this.zMinCentered - marge && loc.getZ() <= this.zMaxCentered + marge;
+ }
+
+ public boolean isColliding(Cuboid region) {
+ List flatRegion1 = new ArrayList<>(this.getFlatRegion());
+ List flatRegion2 = new ArrayList<>(region.getFlatRegion());
+ for (BlockVector2 vector1 : flatRegion1) {
+ for (BlockVector2 vector2 : flatRegion2)
+ if (vector1.getBlockX() == vector2.getBlockX() && vector1.getBlockZ() == vector2.getBlockZ()) return true;
+ }
+ return false;
+ }
+
+ public List getFlatRegion() {
+ List blocksVector = new ArrayList<>();
+ for (Block block : blockList()) {
+ blocksVector.add(BlockVector2.at(block.getLocation().getBlockX(), block.getLocation().getBlockZ()));
+ }
+ return blocksVector;
+ }
+
+ public List getWalls() {
+ List walls = new ArrayList<>();
+ for (int z = zMin; z <= zMax; z++) {
+ walls.add(BlockVector2.at(xMin, z));
+ walls.add(BlockVector2.at(xMax, z));
+ }
+ for (int x = xMin; x < xMax; x++) {
+ walls.add(BlockVector2.at(x, zMin));
+ walls.add(BlockVector2.at(x, zMax));
+ }
+ return walls;
+ }
+
+ public World getWorld() {
+ return world;
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java b/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java
new file mode 100644
index 0000000..d90c789
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java
@@ -0,0 +1,208 @@
+package com.modnmetl.virtualrealty.objects.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.utils.RegionUtil;
+import com.modnmetl.virtualrealty.utils.data.VirtualBlock;
+import lombok.Data;
+import lombok.SneakyThrows;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.util.*;
+
+@Data
+public class GridStructure {
+
+ public static final HashMap> ACTIVE_GRIDS = new HashMap<>();
+
+ private final Player viewer;
+ private final Location previewLocation;
+ private int length;
+ private int height;
+ private int width;
+ private int cuboidId;
+ private final Set changedBlocks;
+ private final World world;
+ private boolean displayingBlocks;
+ private long displayTicks;
+
+ public GridStructure(Player viewer, int length, int height, int width, int cuboidId, World world, long displayTicks, Location previewLocation) {
+ if (!ACTIVE_GRIDS.containsKey(viewer.getUniqueId())) {
+ ACTIVE_GRIDS.put(viewer.getUniqueId(), new HashSet<>());
+ }
+ ACTIVE_GRIDS.get(viewer.getUniqueId()).add(cuboidId);
+ this.viewer = viewer;
+ this.length = length;
+ this.height = height;
+ this.width = width;
+ this.cuboidId = cuboidId;
+ this.changedBlocks = new HashSet<>();
+ this.world = world;
+ this.displayTicks = displayTicks;
+ this.previewLocation = previewLocation;
+ }
+
+ public static boolean isCuboidGridDisplaying(Player player, int cuboidId) {
+ return ACTIVE_GRIDS.containsKey(player.getUniqueId()) && ACTIVE_GRIDS.get(player.getUniqueId()).contains(cuboidId);
+ }
+
+ public void preview() {
+ preview(null);
+ }
+
+ public void preview(Location playerPreviewLocation) {
+ changedBlocks.clear();
+ Plot plot = PlotManager.getPlot(cuboidId);
+ Location location = previewLocation;
+ LinkedList blocks = new LinkedList<>();
+ LinkedList borderBlocks = new LinkedList<>();
+ Direction direction = Direction.byYaw(location.getYaw());
+ int maxX;
+ int maxZ;
+ int minX;
+ int minZ;
+ switch(direction) {
+ case SOUTH: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + getLength() + 1;
+ minX = location.getBlockX() - getWidth() + 1;
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ case WEST: {
+ maxX = location.getBlockX() + 1 + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX() - getLength() + 1;
+ minZ = location.getBlockZ() - getWidth();
+ break;
+ }
+ case NORTH: {
+ maxX = location.getBlockX() + getWidth() + 1;
+ maxZ = location.getBlockZ() + 1 + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - getLength();
+ break;
+ }
+ case EAST: {
+ maxX = location.getBlockX() + getLength() + 1;
+ maxZ = location.getBlockZ() + getWidth() + 1;
+ minX = location.getBlockX();
+ minZ = location.getBlockZ() - 1;
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected value: " + direction);
+ }
+ for (int x = minX - 1; x < maxX; x++) {
+ for (int z = minZ; z < maxZ; z++) {
+ if (x == minX - 1 || z == minZ || x == maxX - 1 || z == maxZ - 1) {
+ borderBlocks.add(location.getWorld().getBlockAt(x, location.getBlockY(), z));
+ }
+ }
+ }
+ Location topRightCorner;
+ Location bottomLeftCorner;
+ if (plot != null) {
+ topRightCorner = plot.getBorderTopRightCorner().toLocation(plot.getCreatedWorld());
+ bottomLeftCorner = plot.getBorderBottomLeftCorner().toLocation(plot.getCreatedWorld());
+ } else {
+ switch (direction) {
+ case SOUTH: {
+ bottomLeftCorner = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() - 1);
+ topRightCorner = new Location(location.getWorld(), location.getBlockX() - getWidth(), location.getBlockY() + getHeight(), location.getBlockZ() + getLength());
+ break;
+ }
+ case WEST: {
+ bottomLeftCorner = new Location(location.getWorld(), location.getBlockX() + 1, location.getBlockY() - 10, location.getBlockZ() + 1);
+ topRightCorner = new Location(location.getWorld(), location.getBlockX() - getLength(), location.getBlockY() + getHeight(), location.getBlockZ() - getWidth());
+ break;
+ }
+ case NORTH: {
+ bottomLeftCorner = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() - 10, location.getBlockZ() + 1);
+ topRightCorner = new Location(location.getWorld(), location.getBlockX() + getWidth(), location.getBlockY() + getHeight(), location.getBlockZ() - getLength());
+ break;
+ }
+ case EAST: {
+ bottomLeftCorner = new Location(location.getWorld(), location.getBlockX() + getLength(), location.getBlockY() - 10, location.getBlockZ() - 1);
+ topRightCorner = new Location(location.getWorld(), location.getBlockX() - 1, location.getBlockY() + getHeight(), location.getBlockZ() + getWidth());
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected value: " + direction);
+ }
+ }
+ for (Block borderBlock : new LinkedList<>(borderBlocks)) {
+ // top grid floor
+ blocks.add(borderBlock.getLocation().add(0, topRightCorner.getBlockY() - borderBlock.getLocation().getBlockY(), 0).getBlock());
+ // bottom grid floor
+ blocks.add(borderBlock.getLocation().subtract(0, borderBlock.getLocation().getBlockY() - bottomLeftCorner.getBlockY(), 0).getBlock());
+ Location playerBlockLocation = borderBlock.getLocation();
+ if (playerPreviewLocation != null) {
+ playerBlockLocation.setY(playerPreviewLocation.getY());
+ } else {
+ playerBlockLocation.add(0, 1, 0);
+ }
+ // plot player level border
+ blocks.add(playerBlockLocation.getBlock());
+ }
+ // grid pillars
+ for (int y = bottomLeftCorner.getBlockY(); y < bottomLeftCorner.getBlockY() + getHeight() + 10; y++) {
+ blocks.add(new Location(world, minX - 1, y, minZ).getBlock());
+ blocks.add(new Location(world, maxX - 1, y, minZ).getBlock());
+ blocks.add(new Location(world, minX - 1, y, maxZ - 1).getBlock());
+ blocks.add(new Location(world, maxX - 1, y, maxZ - 1).getBlock());
+ }
+ swapBlocks(
+ blocks,
+ PlotManager.isColliding(RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), getLength(), getHeight(), getWidth()))
+ );
+ if (displayTicks == 0) return;
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ removeGrid();
+ ACTIVE_GRIDS.get(viewer.getUniqueId()).remove(cuboidId);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), displayTicks);
+ }
+
+ @SneakyThrows
+ public void removeGrid() {
+ for (VirtualBlock changedBlock : changedBlocks) {
+ Block changedBukkitBlock = changedBlock.getBlock(world);
+ if (VirtualRealty.legacyVersion) {
+ viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.getType(), changedBukkitBlock.getData());
+ } else {
+ viewer.sendBlockChange(changedBukkitBlock.getLocation(), changedBukkitBlock.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));
+ }
+ changedBlocks.add(convertedBlock);
+ }
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/registry/VirtualPlaceholders.java b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java
similarity index 93%
rename from src/main/java/me/plytki/virtualrealty/registry/VirtualPlaceholders.java
rename to src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java
index 3d86be8..8f44d51 100644
--- a/src/main/java/me/plytki/virtualrealty/registry/VirtualPlaceholders.java
+++ b/src/main/java/com/modnmetl/virtualrealty/registry/VirtualPlaceholders.java
@@ -1,9 +1,9 @@
-package me.plytki.virtualrealty.registry;
+package com.modnmetl.virtualrealty.registry;
+import com.modnmetl.virtualrealty.managers.PlotManager;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
-import me.plytki.virtualrealty.VirtualRealty;
-import me.plytki.virtualrealty.managers.PlotManager;
-import me.plytki.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.objects.Plot;
import org.bukkit.entity.Player;
public class VirtualPlaceholders extends PlaceholderExpansion {
@@ -98,8 +98,7 @@ public String getVersion(){
*/
@Override
public String onPlaceholderRequest(Player player, String identifier){
- if(player == null)
- return "";
+ if(player == null) return "";
Plot plot = PlotManager.getBorderedPlot(player.getLocation());
if (identifier.equals("plot_id")) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/sql/Database.java b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
new file mode 100644
index 0000000..ee8caeb
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
@@ -0,0 +1,117 @@
+package com.modnmetl.virtualrealty.sql;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.configs.PluginConfiguration;
+import com.zaxxer.hikari.HikariDataSource;
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+import org.sqlite.SQLiteDataSource;
+
+import javax.sql.DataSource;
+import java.io.File;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.logging.Level;
+
+public class Database {
+
+ private static Database instance;
+
+ @Getter
+ private final PluginConfiguration.DataModel dataModel;
+
+ @Getter
+ private final DataSource dataSource;
+ @Getter
+ private final Connection connection;
+ @Getter
+ private final Statement statement;
+
+ public Database(File file) throws SQLException {
+ dataModel = VirtualRealty.getPluginConfiguration().dataModel;
+ SQLiteDataSource sqLiteDataSource = new SQLiteDataSource();
+ sqLiteDataSource.setUrl("jdbc:sqlite:" + file.getAbsolutePath());
+ dataSource = sqLiteDataSource;
+ connection = dataSource.getConnection();
+ statement = connection.createStatement();
+ createTables();
+ updateTables();
+ }
+
+ public Database(String hostname, int port, String username, String password, String database) throws SQLException {
+ dataModel = VirtualRealty.getPluginConfiguration().dataModel;
+ dataSource = new HikariDataSource();
+ HikariDataSource hikariDataSource = (HikariDataSource) dataSource;
+ hikariDataSource.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
+ hikariDataSource.setUsername(username);
+ if (!password.isEmpty()) {
+ hikariDataSource.setPassword(password);
+ }
+ dataSource.setLogWriter(new PrintWriter(System.out));
+ connection = dataSource.getConnection();
+ statement = connection.createStatement();
+ 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();
+ }
+ }
+
+ 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) {}
+ }
+ 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();
+ }
+ }
+ }
+ }
+
+ public static Database getInstance() {
+ return instance;
+ }
+
+ public static void setInstance(Database database) {
+ instance = database;
+ }
+
+}
+
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java b/src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java
new file mode 100644
index 0000000..03f2181
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/EnumUtils.java
@@ -0,0 +1,18 @@
+package com.modnmetl.virtualrealty.utils;
+
+public class EnumUtils {
+
+ public static > boolean isValidEnum(Class enumClass, String enumName) {
+ if (enumName == null) {
+ return false;
+ } else {
+ try {
+ Enum.valueOf(enumClass, enumName);
+ return true;
+ } catch (IllegalArgumentException var3) {
+ return false;
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/utils/Permissions.java b/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java
similarity index 89%
rename from src/main/java/me/plytki/virtualrealty/utils/Permissions.java
rename to src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java
index 833e82e..d1cc936 100644
--- a/src/main/java/me/plytki/virtualrealty/utils/Permissions.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/Permissions.java
@@ -1,27 +1,27 @@
-package me.plytki.virtualrealty.utils;
-
-import me.plytki.virtualrealty.VirtualRealty;
-import org.bukkit.command.CommandSender;
-import org.bukkit.permissions.Permission;
-
-public class Permissions {
-
- public static boolean hasPermission(CommandSender sender, Permission basePermission, String permission) {
- Permission finalPermission = new Permission(basePermission.getName() + "." + permission);
- if (!sender.hasPermission(finalPermission)) {
- sender.sendMessage(VirtualRealty.PREFIX + "§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)");
- return false;
- }
- return true;
- }
-
- 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)");
- return false;
- }
- return true;
- }
-
-}
+package com.modnmetl.virtualrealty.utils;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import org.bukkit.command.CommandSender;
+import org.bukkit.permissions.Permission;
+
+public class Permissions {
+
+ public static boolean hasPermission(CommandSender sender, Permission basePermission, String permission) {
+ Permission finalPermission = new Permission(basePermission.getName() + "." + permission);
+ if (!sender.hasPermission(finalPermission)) {
+ sender.sendMessage(VirtualRealty.PREFIX + "§cInsufficient permissions! §8(§7" + finalPermission.getName() + "§8)");
+ return false;
+ }
+ return true;
+ }
+
+ 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)");
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/utils/PlotUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
similarity index 83%
rename from src/main/java/me/plytki/virtualrealty/utils/PlotUtil.java
rename to src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
index 3fd3a69..a4bb4d3 100644
--- a/src/main/java/me/plytki/virtualrealty/utils/PlotUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
@@ -1,41 +1,41 @@
-package me.plytki.virtualrealty.utils;
-
-import me.plytki.virtualrealty.enums.Direction;
-import me.plytki.virtualrealty.objects.Cuboid;
-import me.plytki.virtualrealty.objects.math.BlockVector3;
-import org.bukkit.Location;
-
-public class PlotUtil {
-
- public static Cuboid getPlotRegion(Location location, Direction direction, int length, int width, int height) {
- Location location1;
- Location location2;
- switch(direction) {
- 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);
- 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);
- 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);
- 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);
- break;
- }
- default:
- throw new IllegalStateException("Unexpected value: " + direction);
- }
- return new Cuboid(BlockVector3.at(location1.getBlockX(), location1.getBlockY(), location1.getBlockZ()),
- BlockVector3.at(location2.getBlockX(), location2.getBlockY(), location2.getBlockZ()), location.getWorld());
- }
-
-}
+package com.modnmetl.virtualrealty.utils;
+
+import com.modnmetl.virtualrealty.enums.Direction;
+import com.modnmetl.virtualrealty.objects.region.Cuboid;
+import com.modnmetl.virtualrealty.objects.math.BlockVector3;
+import org.bukkit.Location;
+
+public class RegionUtil {
+
+ public static Cuboid getRegion(Location location, Direction direction, int length, int height, int width) {
+ Location location1;
+ Location location2;
+ switch(direction) {
+ 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);
+ 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);
+ 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);
+ 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);
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected value: " + direction);
+ }
+ return new Cuboid(BlockVector3.at(location1.getBlockX(), location1.getBlockY(), location1.getBlockZ()),
+ BlockVector3.at(location2.getBlockX(), location2.getBlockY(), location2.getBlockZ()), location.getWorld());
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/utils/UUIDUtils.java b/src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java
similarity index 86%
rename from src/main/java/me/plytki/virtualrealty/utils/UUIDUtils.java
rename to src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java
index ce40e3c..f39d2a8 100644
--- a/src/main/java/me/plytki/virtualrealty/utils/UUIDUtils.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/UUIDUtils.java
@@ -1,4 +1,4 @@
-package me.plytki.virtualrealty.utils;
+package com.modnmetl.virtualrealty.utils;
import java.util.UUID;
diff --git a/src/main/java/me/plytki/virtualrealty/utils/UpdateChecker.java b/src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java
similarity index 94%
rename from src/main/java/me/plytki/virtualrealty/utils/UpdateChecker.java
rename to src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java
index 34bd2e0..052b0f4 100644
--- a/src/main/java/me/plytki/virtualrealty/utils/UpdateChecker.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/UpdateChecker.java
@@ -1,8 +1,8 @@
-package me.plytki.virtualrealty.utils;
+package com.modnmetl.virtualrealty.utils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import me.plytki.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.VirtualRealty;
import java.io.IOException;
import java.io.InputStreamReader;
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java
new file mode 100644
index 0000000..98a6ca8
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/WorldUtil.java
@@ -0,0 +1,34 @@
+package com.modnmetl.virtualrealty.utils;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
+
+import java.util.List;
+
+public class WorldUtil {
+
+ public static List getWorldPermissions() {
+ return VirtualRealty.getPermissions().getWorldProtection();
+ }
+
+ public static void togglePermission(RegionPermission plotPermission) {
+ if (getWorldPermissions().contains(plotPermission)) {
+ VirtualRealty.getPermissions().worldProtection.remove(plotPermission);
+ } else {
+ VirtualRealty.getPermissions().worldProtection.add(plotPermission);
+ }
+ }
+
+ public static boolean hasPermission(RegionPermission plotPermission) {
+ return getWorldPermissions().contains(plotPermission);
+ }
+
+ public static void addPermission(RegionPermission plotPermission) {
+ VirtualRealty.getPermissions().worldProtection.add(plotPermission);
+ }
+
+ public static void removePermission(RegionPermission plotPermission) {
+ VirtualRealty.getPermissions().worldProtection.remove(plotPermission);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java b/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java
new file mode 100644
index 0000000..b729d8c
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java
@@ -0,0 +1,91 @@
+package com.modnmetl.virtualrealty.utils.configuration;
+
+import com.modnmetl.virtualrealty.configs.PermissionsConfiguration;
+import com.modnmetl.virtualrealty.configs.SizesConfiguration;
+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 com.modnmetl.virtualrealty.configs.MessagesConfiguration;
+import com.modnmetl.virtualrealty.configs.PluginConfiguration;
+import eu.okaeri.configs.yaml.bukkit.serdes.SerdesBukkit;
+import lombok.NoArgsConstructor;
+
+import java.io.File;
+
+@NoArgsConstructor
+public class ConfigurationFactory {
+
+ public PluginConfiguration loadPluginConfiguration(File pluginConfigurationFile) {
+ return ConfigManager.create(PluginConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(pluginConfigurationFile);
+ it.saveDefaults();
+ it.load(true);
+ });
+ }
+
+ public SizesConfiguration loadSizesConfiguration(File sizesConfigurationFile) {
+ return ConfigManager.create(SizesConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(sizesConfigurationFile);
+ it.saveDefaults();
+ it.load(true);
+ });
+ }
+
+ public MessagesConfiguration loadMessagesConfiguration(File messagesConfigurationFile) {
+ return ConfigManager.create(MessagesConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(messagesConfigurationFile);
+ it.saveDefaults();
+ it.load(true);
+ });
+ }
+
+ public PermissionsConfiguration loadPermissionsConfiguration(File permissionsConfigurationFile) {
+ return ConfigManager.create(PermissionsConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(permissionsConfigurationFile);
+ it.saveDefaults();
+ it.load(true);
+ });
+ }
+
+ public PermissionsConfiguration updatePluginConfiguration(File pluginConfigurationFile) {
+ return ConfigManager.create(PermissionsConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(pluginConfigurationFile);
+ it.saveDefaults();
+ it.update();
+ });
+ }
+
+ public PermissionsConfiguration updateSizesConfiguration(File sizesConfigurationFile) {
+ return ConfigManager.create(PermissionsConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(sizesConfigurationFile);
+ it.saveDefaults();
+ it.update();
+ });
+ }
+
+ public PermissionsConfiguration updateMessagesConfiguration(File messagesConfigurationFile) {
+ return ConfigManager.create(PermissionsConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(messagesConfigurationFile);
+ it.saveDefaults();
+ it.update();
+ });
+ }
+
+ public PermissionsConfiguration updatePermissionsConfiguration(File permissionsConfigurationFile) {
+ return ConfigManager.create(PermissionsConfiguration.class, (it) -> {
+ it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());
+ it.withBindFile(permissionsConfigurationFile);
+ it.saveDefaults();
+ it.update();
+ });
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/utils/data/Data.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java
similarity index 88%
rename from src/main/java/me/plytki/virtualrealty/utils/data/Data.java
rename to src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java
index 0ff5e38..ec6dae5 100644
--- a/src/main/java/me/plytki/virtualrealty/utils/data/Data.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/DataCompressor.java
@@ -1,13 +1,14 @@
-package me.plytki.virtualrealty.utils.data;
+package com.modnmetl.virtualrealty.utils.data;
import java.io.*;
import java.util.zip.*;
-public class Data {
+public class DataCompressor {
public void compressData(byte[] data, File file) throws IOException {
try (OutputStream outputStream = new FileOutputStream(file)) {
Deflater d = new Deflater();
+ d.setLevel(4);
DeflaterOutputStream dout = new DeflaterOutputStream(outputStream, d);
dout.write(data);
dout.close();
@@ -17,7 +18,7 @@ public void compressData(byte[] data, File file) throws IOException {
public byte[] decompressData(File file) throws IOException {
try (InputStream inputStream = new FileInputStream(file)) {
InflaterInputStream newInput = new InflaterInputStream(inputStream);
- ByteArrayOutputStream bout = new ByteArrayOutputStream(512);
+ ByteArrayOutputStream bout = new ByteArrayOutputStream(512*2*2*2*2);
int b;
while ((b = newInput.read()) != -1) {
bout.write(b);
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java
new file mode 100644
index 0000000..9963359
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/ItemBuilder.java
@@ -0,0 +1,244 @@
+package com.modnmetl.virtualrealty.utils.data;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.bukkit.Color;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemFlag;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.LeatherArmorMeta;
+import org.bukkit.inventory.meta.SkullMeta;
+
+/**
+ * Easily create itemstacks, without messing your hands.
+ * Note that if you do use this in one of your projects, leave this notice.
+ * Please do credit me if you do use this in one of your projects.
+ * @author NonameSL
+ */
+public class ItemBuilder {
+ private ItemStack is;
+ /**
+ * Create a new ItemBuilder from scratch.
+ * @param m The material to create the ItemBuilder with.
+ */
+ public ItemBuilder(Material m){
+ this(m, 1);
+ }
+ /**
+ * Create a new ItemBuilder over an existing itemstack.
+ * @param is The itemstack to create the ItemBuilder over.
+ */
+ public ItemBuilder(ItemStack is){
+ this.is=is;
+ }
+ /**
+ * Create a new ItemBuilder from scratch.
+ * @param m The material of the item.
+ * @param amount The amount of the item.
+ */
+ public ItemBuilder(Material m, int amount){
+ is= new ItemStack(m, amount);
+ }
+ /**
+ * Create a new ItemBuilder from scratch.
+ * @param m The material of the item.
+ * @param amount The amount of the item.
+ * @param durability The durability of the item.
+ */
+ public ItemBuilder(Material m, int amount, byte durability){
+ is = new ItemStack(m, amount, durability);
+ }
+ /**
+ * Clone the ItemBuilder into a new one.
+ * @return The cloned instance.
+ */
+ public ItemBuilder clone(){
+ return new ItemBuilder(is);
+ }
+ /**
+ * Change the durability of the item.
+ * @param dur The durability to set it to.
+ */
+ public ItemBuilder setDurability(short dur){
+ is.setDurability(dur);
+ return this;
+ }
+ /**
+ * Set the displayname of the item.
+ * @param name The name to change it to.
+ */
+ public ItemBuilder setName(String name){
+ ItemMeta im = is.getItemMeta();
+ im.setDisplayName(name);
+ is.setItemMeta(im);
+ return this;
+ }
+ /**
+ * Add an unsafe enchantment.
+ * @param ench The enchantment to add.
+ * @param level The level to put the enchant on.
+ */
+ public ItemBuilder addUnsafeEnchantment(Enchantment ench, int level){
+ is.addUnsafeEnchantment(ench, level);
+ return this;
+ }
+ /**
+ * Remove a certain enchant from the item.
+ * @param ench The enchantment to remove
+ */
+ public ItemBuilder removeEnchantment(Enchantment ench){
+ is.removeEnchantment(ench);
+ return this;
+ }
+ /**
+ * Set the skull owner for the item. Works on skulls only.
+ * @param owner The name of the skull's owner.
+ */
+ public ItemBuilder setSkullOwner(String owner){
+ try{
+ SkullMeta im = (SkullMeta)is.getItemMeta();
+ im.setOwner(owner);
+ is.setItemMeta(im);
+ }catch(ClassCastException expected){}
+ return this;
+ }
+ /**
+ * Add an enchant to the item.
+ * @param ench The enchant to add
+ * @param level The level
+ */
+ public ItemBuilder addEnchant(Enchantment ench, int level){
+ ItemMeta im = is.getItemMeta();
+ im.addEnchant(ench, level, true);
+ is.setItemMeta(im);
+ return this;
+ }
+ /**
+ * Add multiple enchants at once.
+ * @param enchantments The enchants to add.
+ */
+ public ItemBuilder addEnchantments(Map enchantments){
+ is.addEnchantments(enchantments);
+ return this;
+ }
+ /**
+ * Sets infinity durability on the item by setting the durability to Short.MAX_VALUE.
+ */
+ public ItemBuilder setInfinityDurability(){
+ is.setDurability(Short.MAX_VALUE);
+ return this;
+ }
+ /**
+ * Re-sets the lore.
+ * @param lore The lore to set it to.
+ */
+ public ItemBuilder setLore(String... lore){
+ ItemMeta im = is.getItemMeta();
+ im.setLore(Arrays.asList(lore));
+ is.setItemMeta(im);
+ return this;
+ }
+ /**
+ * Re-sets the lore.
+ * @param lore The lore to set it to.
+ */
+ public ItemBuilder setLore(List lore) {
+ ItemMeta im = is.getItemMeta();
+ im.setLore(lore);
+ is.setItemMeta(im);
+ return this;
+ }
+ /**
+ * Remove a lore line.
+ */
+ public ItemBuilder removeLoreLine(String line){
+ ItemMeta im = is.getItemMeta();
+ List lore = new ArrayList<>(im.getLore());
+ if(!lore.contains(line))return this;
+ lore.remove(line);
+ im.setLore(lore);
+ is.setItemMeta(im);
+ return this;
+ }
+ /**
+ * Remove a lore line.
+ * @param index The index of the lore line to remove.
+ */
+ public ItemBuilder removeLoreLine(int index){
+ ItemMeta im = is.getItemMeta();
+ List lore = new ArrayList<>(im.getLore());
+ if(index<0||index>lore.size())return this;
+ lore.remove(index);
+ im.setLore(lore);
+ is.setItemMeta(im);
+ return this;
+ }
+ /**
+ * Add a lore line.
+ * @param line The lore line to add.
+ */
+ public ItemBuilder addLoreLine(String line){
+ ItemMeta im = is.getItemMeta();
+ List lore = new ArrayList<>();
+ if(im.hasLore())lore = new ArrayList<>(im.getLore());
+ lore.add(line);
+ im.setLore(lore);
+ is.setItemMeta(im);
+ return this;
+ }
+ /**
+ * Add a lore line.
+ * @param line The lore line to add.
+ * @param pos The index of where to put it.
+ */
+ public ItemBuilder addLoreLine(String line, int pos){
+ ItemMeta im = is.getItemMeta();
+ List lore = new ArrayList<>(im.getLore());
+ lore.set(pos, line);
+ im.setLore(lore);
+ is.setItemMeta(im);
+ return this;
+ }
+
+ /**
+ * Sets the armor color of a leather armor piece. Works only on leather armor pieces.
+ * @param color The color to set it to.
+ */
+ public ItemBuilder setLeatherArmorColor(Color color){
+ try{
+ LeatherArmorMeta im = (LeatherArmorMeta)is.getItemMeta();
+ im.setColor(color);
+ is.setItemMeta(im);
+ }catch(ClassCastException expected){}
+ return this;
+ }
+
+ /**
+ * Retrieves the itemstack from the ItemBuilder.
+ * @return The itemstack created/modified by the ItemBuilder instance.
+ */
+ public ItemStack toItemStack(){
+ return is;
+ }
+
+
+ public ItemBuilder addItemFlag(ItemFlag itemFlag) {
+ ItemMeta im = is.getItemMeta();
+ im.addItemFlags(itemFlag);
+ is.setItemMeta(im);
+ return this;
+ }
+
+ public ItemBuilder addItemFlags(ItemFlag... itemFlags) {
+ ItemMeta im = is.getItemMeta();
+ im.addItemFlags(itemFlags);
+ is.setItemMeta(im);
+ return this;
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java
new file mode 100644
index 0000000..5684567
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/OldSchematicUtil.java
@@ -0,0 +1,90 @@
+package com.modnmetl.virtualrealty.utils.data;
+
+import com.modnmetl.virtualrealty.utils.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 lombok.SneakyThrows;
+import org.apache.commons.io.FileUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.data.BlockData;
+
+import java.io.*;
+import java.lang.reflect.Method;
+
+@Deprecated
+public class OldSchematicUtil {
+
+ public static final String OLD_REGION_PREFIX = "plot";
+ public static final String OLD_REGION_SUFFIX = ".region";
+
+ 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);
+ Location location = new Location(plot.getCreatedLocation().getWorld(), plot.getBorderBottomLeftCorner().getBlockX(), plot.getBorderBottomLeftCorner().getBlockY(), plot.getBorderBottomLeftCorner().getBlockZ());
+ Location location2 = new Location(plot.getCreatedLocation().getWorld(), plot.getBorderTopRightCorner().getBlockX(), plot.getBorderTopRightCorner().getBlockY(), plot.getBorderTopRightCorner().getBlockZ());
+ Block pos1Block = location.getBlock();
+ Block pos2Block = location2.getBlock();
+ int minX = Math.min(pos1Block.getX(), pos2Block.getX());
+ int minZ = Math.min(pos1Block.getZ(), pos2Block.getZ());
+ int minY = Math.min(pos1Block.getY(), pos2Block.getY());
+ int maxX = Math.max(pos1Block.getX(), pos2Block.getX());
+ int maxZ = Math.max(pos1Block.getZ(), pos2Block.getZ());
+ int maxY = Math.max(pos1Block.getY(), pos2Block.getY());
+ for (int x = minX; x <= maxX; x++) {
+ for (int y = maxY; y > minY; y--) {
+ for (int z = minZ; z <= maxZ; z++) {
+ Block b = location.getWorld().getBlockAt(x, y, z);
+ b.setType(Material.AIR);
+ }
+ }
+ }
+ if (blocks[0].isEmpty()) return;
+ for (String block : blocks) {
+ String[] cords = block.split(";");
+ int x = Integer.parseInt(cords[0]);
+ int y = Integer.parseInt(cords[1]);
+ int z = Integer.parseInt(cords[2]);
+ Location displaced = l.clone();
+ displaced.add(x, y, z);
+ Block b = displaced.getBlock();
+ if (VirtualRealty.legacyVersion) {
+ try {
+ Method m = Block.class.getDeclaredMethod("setType", Material.class);
+ m.setAccessible(true);
+ m.invoke(b, VMaterial.getMaterial(Integer.parseInt(cords[3])));
+ Method m2 = Block.class.getDeclaredMethod("setData", byte.class);
+ m2.setAccessible(true);
+ m2.invoke(b, (byte) Integer.parseInt(cords[4]));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ BlockData blockData = Bukkit.createBlockData("minecraft:" + cords[3]);
+ b.setBlockData(blockData);
+ }
+ b.getState().update(true);
+ }
+ VirtualRealty.debug("Pasted in: " + (System.currentTimeMillis() - time) + " ms");
+ }
+
+ @SneakyThrows
+ private static String[] load(int plotID) {
+ long time = System.currentTimeMillis();
+ File region = new File(VirtualRealty.plotsSchemaFolder, OLD_REGION_PREFIX + plotID + OLD_REGION_SUFFIX);
+ if (region.exists()) {
+ String loaded = new String(new DataCompressor().decompressData(region));
+ if (loaded.equalsIgnoreCase("clear")) return new String[]{""};
+ VirtualRealty.debug("Loaded in: " + (System.currentTimeMillis() - time) + " ms");
+ return loaded.split("\\|");
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java
new file mode 100644
index 0000000..0d64ab7
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java
@@ -0,0 +1,163 @@
+package com.modnmetl.virtualrealty.utils.data;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.utils.multiversion.VMaterial;
+import lombok.SneakyThrows;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.SerializationUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+
+import java.io.*;
+import java.lang.reflect.Method;
+import java.util.*;
+
+public class SchematicUtil {
+
+ public static final String LEGACY_REGION_PREFIX = "legacy_plot-";
+ public static final String REGION_PREFIX = "plot-";
+ public static final String REGION_SUFFIX = ".region";
+
+ public static LinkedList getStructure(Block block, Block block2) {
+ long time = System.currentTimeMillis();
+ int minX = Math.min(block.getX(), block2.getX());
+ int minZ = Math.min(block.getZ(), block2.getZ());
+ int minY = Math.min(block.getY(), block2.getY());
+ int maxX = Math.max(block.getX(), block2.getX());
+ int maxZ = Math.max(block.getZ(), block2.getZ());
+ int maxY = Math.max(block.getY(), block2.getY());
+ LinkedList blocks = new LinkedList<>();
+ for (int x = minX; x <= maxX; x++) {
+ for (int z = minZ; z <= maxZ; z++) {
+ if (block.getWorld().getHighestBlockAt(x, z).getLocation().getY() < minY) continue;
+ for (int y = minY; y <= maxY; ++y) {
+ Block oldBlock = block.getWorld().getBlockAt(x, y, z);
+ if (oldBlock.getType() == Material.AIR) continue;
+ if (VirtualRealty.legacyVersion) {
+ blocks.add(new VirtualBlock(x, y, z, oldBlock.getType().getId(), oldBlock.getData()));
+ } else {
+ blocks.add(new VirtualBlock(x, y, z, oldBlock.getBlockData().getAsString().substring(10)));
+ }
+ }
+ }
+ }
+ VirtualRealty.debug("Got " + blocks.size() + " blocks in: " + (System.currentTimeMillis() - time) + " ms");
+ return blocks;
+ }
+
+ public static void paste(int plotID) {
+ LinkedList blocks = load(plotID);
+ if (blocks == null) return;
+ Plot plot = PlotManager.getPlot(plotID);
+ if (plot == null) return;
+ long time = System.currentTimeMillis();
+ Location location = plot.getBorderBottomLeftCorner().toLocation(plot.getCreatedWorld());
+ Location location2 = plot.getBorderTopRightCorner().toLocation(plot.getCreatedWorld());
+ Block pos1Block = location.getBlock();
+ Block pos2Block = location2.getBlock();
+ int minX = Math.min(pos1Block.getX(), pos2Block.getX());
+ int minZ = Math.min(pos1Block.getZ(), pos2Block.getZ());
+ int minY = Math.min(pos1Block.getY(), pos2Block.getY());
+ int maxX = Math.max(pos1Block.getX(), pos2Block.getX());
+ int maxZ = Math.max(pos1Block.getZ(), pos2Block.getZ());
+ 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);
+ if (block.getType() == Material.AIR) continue;
+ block.setType(Material.AIR);
+ i++;
+ }
+ }
+ }
+ 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);
+ }
+ }
+ VirtualRealty.debug("Pasted " + blocks.size() + " blocks in: " + (System.currentTimeMillis() - time) + " ms");
+ }
+
+ @SneakyThrows
+ public static void save(int plotID, LinkedList blocks) {
+ 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");
+ }
+
+ @SneakyThrows
+ public static LinkedList load(int plotID) {
+ long time = System.currentTimeMillis();
+ File region = new File(VirtualRealty.plotsSchemaFolder, REGION_PREFIX + plotID + REGION_SUFFIX);
+ File legacyRegion = new File(VirtualRealty.plotsSchemaFolder, LEGACY_REGION_PREFIX + plotID + REGION_SUFFIX);
+ ByteArrayInputStream bais;
+ ObjectInputStream ois;
+ if (region.exists()) {
+ byte[] bytes = new DataCompressor().decompressData(region);
+ bais = new ByteArrayInputStream(bytes);
+ ois = new ObjectInputStream(bais);
+ VirtualRealty.debug("Loaded in: " + (System.currentTimeMillis() - time) + " ms");
+ return (LinkedList) ois.readObject();
+ } else if (legacyRegion.exists()) {
+ byte[] bytes = new DataCompressor().decompressData(legacyRegion);
+ bais = new ByteArrayInputStream(bytes);
+ ois = new ObjectInputStream(bais);
+ VirtualRealty.debug("Loaded in: " + (System.currentTimeMillis() - time) + " ms");
+ return (LinkedList) ois.readObject();
+ }
+ return null;
+ }
+
+ public static boolean isPlotFileLegacy(int plotID) throws FileNotFoundException {
+ File region = new File(VirtualRealty.plotsSchemaFolder, REGION_PREFIX + plotID + REGION_SUFFIX);
+ File legacyRegion = new File(VirtualRealty.plotsSchemaFolder, LEGACY_REGION_PREFIX + plotID + REGION_SUFFIX);
+ if (region.exists()) return false;
+ if (legacyRegion.exists()) return true;
+ throw new FileNotFoundException();
+ }
+
+ public static void deletePlotFile(int id) {
+ File file = new File(VirtualRealty.plotsSchemaFolder, "plot" + id + ".region");
+ if (file.exists())
+ FileUtils.deleteQuietly(file);
+ File file2 = new File(VirtualRealty.plotsSchemaFolder, REGION_PREFIX + id + REGION_SUFFIX);
+ if (file2.exists())
+ FileUtils.deleteQuietly(file2);
+ File file3 = new File(VirtualRealty.plotsSchemaFolder, LEGACY_REGION_PREFIX + id + REGION_SUFFIX);
+ if (file3.exists())
+ FileUtils.deleteQuietly(file3);
+ }
+
+ public static boolean isOldSerialization(int plotID) {
+ File oldRegion = new File(VirtualRealty.plotsSchemaFolder, "plot" + plotID + ".region");
+ return oldRegion.exists();
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java
new file mode 100644
index 0000000..3d11ce8
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/SkullUtil.java
@@ -0,0 +1,76 @@
+package com.modnmetl.virtualrealty.utils.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;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.SkullMeta;
+
+import java.lang.reflect.Field;
+import java.util.Base64;
+import java.util.UUID;
+
+public class SkullUtil {
+
+ public static ItemStack getSkull(String url) {
+ ItemStack skull;
+ if (VirtualRealty.legacyVersion) {
+ skull = new ItemStack(VMaterial.getMaterial("SKULL_ITEM"), 1, (short) 3);
+ } else {
+ skull = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
+ }
+ if (url == null || url.isEmpty())
+ return skull;
+ SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
+ GameProfile profile = new GameProfile(UUID.randomUUID(), null);
+ byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", "http://textures.minecraft.net/texture/" + url).getBytes());
+ profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
+ Field profileField = null;
+ try {
+ profileField = skullMeta.getClass().getDeclaredField("profile");
+ } catch (NoSuchFieldException | SecurityException e) {
+ e.printStackTrace();
+ }
+ profileField.setAccessible(true);
+ try {
+ profileField.set(skullMeta, profile);
+ } catch (IllegalArgumentException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ skull.setItemMeta(skullMeta);
+ return skull;
+ }
+
+
+ public static ItemStack getSkull(String url, UUID uuid) {
+ ItemStack skull;
+ if (VirtualRealty.legacyVersion) {
+ skull = new ItemStack(VMaterial.getMaterial("SKULL_ITEM"), 1, (short) 3);
+ } else {
+ skull = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
+ }
+ if (url == null || url.isEmpty())
+ return skull;
+ SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
+ GameProfile profile = new GameProfile(uuid, null);
+ byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", "http://textures.minecraft.net/texture/" + url).getBytes());
+ profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
+ Field profileField = null;
+ try {
+ profileField = skullMeta.getClass().getDeclaredField("profile");
+ } catch (NoSuchFieldException | SecurityException e) {
+ e.printStackTrace();
+ }
+ profileField.setAccessible(true);
+ try {
+ profileField.set(skullMeta, profile);
+ } catch (IllegalArgumentException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ skull.setItemMeta(skullMeta);
+ return skull;
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java
new file mode 100644
index 0000000..782f893
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/VirtualBlock.java
@@ -0,0 +1,47 @@
+package com.modnmetl.virtualrealty.utils.data;
+
+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 {
+
+ private int x;
+ private int y;
+ private int z;
+
+ private int material;
+ private byte data;
+
+ private String blockData;
+
+ public VirtualBlock(int x, int y, int z, int material, byte data) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.material = material;
+ this.data = data;
+ }
+
+ public VirtualBlock(int x, int y, int z, String blockData) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.blockData = blockData;
+ }
+
+ public Block getBlock(World world) {
+ return world.getBlockAt(x,y,z);
+ }
+
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java b/src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java
new file mode 100644
index 0000000..98f6e71
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/loader/CustomClassLoader.java
@@ -0,0 +1,12 @@
+package com.modnmetl.virtualrealty.utils.loader;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+public class CustomClassLoader extends URLClassLoader {
+
+ public CustomClassLoader(URL[] urls, ClassLoader parent) {
+ super(urls, parent);
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/utils/multiversion/Chat.java b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java
similarity index 88%
rename from src/main/java/me/plytki/virtualrealty/utils/multiversion/Chat.java
rename to src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java
index c3c88bb..95a2597 100644
--- a/src/main/java/me/plytki/virtualrealty/utils/multiversion/Chat.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/Chat.java
@@ -1,6 +1,6 @@
-package me.plytki.virtualrealty.utils.multiversion;
+package com.modnmetl.virtualrealty.utils.multiversion;
-import me.plytki.virtualrealty.VirtualRealty;
+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;
@@ -24,7 +24,7 @@ public Chat(String text) {
public void sendTo(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
- if (VirtualRealty.isLegacy) {
+ if (VirtualRealty.legacyVersion) {
try {
Method m = Player.class.getDeclaredMethod("sendMessage", BaseComponent.class);
m.setAccessible(true);
diff --git a/src/main/java/me/plytki/virtualrealty/utils/multiversion/VMaterial.java b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java
similarity index 90%
rename from src/main/java/me/plytki/virtualrealty/utils/multiversion/VMaterial.java
rename to src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java
index 3e651a4..d39b011 100644
--- a/src/main/java/me/plytki/virtualrealty/utils/multiversion/VMaterial.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/multiversion/VMaterial.java
@@ -1,7 +1,7 @@
-package me.plytki.virtualrealty.utils.multiversion;
+package com.modnmetl.virtualrealty.utils.multiversion;
-import me.plytki.virtualrealty.VirtualRealty;
-import me.plytki.virtualrealty.exceptions.MaterialMatchException;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.exceptions.MaterialMatchException;
import org.bukkit.Material;
import java.lang.reflect.InvocationTargetException;
@@ -10,7 +10,7 @@
public class VMaterial {
public static Material getMaterial(int materialID) throws MaterialMatchException {
- if (VirtualRealty.isLegacy) {
+ if (VirtualRealty.legacyVersion) {
try {
Method m = Material.class.getDeclaredMethod("getMaterial", int.class);
m.setAccessible(true);
diff --git a/src/main/java/me/plytki/virtualrealty/VirtualRealty.java b/src/main/java/me/plytki/virtualrealty/VirtualRealty.java
deleted file mode 100644
index 3376005..0000000
--- a/src/main/java/me/plytki/virtualrealty/VirtualRealty.java
+++ /dev/null
@@ -1,560 +0,0 @@
-package me.plytki.virtualrealty;
-
-import me.plytki.virtualrealty.commands.PlotCommand;
-import me.plytki.virtualrealty.commands.VirtualRealtyCommand;
-import me.plytki.virtualrealty.configs.MessagesConfiguration;
-import me.plytki.virtualrealty.configs.PluginConfiguration;
-import me.plytki.virtualrealty.configs.SizesConfiguration;
-import me.plytki.virtualrealty.enums.Flag;
-import me.plytki.virtualrealty.enums.PlotSize;
-import me.plytki.virtualrealty.exceptions.MaterialMatchException;
-import me.plytki.virtualrealty.listeners.plot.BorderListener;
-import me.plytki.virtualrealty.listeners.plot.PlotListener;
-import me.plytki.virtualrealty.listeners.ProtectionListener;
-import me.plytki.virtualrealty.listeners.world.WorldListener;
-import me.plytki.virtualrealty.managers.PlotManager;
-import me.plytki.virtualrealty.objects.Plot;
-import me.plytki.virtualrealty.registry.VirtualPlaceholders;
-import me.plytki.virtualrealty.sql.SQL;
-import me.plytki.virtualrealty.utils.ConfigurationFactory;
-import me.plytki.virtualrealty.utils.SchematicUtil;
-import me.plytki.virtualrealty.utils.UpdateChecker;
-import me.plytki.virtualrealty.utils.multiversion.VMaterial;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.LineIterator;
-import org.bstats.bukkit.Metrics;
-import org.bstats.charts.AdvancedPie;
-import org.bstats.charts.SimplePie;
-import org.bukkit.Bukkit;
-import org.bukkit.Material;
-import org.bukkit.permissions.Permission;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.scheduler.BukkitRunnable;
-import org.bukkit.scheduler.BukkitTask;
-import org.dynmap.DynmapAPI;
-import org.dynmap.markers.MarkerIcon;
-import org.dynmap.markers.MarkerSet;
-
-import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
-import java.util.*;
-import java.util.concurrent.Callable;
-
-public final class VirtualRealty extends JavaPlugin {
-
- public final Locale locale = Locale.getDefault();
- public final List availableLocales = new ArrayList<>(Arrays.asList(new Locale("en", "GB"), new Locale("es", "ES"), new Locale("pl", "PL")));
-
- //CORE
- private static VirtualRealty instance;
- public static final String PREFIX = "§a§lVR §8§l» §7";
- public static ArrayList tasks = new ArrayList<>();
- private static final ArrayList preVersions = new ArrayList<>();
- public static boolean isLegacy = false;
- public static final Permission GLOBAL_PERMISSION = new Permission("virtualrealty");
-
- //FILES
- public static File plotsFolder;
- public static File plotsSchemaFolder;
- public PluginConfiguration pluginConfiguration;
- public SizesConfiguration sizesConfiguration;
- public MessagesConfiguration messagesConfiguration;
- private final File pluginConfigurationFile = new File(this.getDataFolder(), "config.yml");
- private final File sizesConfigurationFile = new File(this.getDataFolder(), "sizes.yml");
- private final File languagesDirectory = new File(this.getDataFolder(), "messages");
-
- //DYNMAP API
- public static boolean isDynmapPresent = false;
- public static DynmapAPI dapi = null;
- public static MarkerSet markerset = null;
- public static MarkerIcon markerIcon = null;
-
- @Override
- public void onEnable() {
- instance = this;
- if (checkLegacyVersions()) {
- isLegacy = true;
- }
- String[] updateCheck = UpdateChecker.getUpdate();
- if (updateCheck != null) {
- if (!updateCheck[0].equals(this.getDescription().getVersion())) {
- 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 {
- this.getLogger().info("Plugin is up to date!");
- }
- }
- try {
- checkConfig();
- checkSizesConfig();
- } catch (IOException e) {
- e.printStackTrace();
- }
- plotsFolder = new File(getInstance().getDataFolder().getAbsolutePath(), "plots");
- plotsFolder.mkdirs();
- plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain");
- plotsSchemaFolder.mkdirs();
- spawnLocales();
- reformatConfig();
- reloadConfigs();
- registerMetrics();
- loadSizesConfiguration();
- connectToDatabase();
- PlotManager.loadPlots();
- if (pluginConfiguration.dynmapMarkers) {
- registerDynmap();
- }
- reloadFlags();
- registerCommands();
- registerListeners();
- registerTasks();
- checkForOldSchemas();
- convertOldDatabase();
- if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){
- new VirtualPlaceholders(this).register();
- debug("Registered new placeholders");
- }
- debug("Server version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion());
- }
-
- @Override
- public void onDisable() {
- PlotManager.plots.forEach(Plot::update);
- tasks.forEach(BukkitTask::cancel);
- SQL.closeConnection();
- if (pluginConfiguration.dataModel == PluginConfiguration.DataModel.H2) {
- pluginConfiguration.dataModel = PluginConfiguration.DataModel.SQLITE;
- }
- pluginConfiguration.save();
- }
-
- public static void debug(String debugMessage) {
- if (VirtualRealty.getPluginConfiguration().debugMode)
- VirtualRealty.getInstance().getLogger().warning("DEBUG-MODE > " + debugMessage);
- }
-
- public void spawnLocales() {
- for (Locale availableLocale : availableLocales) {
- if (availableLocale.toString().equalsIgnoreCase("en_GB")) {
- File messagesConfigurationFile = new File(languagesDirectory, "messages_en_GB.yml");
- ConfigurationFactory configFactory = new ConfigurationFactory();
- configFactory.createMessagesConfiguration(messagesConfigurationFile);
- } else {
- File languageConfigurationFile = new File(languagesDirectory, "messages_" + availableLocale + ".yml");
- if (!languageConfigurationFile.exists()) {
- saveResource("messages_" + availableLocale + ".yml", true);
- File file = new File(this.getDataFolder(), "messages_" + availableLocale + ".yml");
- try {
- FileUtils.moveFile(file, languageConfigurationFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
-
- public void convertOldDatabase() {
- File oldDatabase = new File(VirtualRealty.getInstance().getDataFolder().getAbsolutePath() + "\\data\\data.mv.db");
- if (oldDatabase.exists()) {
- try {
- SQL.closeConnection();
- Connection connection = DriverManager.getConnection("jdbc:sqlite:" + VirtualRealty.getInstance().getDataFolder().getAbsolutePath() + "\\data\\data.db");
- SQL.setConnection(connection);
- Statement statement = connection.createStatement();
- SQL.setStatement(statement);
- statement.execute("CREATE TABLE IF NOT EXISTS `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` (`ID` INT(12) NOT NULL, `ownedBy` VARCHAR(36) NOT NULL, `members` TEXT, `assignedBy` VARCHAR(36) NOT NULL, `ownedUntilDate` DATETIME NOT NULL, `floorMaterial` VARCHAR(32) NOT NULL, `borderMaterial` VARCHAR(32) NOT NULL, `plotSize` VARCHAR(32) NOT NULL, `length` INT(24) NOT NULL, `width` INT(24) NOT NULL, `height` INT(24) NOT NULL, `createdLocation` TEXT(500) NOT NULL, `created` DATETIME, `modified` DATETIME, PRIMARY KEY(`ID`))");
- for (Plot plot : PlotManager.plots) {
- plot.insert();
- }
- FileUtils.deleteQuietly(oldDatabase);
- debug("H2 database converted successfully to SQLITE");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- public void reloadConfigs() {
- try {
- ConfigurationFactory configFactory = new ConfigurationFactory();
- pluginConfiguration = configFactory.createPluginConfiguration(pluginConfigurationFile);
- File messagesConfigurationFile = new File(languagesDirectory, "messages_" + pluginConfiguration.locale + ".yml");
- sizesConfiguration = configFactory.createSizesConfiguration(sizesConfigurationFile);
- messagesConfiguration = configFactory.createMessagesConfiguration(messagesConfigurationFile);
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
-
- public void reloadFlags() {
- if (pluginConfiguration.allowOutPlotBuild) {
- for (Flag.World value : Flag.World.values()) {
- value.setAllowed(true);
- }
- } else {
- for (Flag.World value : Flag.World.values()) {
- value.setAllowed(false);
- }
- }
- }
-
- public static void checkForOldSchemas() {
- for (Plot plot : PlotManager.plots) {
- File f = new File(VirtualRealty.plotsSchemaFolder, "plot" + plot.getID() + ".schem");
- if (f.exists()) {
- List data = SchematicUtil.oldLoad(plot.getID());
- FileUtils.deleteQuietly(f);
- SchematicUtil.save(plot.getID(), data.toArray(new String[0]));
- debug("Converted Plot #" + plot.getID() + " | File: " + f.getName());
- }
- }
- }
-
- public void registerDynmap() {
- new BukkitRunnable() {
- @Override
- public void run() {
- Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("dynmap");
- if (plugin != null) {
- isDynmapPresent = true;
- }
- if (plugin != null && plugin.isEnabled()) {
- dapi = (DynmapAPI) plugin;
- if (dapi.markerAPIInitialized()) {
- markerset = dapi.getMarkerAPI().getMarkerSet("virtualrealty.plots");
- if (markerset == null)
- markerset = dapi.getMarkerAPI().createMarkerSet("virutalrealty.plots", "Plots", dapi.getMarkerAPI().getMarkerIcons(), false);
- for (MarkerSet markerSet : dapi.getMarkerAPI().getMarkerSets()) {
- if (markerSet.getMarkerSetLabel().equalsIgnoreCase("Plots")) {
- markerset = markerSet;
- }
- }
- try {
- if (dapi.getMarkerAPI().getMarkerIcon("virtualrealty_main_icon") == null) {
- InputStream in = this.getClass().getResourceAsStream("/ploticon.png");
- if (in.available() > 0) {
- markerIcon = dapi.getMarkerAPI().createMarkerIcon("virtualrealty_main_icon", "Plots", in);
- }
- }
- else {
- markerIcon = dapi.getMarkerAPI().getMarkerIcon("virtualrealty_main_icon");
- }
- }
- catch (IOException ex) {}
- VirtualRealty.debug("Registering plots markers..");
- for (Plot plot : PlotManager.plots) {
- PlotManager.resetPlotMarker(plot);
- }
- VirtualRealty.debug("Registered plots markers");
- this.cancel();
- }
- }
- }
- }.runTaskTimer(this, 20, 20*5);
- }
-
-
- private void registerCommands() {
- this.getCommand("plot").setExecutor(new PlotCommand());
- this.getCommand("virtualrealty").setExecutor(new VirtualRealtyCommand());
- }
-
- private void registerListeners() {
- new BorderListener(this).registerEvents();
- new PlotListener(this).registerEvents();
- new ProtectionListener(this).registerEvents();
- new WorldListener(this).registerEvents();
- debug("Registered listeners");
- }
-
- private void registerTasks() {
- //debug("Registered tasks");
- }
-
- private void registerMetrics() {
- Metrics metrics = new Metrics(this, 12578);
- metrics.addCustomChart(new SimplePie("used_database", () -> pluginConfiguration.dataModel.name()));
- metrics.addCustomChart(new AdvancedPie("created_plots", new Callable