diff --git a/pom.xml b/pom.xml
index 10932cb..3e1c1ef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.modnmetl
virtualrealty
- 2.0.0
+ 2.1.0
jar
A plot creation and management plugin for Minecraft
@@ -163,7 +163,7 @@
com.modnmetl
virtualrealty-premium
- ${project.version}
+ 2.1.0
provided
diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
index 3928e86..4a68a14 100644
--- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
+++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
@@ -1,8 +1,5 @@
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;
@@ -16,92 +13,99 @@
import com.modnmetl.virtualrealty.listeners.PlotEntranceListener;
import com.modnmetl.virtualrealty.listeners.protection.PlotProtectionListener;
import com.modnmetl.virtualrealty.listeners.protection.WorldProtectionListener;
+import com.modnmetl.virtualrealty.listeners.stake.DraftListener;
+import com.modnmetl.virtualrealty.listeners.stake.StakeConfirmationListener;
+import com.modnmetl.virtualrealty.managers.DynmapManager;
+import com.modnmetl.virtualrealty.managers.MetricsManager;
import com.modnmetl.virtualrealty.managers.PlotManager;
import com.modnmetl.virtualrealty.managers.PlotMemberManager;
import com.modnmetl.virtualrealty.objects.Plot;
import com.modnmetl.virtualrealty.registry.VirtualPlaceholders;
import com.modnmetl.virtualrealty.sql.Database;
+import com.modnmetl.virtualrealty.utils.Loader;
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 lombok.Getter;
+import lombok.Setter;
+import lombok.SneakyThrows;
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.command.PluginCommand;
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.instrument.Instrumentation;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URISyntaxException;
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.net.URLDecoder;
import java.sql.SQLException;
import java.util.*;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import java.util.logging.Level;
+import java.util.stream.Collectors;
public final class VirtualRealty extends JavaPlugin {
//CORE
- public Locale locale = Locale.getDefault();
+ public List jarFiles = new ArrayList<>();
+ public DynmapManager dynmapManager;
+ public Locale locale;
+ @Getter
private static VirtualRealty instance;
- private static ClassLoader loader;
+ @Getter
+ public MetricsManager metricsManager;
+ public PluginConfiguration pluginConfiguration;
+ public SizesConfiguration sizesConfiguration;
+ public MessagesConfiguration messagesConfiguration;
+ public PermissionsConfiguration permissionsConfiguration;
+ private static ClassLoader classLoader;
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 List tasks = new ArrayList<>();
+ private final List preVersions = Arrays.asList("1.12", "1.11", "1.10", "1.9", "1.8");
public static boolean legacyVersion = false;
public static ServerVersion currentServerVersion = ServerVersion.MODERN;
public static final Permission GLOBAL_PERMISSION = new Permission("virtualrealty");
+ @Getter
+ @Setter
private static Object premium;
public static boolean upToDate;
public static String latestVersion;
//FILES
+ @Getter
+ @Setter
+ public static File loaderFile;
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() {
+ classLoader = getClassLoader();
instance = this;
- loader = getClassLoader();
- VersionChecker.hideOk = true;
- if (checkLegacyVersions()) {
- legacyVersion = true;
- currentServerVersion = ServerVersion.LEGACY;
+ try {
+ jarFiles.add(new JarFile(getFile()));
+ } catch (IOException e) {
+ e.printStackTrace();
}
+ checkLegacyVersions();
databaseFolder.mkdirs();
plotsFolder = new File(getInstance().getDataFolder().getAbsolutePath(), "plots");
plotsFolder.mkdirs();
@@ -141,15 +145,16 @@ public void onEnable() {
}
if (!pluginConfiguration.license.key.isEmpty() && !pluginConfiguration.license.email.isEmpty()) {
try {
- runLoader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion());
+ new Loader(pluginConfiguration.license.key, pluginConfiguration.license.email, this.getDescription().getVersion(), getLoader(), false);
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
- getLogger().log(Level.WARNING, "Loading of premium features failed.");
+ getLogger().log(Level.WARNING, "Load of premium features failed.");
}
}
- registerMetrics();
+ metricsManager = new MetricsManager(this, 14066);
+ metricsManager.registerMetrics();
loadSizesConfiguration();
try {
- connectToDatabase();
+ Database.connectToDatabase(databaseFile);
} catch (SQLException e) {
getLogger().log(Level.WARNING, "Failed to connect to the database.");
this.getPluginLoader().disablePlugin(this);
@@ -158,7 +163,8 @@ public void onEnable() {
PlotManager.loadPlots();
PlotMemberManager.loadMembers();
if (pluginConfiguration.dynmapMarkers) {
- registerDynmap();
+ dynmapManager = new DynmapManager(this);
+ dynmapManager.registerDynmap();
}
registerCommands();
registerListeners();
@@ -172,11 +178,17 @@ public void onEnable() {
@Override
public void onDisable() {
try {
- Method method = Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, getCustomClassLoader()).getMethod("onDisable");
+ Method method = Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, getLoader()).getMethod("onDisable");
method.setAccessible(true);
method.invoke(premium);
} catch (Exception ignored) {
}
+ DraftListener.DRAFT_MAP.forEach((player, gridStructureEntryEntry) -> {
+ player.getInventory().remove(gridStructureEntryEntry.getValue().getValue().getItemStack());
+ player.getInventory().addItem(gridStructureEntryEntry.getValue().getKey().getItemStack());
+ gridStructureEntryEntry.getKey().removeGrid();
+ });
+ DraftListener.DRAFT_MAP.clear();
PlotManager.getPlots().forEach(Plot::update);
tasks.forEach(BukkitTask::cancel);
try {
@@ -188,62 +200,14 @@ public void onDisable() {
dataSource.getConnection().close();
}
}
- } catch (SQLException ignored) {
- }
+ } 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 static void debug(String message) {
+ if (VirtualRealty.getPluginConfiguration().debugMode) VirtualRealty.getInstance().getLogger().warning("DEBUG > " + message);
}
public void configureMessages() {
@@ -265,56 +229,34 @@ public void reloadConfigs() {
}
}
- 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() {
+ PluginCommand plotCommand = this.getCommand("plot");
+ assert plotCommand != null;
+ plotCommand.setExecutor(new PlotCommand());
+ plotCommand.setTabCompleter( new CommandManager());
+ registerSubCommands(PlotCommand.class, "panel");
+
+ PluginCommand vrCommand = this.getCommand("virtualrealty");
+ assert vrCommand != null;
+ vrCommand.setExecutor(new VirtualRealtyCommand());
+ vrCommand.setTabCompleter( new CommandManager());
+ registerSubCommands(VirtualRealtyCommand.class);
}
- 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);
+ public void registerSubCommands(Class> mainCommandClass, String... names) {
+ SubCommand.registerSubCommands(names, mainCommandClass);
+ for (JarFile jarFile : jarFiles) {
+ for (Enumeration entry = jarFile.entries(); entry.hasMoreElements();) {
+ JarEntry jarEntry = entry.nextElement();
+ String name = jarEntry.getName().replace("/", ".");
+ if (name.endsWith(".class") && name.startsWith(mainCommandClass.getPackage().getName() + ".subcommand.")) {
+ try {
+ Class> clazz = Class.forName(name.replaceAll("[.]class", ""), true, getClassLoader());
+ SubCommand.registerSubCommands(new String[]{ clazz.getSimpleName().toLowerCase().replaceAll("subcommand", "") }, mainCommandClass);
+ } catch (ClassNotFoundException ignored) {}
+ }
+ }
+ }
}
private void registerListeners() {
@@ -323,81 +265,18 @@ private void registerListeners() {
new WorldProtectionListener(this);
new PlotEntranceListener(this);
new PlayerActionListener(this);
+ new DraftListener(this);
+ new StakeConfirmationListener(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);
+ List> classes = new ArrayList<>();
+ classes.add(Class.forName("com.modnmetl.virtualrealty.listeners.premium.PanelListener", true, getLoader()));
+ for (Class> aClass : classes) {
+ aClass.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;
@@ -447,12 +326,14 @@ public void loadSizesConfiguration() {
debug("Loaded sizes config");
}
- public static VirtualRealty getInstance() {
- return instance;
- }
-
- public static ClassLoader getCustomClassLoader() {
- return loader;
+ public void checkLegacyVersions() {
+ for (String preVersion : preVersions) {
+ if (Bukkit.getBukkitVersion().toLowerCase().contains(preVersion.toLowerCase())) {
+ legacyVersion = true;
+ currentServerVersion = ServerVersion.LEGACY;
+ return;
+ }
+ }
}
public static PluginConfiguration getPluginConfiguration() {
@@ -479,30 +360,20 @@ 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 DynmapManager getDynmapManager() {
+ return getInstance().dynmapManager;
}
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");
+ public static ClassLoader getLoader() {
+ return classLoader;
+ }
+
+ public void setClassLoader(ClassLoader newClassLoader) {
+ classLoader = newClassLoader;
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
index 49cf771..5744088 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java
@@ -1,6 +1,5 @@
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;
@@ -8,7 +7,6 @@
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;
@@ -49,6 +47,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman
case "CREATE": {
if (assertPermission(sender, VirtualRealtyCommand.COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase())) return null;
if (args.length > 1) {
+ // Enum Hints (Sizes)
if (args.length == 2) {
for (PlotSize value : PlotSize.values()) {
if (value == PlotSize.CUSTOM) continue;
@@ -62,15 +61,34 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman
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;
+ // Enum Hints (Materials)
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());
+ PlotSize plotSize = predefinedValue ? PlotSize.valueOf(args[1].toUpperCase()) : PlotSize.CUSTOM;
+ if (plotSize != PlotSize.AREA) {
+ 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());
+ }
+ }
+ }
+ } else if (args.length < 6) {
+ switch (args.length) {
+ case 3: {
+ tabCompleter.add(String.valueOf(plotSize.getLength()));
+ break;
+ }
+ case 4: {
+ tabCompleter.add(String.valueOf(plotSize.getHeight()));
+ break;
+ }
+ case 5: {
+ tabCompleter.add(String.valueOf(plotSize.getWidth()));
+ break;
}
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
index 1342d70..9f2ea5b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
@@ -11,13 +11,17 @@
import java.lang.reflect.Method;
import java.util.LinkedList;
+import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION;
+
public abstract class SubCommand {
+ private final String[] args;
private final CommandSender commandSender;
private final LinkedList helpList;
@SneakyThrows
public SubCommand(CommandSender sender, Command command, String label, String[] args, LinkedList helpList) throws FailedCommandException {
+ this.args = args;
this.helpList = helpList;
this.commandSender = sender;
exec(sender, command, label, args);
@@ -32,6 +36,21 @@ public void assertPlayer() throws FailedCommandException {
}
}
+ public String getDefaultPermission() {
+ return COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase();
+ }
+
+ public void assertPermission() throws InsufficientPermissionsException {
+ if (!commandSender.hasPermission(getDefaultPermission())) {
+ if (commandSender.isOp()) {
+ commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", getDefaultPermission()));
+ } else {
+ commandSender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissionsShort.replaceAll("%permission%", getDefaultPermission()));
+ }
+ throw new InsufficientPermissionsException();
+ }
+ }
+
public void assertPermission(String permission) throws InsufficientPermissionsException {
if (!commandSender.hasPermission(permission)) {
if (commandSender.isOp()) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
index 3495249..f969084 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java
@@ -2,9 +2,12 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabExecutor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
@@ -36,17 +39,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
printHelp(sender);
return false;
}
- if (args[0].equalsIgnoreCase("panel") || args[0].equalsIgnoreCase("draft") || args[0].equalsIgnoreCase("stake")) {
+ if (args[0].equalsIgnoreCase("panel")) {
try {
- Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getCustomClassLoader());
+ Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getLoader());
} catch (Exception e) {
sender.sendMessage("§aThis function is available with a valid license key");
- sender.sendMessage("§aPlease visit §fhttps://modnmetl.com/ §ato purchase one");
+ TextComponent linkComponent = new TextComponent("§fhttps://modnmetl.com/");
+ linkComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://modnmetl.com/category/virtual-realty-plugin-61eef16fe2eeab00116a3e64"));
+ sender.spigot().sendMessage(new TextComponent("§aPlease visit "), linkComponent, new TextComponent(" §ato purchase one"));
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());
+ 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.getLoader());
clazz.getConstructors()[0].newInstance(sender, command, label, args);
} catch (Exception e) {
if(!(e instanceof InvocationTargetException)) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java
index d91cdec..cf9df9a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java
@@ -6,7 +6,7 @@
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 com.modnmetl.virtualrealty.objects.data.PlotMember;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java
new file mode 100644
index 0000000..76a5d89
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java
@@ -0,0 +1,98 @@
+package com.modnmetl.virtualrealty.commands.plot.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.enums.items.VItem;
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.listeners.stake.DraftListener;
+import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.objects.data.PlotItem;
+import com.modnmetl.virtualrealty.objects.region.Cuboid;
+import com.modnmetl.virtualrealty.objects.region.GridStructure;
+import com.modnmetl.virtualrealty.utils.RegionUtil;
+import de.tr7zw.nbtapi.NBTItem;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.PlayerInventory;
+
+import java.util.AbstractMap;
+import java.util.LinkedList;
+
+public class DraftSubCommand extends SubCommand {
+
+ public DraftSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, new LinkedList<>());
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ assertPlayer();
+ Player player = ((Player) sender);
+ if (DraftListener.DRAFT_MAP.containsKey(player)) {
+ player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
+ DraftListener.DRAFT_MAP.get(player).getKey().removeGrid();
+ DraftListener.DRAFT_MAP.remove(player);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeDisabled);
+ return;
+ }
+ PlayerInventory inv;
+ ItemStack claimItem;
+ if (VirtualRealty.legacyVersion) {
+ inv = player.getInventory();
+ claimItem = player.getItemInHand();
+ } else {
+ inv = player.getInventory();
+ claimItem = inv.getItemInMainHand();
+ }
+ NBTItem claimNbtItem;
+ if (!(claimItem.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD)
+ &&
+ (claimNbtItem = new NBTItem(claimItem)).getString("vrplot_item") != null && claimNbtItem.getString("vrplot_item").equals("CLAIM"))) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notHoldingPlotClaim);
+ return;
+ }
+ PlotItem plotItem = PlotItem.fromItemStack(claimItem);
+ Plot plot = PlotManager.getPlot(player.getLocation());
+ if (plot != null) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot);
+ return;
+ }
+ PlotSize plotSize = PlotSize.valueOf(claimNbtItem.getString("vrplot_size"));
+ Cuboid cuboid = RegionUtil.getRegion(player.getLocation(), Direction.byYaw(player.getLocation().getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth());
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision);
+ if (!GridStructure.isCuboidGridDisplaying(player, 0)) {
+ new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, ((Player) sender).getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true);
+
+ }
+ return;
+ }
+ if (RegionUtil.isCollidingWithBedrock(cuboid)) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledBedrock);
+ GridStructure.isCuboidGridDisplaying(player, 0);
+ if (!GridStructure.isCuboidGridDisplaying(player, 0)) {
+ new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, ((Player) sender).getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true);
+ }
+ return;
+ }
+ PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT);
+ GridStructure draftStructure = new GridStructure(player, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), 0, ((Player) sender).getWorld(), 0, player.getLocation());
+ DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(draftStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem)));
+ inv.remove(claimItem);
+ if (VirtualRealty.legacyVersion) {
+ player.setItemInHand(draftItem.getItemStack());
+ } else {
+ inv.setItemInMainHand(draftItem.getItemStack());
+ }
+ draftStructure.preview(player.getLocation(), true, false);
+ VirtualRealty.getMessages().draftModeEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§")));
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java
index c8b89d8..7bc52e0 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java
@@ -5,7 +5,7 @@
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 com.modnmetl.virtualrealty.objects.data.PlotMember;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java
index c54b81b..de668fd 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java
@@ -6,7 +6,7 @@
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 com.modnmetl.virtualrealty.objects.data.PlotMember;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java
new file mode 100644
index 0000000..7fe2f87
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java
@@ -0,0 +1,54 @@
+package com.modnmetl.virtualrealty.commands.plot.subcommand;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.commands.SubCommand;
+import com.modnmetl.virtualrealty.enums.Direction;
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.listeners.stake.DraftListener;
+import com.modnmetl.virtualrealty.objects.data.PlotItem;
+import com.modnmetl.virtualrealty.objects.region.Cuboid;
+import com.modnmetl.virtualrealty.objects.region.GridStructure;
+import com.modnmetl.virtualrealty.utils.RegionUtil;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.*;
+
+public class StakeSubCommand extends SubCommand {
+
+ public static Set stakeConfirmations = new HashSet<>();
+
+ public StakeSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ super(sender, command, label, args, new LinkedList<>());
+ }
+
+ @Override
+ public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
+ assertPlayer();
+ Player player = ((Player) sender);
+ if (!DraftListener.DRAFT_MAP.containsKey(player)) {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noDraftClaimEnabled);
+ return;
+ }
+ GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey();
+ PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey();
+ Cuboid cuboid = RegionUtil.getRegion(gridStructure.getPreviewLocation(), Direction.byYaw(gridStructure.getPreviewLocation().getYaw()), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth());
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
+ player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
+ DraftListener.DRAFT_MAP.get(player).getKey().removeGrid();
+ DraftListener.DRAFT_MAP.remove(player);
+ gridStructure.removeGrid();
+ gridStructure.setDisplayTicks(20L * 6);
+ gridStructure.preview(true, true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision);
+ return;
+ }
+ stakeConfirmations.add(player.getUniqueId());
+ for (String s : VirtualRealty.getMessages().stakeConfirmation) {
+ sender.sendMessage(VirtualRealty.PREFIX + s);
+ }
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java
index 6dd15fd..df89f06 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java
@@ -5,13 +5,11 @@
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 {
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
index 803eb60..1a3be53 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java
@@ -3,6 +3,8 @@
import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException;
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.*;
import org.bukkit.permissions.Permission;
import org.jetbrains.annotations.NotNull;
@@ -45,17 +47,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
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());
+ 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.getLoader());
clazz.getConstructors()[0].newInstance(sender, command, label, args);
} catch (Exception e) {
if(!(e instanceof InvocationTargetException)) {
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java
index 125855d..44e6b84 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java
@@ -16,8 +16,6 @@
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<>();
@@ -34,7 +32,7 @@ public AssignSubCommand(CommandSender sender, Command command, String label, Str
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (args.length < 2) {
for (String helpMessage : HELP) {
sender.sendMessage(helpMessage);
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java
index 631e88b..31c380b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java
@@ -26,8 +26,6 @@
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<>();
@@ -35,7 +33,8 @@ public class CreateSubCommand extends SubCommand {
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<§7small/medium/large§8> §8<§7floor (optional)§8> §8<§7border (optional)§8> §8<§7--natural(optional)§8>");
+ HELP.add(" §a/vrplot create area §8<§7length§8> §8<§7height§8> §8<§7width§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>");
}
@@ -46,7 +45,7 @@ public CreateSubCommand(CommandSender sender, Command command, String label, Str
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
assertPlayer();
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (args.length < 2) {
printHelp();
return;
@@ -60,16 +59,61 @@ public void exec(CommandSender sender, Command command, String label, String[] a
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);
+ if (plotSize == PlotSize.AREA) {
+ int length = plotSize.getLength();
+ int height = plotSize.getHeight();
+ int width = plotSize.getWidth();
+ if (args.length > 2) {
+ try {
+ length = Integer.parseInt(args[2]);
+ height = Integer.parseInt(args[3]);
+ width = Integer.parseInt(args[4]);
+ } catch (IllegalArgumentException e) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
+ return;
+ }
+ }
+ if (length < 1 || width < 1 || height < 1) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().graterThenZero);
+ return;
+ }
+ if (length > 500 || width > 500 || height > 500) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().hardLimit);
+ return;
+ }
+ Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width);
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting);
+ } else {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
+ long timeStart = System.currentTimeMillis();
+ Plot plot = PlotManager.createPlot(location, PlotSize.AREA, length, height, width, true);
+ long timeEnd = System.currentTimeMillis();
+ BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
+ BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
+ BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
+ textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
+ textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
+ textComponent.addExtra(textComponent2);
+ textComponent.addExtra(textComponent3);
+ new Chat(textComponent).sendTo(player);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ new GridStructure(player, plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 20);
+ }
} else {
- 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) {
+ Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth());
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting);
+ } else {
+ boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
+ Material floorMaterial = null;
+ byte floorData = 0;
+ Material borderMaterial = null;
+ byte borderData = 0;
if (args.length >= 3 && !natural) {
try {
floorMaterial = VMaterial.getMaterial(args[2].split(":")[0].toUpperCase());
@@ -100,33 +144,33 @@ public void exec(CommandSender sender, Command command, String label, String[] a
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);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
+ long timeStart = System.currentTimeMillis();
+ Plot plot = PlotManager.createPlot(location, plotSize, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), natural);
+ if (!natural) {
+ if (floorMaterial != null) {
+ plot.setFloorMaterial(floorMaterial, floorData);
+ }
+ if (borderMaterial != null) {
+ plot.setBorderMaterial(borderMaterial, borderData);
+ }
}
+ long timeEnd = System.currentTimeMillis();
+ BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
+ BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
+ BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
+ textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
+ textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
+ textComponent.addExtra(textComponent2);
+ textComponent.addExtra(textComponent3);
+ new Chat(textComponent).sendTo(player);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ new GridStructure(player, plot.getPlotSize().getLength(), plot.getPlotSize().getHeight(), plot.getPlotSize().getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 20);
}
- 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);
@@ -143,12 +187,16 @@ public void run() {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().useNaturalNumbersOnly);
return;
}
+ if (length < 1 || width < 1 || height < 1) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().graterThenZero);
+ return;
+ }
if (length > 500 || width > 500 || height > 500) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().LHWHardLimit);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().hardLimit);
return;
}
Cuboid cuboid = RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), length, height, width);
- if (PlotManager.isColliding(cuboid) || PlotManager.getPlot(player.getLocation()) != null) {
+ if (RegionUtil.isCollidingWithAnotherPlot(cuboid) || RegionUtil.isCollidingWithBedrock(cuboid)) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantCreateOnExisting);
} else {
boolean natural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
@@ -209,7 +257,7 @@ public void run() {
new BukkitRunnable() {
@Override
public void run() {
- new GridStructure(player, plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview();
+ new GridStructure(player, plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation()).preview(true, false);
}
}.runTaskLater(VirtualRealty.getInstance(), 20);
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java
new file mode 100644
index 0000000..2044b44
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java
@@ -0,0 +1,88 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.commands.SubCommand;
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.DecimalFormat;
+import java.util.Arrays;
+import java.util.LinkedList;
+
+public class DebugSubCommand extends SubCommand {
+
+ private static long LAST_REQUEST = 0;
+
+ public DebugSubCommand(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();
+ VirtualRealty instance = VirtualRealty.getInstance();
+ if (System.currentTimeMillis() - LAST_REQUEST < 1500) {
+ sender.sendMessage(VirtualRealty.PREFIX + "§cPlease wait " + Math.abs(System.currentTimeMillis() - LAST_REQUEST - 1500) + "ms. §7(Rate limiting)");
+ return;
+ }
+ sender.sendMessage(" ");
+ sender.sendMessage(" §8§l«§8§m §8[§aDebug§8]§m §8§l»");
+ sender.sendMessage(" §8┏ §7Operating System: §a" + System.getProperty("os.name") + " §7(" + System.getProperty("os.version") + "-" + System.getProperty("os.arch") + ")");
+ sender.sendMessage(" §8┣ §7Java Version: §a" + System.getProperty("java.version"));
+ sender.sendMessage(" §8┣ §7Engine: §a" + instance.getServer().getName() + " §7(" + instance.getServer().getBukkitVersion() + ")");
+ sender.sendMessage(" §8┣ §7Core count: §a" + Runtime.getRuntime().availableProcessors());
+ sender.sendMessage(" §8┣ §7RAM: §a" + format(Runtime.getRuntime().totalMemory()) + "§7/§a" + format(Runtime.getRuntime().maxMemory()) + " §7MB");
+ try {
+ // API Rate Limit is 45 requests per minute
+ URL url = new URL("http://ip-api.com/json/?fields=org,isp,country,countryCode");
+ URLConnection urlConnection = url.openConnection();
+ JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(urlConnection.getInputStream())).getAsJsonObject();
+ LAST_REQUEST = System.currentTimeMillis();
+ sender.sendMessage(" §8┣ §7Location: §a" + jsonObject.get("country").getAsString() + " §7(" + jsonObject.get("countryCode").getAsString() + ")");
+ sender.sendMessage(" §8┣ §7ISP: §a" + jsonObject.get("isp").getAsString());
+ sender.sendMessage(" §8┣ §7Host: §a" + jsonObject.get("org").getAsString());
+ } catch (IOException ignored) {
+ sender.sendMessage(" §8┣ §7Couldn't connect to the IP-API");
+ }
+ sender.sendMessage(" §8┣ §7Default GM: §a" + instance.getServer().getDefaultGameMode().name().charAt(0) + instance.getServer().getDefaultGameMode().name().substring(1).toLowerCase());
+ Plugin[] plugins = instance.getServer().getPluginManager().getPlugins();
+ sender.sendMessage(" §8┣ §7Version: §a" + VirtualRealty.currentServerVersion.name().substring(0, 1).toUpperCase() + VirtualRealty.currentServerVersion.name().substring(1).toLowerCase());
+ sender.sendMessage(" §8┣ §7Plugins (§a" + plugins.length + "§7):");
+ int limit = sender instanceof Player ? 2 : 3;
+ int lastRow = (plugins.length / limit + (plugins.length % limit == 0 ? 0 : 1));
+ int pluginIndex = 0;
+ for (int row = 0; row < lastRow; row++) {
+ StringBuilder sb = new StringBuilder(" §8" + (row == lastRow - 1 ? "┗" : "┣") + " §a");
+ for (int index = 0; index < Arrays.stream(plugins).skip((long) row * limit).limit(limit).count(); index++) {
+ Plugin plugin = (Plugin) Arrays.stream(plugins).skip((long) row * limit).limit(index + 1).toArray()[index];
+ if (plugin != null) {
+ sb.append("§a").append(plugin.getName()).append(" §7(").append(plugin.getDescription().getVersion()).append(")");
+ try {
+ Object o = Arrays.stream(plugins).skip((long) row * limit).limit(index + 2).toArray()[index + 1];
+ if (pluginIndex % limit != (limit == 2 ? 1 : 2))
+ sb.append(" §8| ");
+ } catch (Exception ignored) {
+ }
+ } else break;
+ pluginIndex++;
+ }
+ sender.sendMessage(sb.toString());
+ }
+ }
+
+ private String format(double memory) {
+ DecimalFormat df = new DecimalFormat("##.#");
+ memory = memory / (1024 * 1024);
+ return df.format(memory);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
index c51a3d9..a0bc24d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java
@@ -16,8 +16,6 @@
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 {
@@ -26,7 +24,7 @@ public InfoSubCommand(CommandSender sender, Command command, String label, Strin
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (args.length < 2) {
assertPlayer();
Plot plot = PlotManager.getPlot(((Player) sender).getLocation());
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java
new file mode 100644
index 0000000..5013fc5
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java
@@ -0,0 +1,101 @@
+package com.modnmetl.virtualrealty.commands.vrplot.subcommand;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.commands.SubCommand;
+import com.modnmetl.virtualrealty.enums.PlotSize;
+import com.modnmetl.virtualrealty.enums.items.VItem;
+import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.objects.data.PlotItem;
+import com.modnmetl.virtualrealty.utils.EnumUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.*;
+
+public class ItemSubCommand 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 item §8<§7small/medium/large§8> §8<§7floor§8> §8<§7border§8> §8<§7lease duration (in days)§8> §8<§7amount of items§8> §8<§7player§8> §8<§7--natural(optional)§8>");
+ HELP.add(" §a/vrplot item §8<§7custom/area§8> §8<§7length§8> §8<§7height§8> §8<§7width§8> §8<§7floor§8> §8<§7border§8> §8<§7lease duration (in days)§8> §8<§7amount of items§8> §8<§7player§8> §8<§7--natural(optional)§8>");
+ }
+
+ public ItemSubCommand(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();
+ boolean isNatural = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--natural"));
+ args = Arrays.stream(args).filter(s1 -> !s1.equalsIgnoreCase("--natural")).toArray(String[]::new);
+ if (args.length < 2) {
+ printHelp();
+ return;
+ }
+ PlotSize plotSize = PlotSize.valueOf(args[1].toUpperCase());
+ if (!EnumUtils.isValidEnum(PlotSize.class, args[1].toUpperCase())) return;
+ int length;
+ int height;
+ int width;
+ int backwardArgs;
+ if (plotSize == PlotSize.CUSTOM || plotSize == PlotSize.AREA) {
+ backwardArgs = (isNatural ? 2 : 0);
+ length = Integer.parseInt(args[2]);
+ height = Integer.parseInt(args[3]);
+ width = Integer.parseInt(args[4]);
+ } else {
+ backwardArgs = 3 + (isNatural ? 2 : 0);
+ length = plotSize.getLength();
+ height = plotSize.getHeight();
+ width = plotSize.getWidth();
+ }
+ if (length < 1 || width < 1 || height < 1) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().graterThenZero);
+ return;
+ }
+ Map.Entry floorData;
+ Map.Entry borderData;
+ if (VirtualRealty.legacyVersion) {
+ if (isNatural) {
+ floorData = new AbstractMap.SimpleEntry<>(Material.AIR.name(), (byte)0);
+ borderData = new AbstractMap.SimpleEntry<>(Material.AIR.name(), (byte)0);
+ } else {
+ if (args[5 - backwardArgs].equalsIgnoreCase("default")) {
+ floorData = new AbstractMap.SimpleEntry<>(plotSize.getFloorMaterial().name(), plotSize.getFloorData());
+ } else floorData = new AbstractMap.SimpleEntry<>(Material.valueOf(args[5 - backwardArgs].split(":")[0].toUpperCase()).name(), Byte.valueOf(args[5 - backwardArgs].split(":")[1]));
+ if (args[6 - backwardArgs].equalsIgnoreCase("default")) {
+ borderData = new AbstractMap.SimpleEntry<>(plotSize.getBorderMaterial().name(), plotSize.getBorderData());
+ } else borderData = new AbstractMap.SimpleEntry<>(Material.valueOf(args[6 - backwardArgs].split(":")[0].toUpperCase()).name(), Byte.valueOf(args[6 - backwardArgs].split(":")[1]));
+ }
+ } else {
+ if (isNatural) {
+ floorData = new AbstractMap.SimpleEntry<>(Material.AIR.createBlockData().getAsString(), (byte)0);
+ borderData = new AbstractMap.SimpleEntry<>(Material.AIR.createBlockData().getAsString(), (byte)0);
+ } else {
+ if (args[5 - backwardArgs].equalsIgnoreCase("default")) {
+ floorData = new AbstractMap.SimpleEntry<>(plotSize.getFloorMaterial().createBlockData().getAsString(), (byte) 0);
+ } else
+ floorData = new AbstractMap.SimpleEntry<>(Material.valueOf(args[5 - backwardArgs].toUpperCase()).createBlockData().getAsString(), (byte) 0);
+ if (args[6 - backwardArgs].equalsIgnoreCase("default")) {
+ borderData = new AbstractMap.SimpleEntry<>(plotSize.getBorderMaterial().createBlockData().getAsString(), (byte) 0);
+ } else
+ borderData = new AbstractMap.SimpleEntry<>(Material.valueOf(args[6 - backwardArgs].toUpperCase()).createBlockData().getAsString(), (byte) 0);
+ }
+ }
+ int additionalDays = Integer.parseInt(args[7-backwardArgs]);
+ int itemsAmount = Integer.parseInt(args[8-backwardArgs]);
+ Player onlinePlayer = Bukkit.getPlayer(args[9-backwardArgs]);
+ for (int i = 0; i < itemsAmount; i++) {
+ PlotItem plotItem = new PlotItem(VItem.CLAIM, plotSize, length, height, width, floorData, borderData, isNatural, additionalDays, UUID.randomUUID());
+ onlinePlayer.getInventory().addItem(plotItem.getItemStack());
+ }
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java
index a04fa23..53bb9ab 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java
@@ -18,8 +18,6 @@
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 {
@@ -28,7 +26,7 @@ public ListSubCommand(CommandSender sender, Command command, String label, Strin
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (PlotManager.getPlots().isEmpty()) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().noPlots);
return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java
index fdc275f..0ab4f51 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java
@@ -3,6 +3,7 @@
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
+import com.modnmetl.virtualrealty.managers.DynmapManager;
import com.modnmetl.virtualrealty.managers.PlotManager;
import com.modnmetl.virtualrealty.objects.Plot;
import org.bukkit.command.Command;
@@ -10,8 +11,6 @@
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 {
@@ -20,20 +19,22 @@ public ReloadSubCommand(CommandSender sender, Command command, String label, Str
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
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();
+ if (VirtualRealty.getDynmapManager() != null) {
+ if (VirtualRealty.getPluginConfiguration().dynmapMarkers) {
+ if (VirtualRealty.getDynmapManager().markerset != null) {
+ VirtualRealty.getDynmapManager().markerset.deleteMarkerSet();
+ }
+ VirtualRealty.getDynmapManager().registerDynmap();
+ for (Plot plot : PlotManager.getPlots()) {
+ DynmapManager.resetPlotMarker(plot);
+ }
+ } else {
+ if (VirtualRealty.getDynmapManager().markerset != null) {
+ VirtualRealty.getDynmapManager().markerset.deleteMarkerSet();
+ }
}
}
PlotManager.loadPlots();
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java
index aa7e2f3..2cd7ec9 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java
@@ -10,8 +10,6 @@
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<>();
@@ -28,7 +26,7 @@ public RemoveSubCommand(CommandSender sender, Command command, String label, Str
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (args.length < 2) {
printHelp();
return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java
index 1b8ad67..14ab0b2 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java
@@ -2,7 +2,6 @@
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;
@@ -39,7 +38,7 @@ public SetSubCommand(CommandSender sender, Command command, String label, String
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (args.length < 3) {
printHelp();
return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java
index 73ce292..970963b 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java
@@ -5,15 +5,12 @@
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<>();
@@ -31,7 +28,7 @@ public TpSubCommand(CommandSender sender, Command command, String label, String[
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
assertPlayer();
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (args.length < 2) {
printHelp();
return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java
index bd9907e..d588ac9 100644
--- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java
@@ -2,7 +2,6 @@
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;
@@ -11,8 +10,6 @@
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<>();
@@ -29,7 +26,7 @@ public UnassignSubCommand(CommandSender sender, Command command, String label, S
@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception {
- assertPermission(COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase());
+ assertPermission();
if (args.length < 2) {
printHelp();
return;
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java
new file mode 100644
index 0000000..92a4d52
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java
@@ -0,0 +1,31 @@
+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 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.command.Command;
+import org.bukkit.command.CommandSender;
+
+import java.util.LinkedList;
+
+public class VersionSubCommand extends SubCommand {
+
+ public VersionSubCommand(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 {
+ TextComponent textComponent = new TextComponent();
+ if (!VirtualRealty.upToDate) {
+ textComponent = new TextComponent(" §7(Newer version available)");
+ textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick here to download new version!")}));
+ textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/"));
+ }
+ sender.spigot().sendMessage(new TextComponent(VirtualRealty.PREFIX + "Version: §a" + VirtualRealty.getInstance().getDescription().getVersion()), textComponent);
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java
new file mode 100644
index 0000000..2e7eef3
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java
@@ -0,0 +1,41 @@
+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.objects.region.GridStructure;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.LinkedList;
+
+public class VisualSubCommand extends SubCommand {
+
+ public VisualSubCommand(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 {
+ assertPlayer();
+ assertPermission();
+ Player player = ((Player) sender);
+ Plot plot = PlotManager.getPlot(player.getLocation());
+ if (plot == null) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notStandingOnPlot);
+ return;
+ }
+ if (GridStructure.isCuboidGridDisplaying(player, plot.getID())) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryActive);
+ return;
+ }
+ GridStructure previewStructure = new GridStructure(((Player) sender), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 20 * 6, plot.getCreatedLocation());
+ previewStructure.preview(player.getLocation(), true, false);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed);
+ }
+
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
index 773fff9..096a89d 100644
--- a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
+++ b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java
@@ -2,7 +2,6 @@
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;
@@ -37,7 +36,8 @@ public class MessagesConfiguration extends OkaeriConfig {
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 hardLimit = "§cL, W and H hard-limit is 500!";
+ public String graterThenZero = "§cL, W and H values must be greater than 0!";
public String specifyUsername = "§cSpecify username!";
public String playerNotFoundWithUsername = "§cCouldn't find player with specified username!";
public String invalidDateProvided = "§cInvalid date format provided!";
@@ -50,7 +50,6 @@ public class MessagesConfiguration extends OkaeriConfig {
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!";
@@ -99,8 +98,8 @@ public class MessagesConfiguration extends OkaeriConfig {
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 draftModeCancelledBedrock = "§cDraft cancelled. Colliding with bedrock.";
+ public String draftModeCancelledCollision = "§cDraft cancelled. Colliding with another plot.";
public String draftModeDisabledDueToDeath = "§cDraft mode has been disabled due to death.";
public List draftModeEnabled = Arrays.asList(
" ",
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
index cadefd3..3f306a8 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/PlotEntranceListener.java
@@ -4,7 +4,7 @@
import com.modnmetl.virtualrealty.managers.PlotManager;
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.objects.Plot;
-import com.modnmetl.virtualrealty.objects.PlotMember;
+import com.modnmetl.virtualrealty.objects.data.PlotMember;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java
index fff76ca..e8fe6f0 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/player/PlayerActionListener.java
@@ -7,7 +7,9 @@
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.scheduler.BukkitRunnable;
public class PlayerActionListener extends VirtualListener {
@@ -20,11 +22,16 @@ 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);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ player.sendMessage(VirtualRealty.PREFIX + "§7A new version of VirtualRealty plugin is available. §a[" + VirtualRealty.latestVersion + "]");
+ TextComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aDownload the new version of the plugin here!");
+ textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick here to download the update!")}));
+ textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/virtual-realty.95599/"));
+ player.spigot().sendMessage(textComponent);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 5);
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java
index 1d1ef52..1d61616 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java
@@ -7,7 +7,7 @@
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 com.modnmetl.virtualrealty.objects.data.PlotMember;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java
index 1108722..dfe2480 100644
--- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/WorldProtectionListener.java
@@ -52,7 +52,7 @@ public void onBlockInteract(PlayerInteractEvent e) {
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());
+ Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", false, VirtualRealty.getLoader());
if (!WorldUtil.hasPermission(RegionPermission.SWITCH)) {
e.setCancelled(true);
player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
@@ -60,7 +60,7 @@ public void onBlockInteract(PlayerInteractEvent e) {
return;
}
if (PlotProtectionListener.INTERACTABLE.contains(e.getClickedBlock().getType())) {
- Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", false, VirtualRealty.getCustomClassLoader());
+ Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", false, VirtualRealty.getLoader());
if (!WorldUtil.hasPermission(RegionPermission.ITEM_USE)) {
e.setCancelled(true);
player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantInteract);
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java
new file mode 100644
index 0000000..77a4e8b
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/DraftListener.java
@@ -0,0 +1,104 @@
+package com.modnmetl.virtualrealty.listeners.stake;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.listeners.VirtualListener;
+import com.modnmetl.virtualrealty.objects.data.PlotItem;
+import com.modnmetl.virtualrealty.objects.region.GridStructure;
+import de.tr7zw.nbtapi.NBTItem;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.block.BlockPlaceEvent;
+import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCreativeEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerItemHeldEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.PlayerInventory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DraftListener extends VirtualListener {
+
+ public static final HashMap>> DRAFT_MAP = new HashMap<>();
+
+ public DraftListener(VirtualRealty plugin) {
+ super(plugin);
+ }
+
+ @EventHandler
+ public void onInventoryClick(InventoryClickEvent e) {
+ Player player = ((Player) e.getWhoClicked());
+ if (DRAFT_MAP.containsKey(player)) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onInventoryClick(InventoryCreativeEvent e) {
+ Player player = ((Player) e.getWhoClicked());
+ if (DRAFT_MAP.containsKey(player)) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onItemDrop(PlayerDropItemEvent e) {
+ Player player = e.getPlayer();
+ if (DRAFT_MAP.containsKey(player)) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onSlotSwitch(PlayerItemHeldEvent e) {
+ Player player = e.getPlayer();
+ if (DRAFT_MAP.containsKey(player)) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onPlayerDeath(PlayerDeathEvent e) {
+ Player player = e.getEntity();
+ if (DRAFT_MAP.containsKey(player)) {
+ e.getDrops().remove(DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ e.getDrops().add(DRAFT_MAP.get(player).getValue().getKey().getItemStack());
+ player.getInventory().remove(DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ player.getInventory().addItem(DRAFT_MAP.get(player).getValue().getKey().getItemStack());
+ DRAFT_MAP.get(player).getKey().removeGrid();
+ DRAFT_MAP.remove(player);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeDisabledDueToDeath);
+ }
+ }
+
+ @EventHandler
+ public void onBlockPlace(BlockPlaceEvent e) {
+ Player player = e.getPlayer();
+ ItemStack itemInHand;
+ if (VirtualRealty.legacyVersion) {
+ itemInHand = player.getItemInHand();
+ } else {
+ itemInHand = player.getInventory().getItemInMainHand();
+ }
+ if (itemInHand.getType() == (VirtualRealty.legacyVersion ? Material.valueOf("SKULL_ITEM") : Material.PLAYER_HEAD) && (new NBTItem(itemInHand)).hasKey("vrplot_item")) {
+ e.setCancelled(true);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantPlaceDraftItems);
+ }
+ }
+
+ @EventHandler
+ public void onPlayerLeave(PlayerQuitEvent e) {
+ Player player = e.getPlayer();
+ if (DRAFT_MAP.containsKey(player)) {
+ player.getInventory().remove(DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ player.getInventory().addItem(DRAFT_MAP.get(player).getValue().getKey().getItemStack());
+ DRAFT_MAP.get(player).getKey().removeGrid();
+ DRAFT_MAP.remove(player);
+ }
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/stake/StakeConfirmationListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/StakeConfirmationListener.java
new file mode 100644
index 0000000..2c919b0
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/listeners/stake/StakeConfirmationListener.java
@@ -0,0 +1,103 @@
+package com.modnmetl.virtualrealty.listeners.stake;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.commands.plot.subcommand.StakeSubCommand;
+import com.modnmetl.virtualrealty.enums.PlotSize;
+import com.modnmetl.virtualrealty.listeners.VirtualListener;
+import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.objects.data.PlotItem;
+import com.modnmetl.virtualrealty.objects.region.GridStructure;
+import com.modnmetl.virtualrealty.utils.multiversion.Chat;
+import de.tr7zw.nbtapi.NBTItem;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.HoverEvent;
+import net.md_5.bungee.api.chat.TextComponent;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.time.LocalDateTime;
+import java.util.AbstractMap;
+
+public class StakeConfirmationListener extends VirtualListener {
+
+ public StakeConfirmationListener(VirtualRealty plugin) {
+ super(plugin);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onChat(AsyncPlayerChatEvent e) {
+ if (StakeSubCommand.stakeConfirmations.contains(e.getPlayer().getUniqueId())) {
+ e.setCancelled(true);
+ Player player = e.getPlayer();
+ GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey();
+ PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey();
+ PlotSize plotSize = plotItem.getPlotSize();
+ ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack();
+ NBTItem item = new NBTItem(plotItemStack);
+ gridStructure.removeGrid();
+ if (e.getMessage().equalsIgnoreCase("YES")) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().notCollidingCreating);
+ long timeStart = System.currentTimeMillis();
+ Plot plot = PlotManager.createPlot(gridStructure.getPreviewLocation().subtract(0, 1, 0), plotSize, plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.isNatural());
+ AbstractMap.SimpleEntry floorData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_floor_material"), item.getByte("vrplot_floor_data"));
+ AbstractMap.SimpleEntry borderData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_border_material"), item.getByte("vrplot_border_data"));
+ if (!plotItem.isNatural()) {
+ if (VirtualRealty.legacyVersion) {
+ plot.setFloorMaterial(Material.valueOf(floorData.getKey()), floorData.getValue());
+ plot.setBorderMaterial(Material.valueOf(borderData.getKey()), borderData.getValue());
+ } else {
+ plot.setFloorMaterial(Bukkit.createBlockData(floorData.getKey()).getMaterial(), floorData.getValue());
+ plot.setBorderMaterial(Bukkit.createBlockData(borderData.getKey()).getMaterial(), borderData.getValue());
+ }
+ }
+ plot.setOwnedBy(player.getUniqueId());
+ if (plotItem.getAdditionalDays() == 0) {
+ plot.setOwnedUntilDate(Plot.MAX_DATE);
+ } else {
+ plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays()));
+ }
+ player.getInventory().remove(plotItemStack);
+ long timeEnd = System.currentTimeMillis();
+ BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
+ BaseComponent textComponent2 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent2.replaceAll("%plot_id%", String.valueOf(plot.getID())));
+ BaseComponent textComponent3 = new TextComponent(VirtualRealty.getMessages().creationPlotComponent3.replaceAll("%creation_time%", String.valueOf(timeEnd - timeStart)));
+ textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(VirtualRealty.getMessages().clickToShowDetailedInfo.replaceAll("%plot_id%", String.valueOf(plot.getID())))}));
+ textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
+ textComponent.addExtra(textComponent2);
+ textComponent.addExtra(textComponent3);
+ new Chat(textComponent).sendTo(player);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ gridStructure.setCuboidId(plot.getID());
+ gridStructure.setDisplayTicks(20 * 6);
+ gridStructure.preview(true, false);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 20);
+ }
+ }.runTaskLater(VirtualRealty.getInstance(), 10);
+ } else {
+ player.getInventory().removeItem(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
+ player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
+ DraftListener.DRAFT_MAP.get(player).getKey().removeGrid();
+ DraftListener.DRAFT_MAP.remove(player);
+ player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled);
+ }
+ DraftListener.DRAFT_MAP.remove(player);
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java
new file mode 100644
index 0000000..0cc2434
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java
@@ -0,0 +1,131 @@
+package com.modnmetl.virtualrealty.managers;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.enums.dynmap.HighlightType;
+import com.modnmetl.virtualrealty.objects.Plot;
+import lombok.Getter;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.dynmap.DynmapAPI;
+import org.dynmap.markers.AreaMarker;
+import org.dynmap.markers.MarkerIcon;
+import org.dynmap.markers.MarkerSet;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.HashSet;
+import java.util.Set;
+
+public class DynmapManager {
+
+ private final VirtualRealty instance;
+
+ @Getter
+ public boolean dynmapPresent = false;
+ public DynmapAPI dapi = null;
+ public MarkerSet markerset = null;
+ public MarkerIcon markerIcon = null;
+ 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<>();
+
+
+ public DynmapManager(VirtualRealty instance) {
+ this.instance = instance;
+ }
+
+ public void registerDynmap() {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("dynmap");
+ if (plugin == null) return;
+ dynmapPresent = 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()) {
+ resetPlotMarker(plot);
+ }
+ VirtualRealty.debug("Registered plots markers");
+ this.cancel();
+ }
+ }
+ }
+ }.runTaskTimer(instance, 20, 20 * 5);
+ }
+
+ private static AreaMarker getAreaMarker(String areaMarkerName) {
+ if (VirtualRealty.getDynmapManager() == null) return null;
+ for (AreaMarker areaMarker : VirtualRealty.getDynmapManager().markerset.getAreaMarkers()) {
+ if (areaMarker.getMarkerID().equalsIgnoreCase(areaMarkerName)) {
+ return areaMarker;
+ }
+ }
+ return null;
+ }
+
+ public static void resetPlotMarker(Plot plot) {
+ if (VirtualRealty.getDynmapManager() == null || !VirtualRealty.getDynmapManager().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.getDynmapManager().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.getDynmapManager().markerset);
+ }
+
+ public static void removeDynMapMarker(Plot plot) {
+ if (VirtualRealty.getDynmapManager() == null || !VirtualRealty.getDynmapManager().isDynmapPresent() || VirtualRealty.getDynmapManager().dapi == null || VirtualRealty.getDynmapManager().markerset == null) return;
+ AreaMarker marker = VirtualRealty.getDynmapManager().markerset.findAreaMarker("virtualrealty.plots." + plot.getID());
+ areaMarkers.remove(marker);
+ marker.deleteMarker();
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java
new file mode 100644
index 0000000..f5ddb36
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/managers/MetricsManager.java
@@ -0,0 +1,78 @@
+package com.modnmetl.virtualrealty.managers;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.objects.Plot;
+import lombok.Getter;
+import org.bstats.bukkit.Metrics;
+import org.bstats.charts.AdvancedPie;
+import org.bstats.charts.SimplePie;
+
+import java.util.*;
+
+@Getter
+public class MetricsManager {
+
+ private final Metrics metrics;
+ private final VirtualRealty virtualRealty;
+ private final int serviceID;
+ private final List licenses;
+
+ public MetricsManager(VirtualRealty instance, int serviceID) {
+ this.virtualRealty = instance;
+ this.serviceID = serviceID;
+ this.metrics = new Metrics(instance, serviceID);
+ this.licenses = new ArrayList<>();
+ }
+
+
+ public void registerMetrics() {
+ metrics.addCustomChart(new SimplePie("used_database", () -> VirtualRealty.getPluginConfiguration().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;
+ }));
+ VirtualRealty.debug("Registered metrics");
+ }
+
+ public void addLicenseUser(String licenseName) {
+ licenses.add(licenseName);
+ metrics.addCustomChart(new SimplePie("used_license", () -> licenseName));
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
index d90bd83..12ecbaf 100644
--- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/managers/PlotManager.java
@@ -1,6 +1,5 @@
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;
@@ -11,22 +10,15 @@
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<>();
+ private static final Set plots = new LinkedHashSet<>();
public static void loadPlots() {
plots.clear();
@@ -58,6 +50,14 @@ public static Plot getPlot(int ID) {
return null;
}
+ public static List getPlots(String world) {
+ List newPlots = new LinkedList<>();
+ for (Plot plot : plots) {
+ if (plot.getCreatedWorldString().equals(world)) newPlots.add(plot);
+ }
+ return newPlots;
+ }
+
public static HashMap getPlots(UUID owner) {
HashMap plotHashMap = new HashMap<>();
for (Plot plot : plots) {
@@ -104,7 +104,7 @@ 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)) {
+ if(region.isIn(newVector, plot.getCreatedWorld())) {
return plot;
}
}
@@ -118,14 +118,14 @@ public static void removePlotFromList(Plot 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);
+ return region.isIn(newVector, location.getWorld());
}
public static Plot getBorderedPlot(Location location) {
BlockVector3 newVector = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
for (Plot plot : plots) {
Cuboid region = new Cuboid(plot.getBorderBottomLeftCorner(), plot.getBorderTopRightCorner(), location.getWorld());
- if(region.contains(newVector)) {
+ if(region.isIn(newVector, plot.getCreatedWorld())) {
return plot;
}
}
@@ -135,68 +135,7 @@ public static Plot getBorderedPlot(Location location) {
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();
+ return region.isIn(newVector, plot.getCreatedWorld());
}
}
\ No newline at end of file
diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java
index 71c6d19..8bf5b39 100644
--- a/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java
+++ b/src/main/java/com/modnmetl/virtualrealty/managers/PlotMemberManager.java
@@ -1,7 +1,7 @@
package com.modnmetl.virtualrealty.managers;
import com.modnmetl.virtualrealty.VirtualRealty;
-import com.modnmetl.virtualrealty.objects.PlotMember;
+import com.modnmetl.virtualrealty.objects.data.PlotMember;
import com.modnmetl.virtualrealty.sql.Database;
import java.sql.ResultSet;
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java
index f809421..8747dbd 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java
@@ -4,7 +4,9 @@
import com.modnmetl.virtualrealty.enums.Direction;
import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
import com.modnmetl.virtualrealty.enums.PlotSize;
+import com.modnmetl.virtualrealty.managers.DynmapManager;
import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.data.PlotMember;
import com.modnmetl.virtualrealty.objects.region.Cuboid;
import com.modnmetl.virtualrealty.sql.Database;
import com.modnmetl.virtualrealty.utils.EnumUtils;
@@ -84,8 +86,8 @@ public Plot(Location location, Material floorMaterial, Material borderMaterial,
this.width = width;
this.height = height;
initialize(natural);
- if (VirtualRealty.markerset != null) {
- PlotManager.resetPlotMarker(this);
+ if (VirtualRealty.getDynmapManager() != null && VirtualRealty.getDynmapManager().markerset != null) {
+ DynmapManager.resetPlotMarker(this);
}
}
@@ -294,6 +296,10 @@ public BlockVector3 getCenter() {
return new Cuboid(bottomLeftCorner, topRightCorner, createdLocation.getWorld()).getCenterVector();
}
+ public Cuboid getCuboid() {
+ return new Cuboid(bottomLeftCorner, topRightCorner, createdLocation.getWorld());
+ }
+
public org.bukkit.World getCreatedWorld() {
return Bukkit.getWorld(createdWorld);
}
@@ -570,6 +576,7 @@ public void prepareBlocks(Location location, boolean natural) {
public void unloadPlot() {
if (SchematicUtil.isOldSerialization(ID)) {
+ long time = System.currentTimeMillis();
Location location = null;
switch (createdDirection) {
case SOUTH: {
@@ -590,6 +597,7 @@ public void unloadPlot() {
}
}
OldSchematicUtil.paste(ID, location);
+ VirtualRealty.debug("Region pasted in: " + (System.currentTimeMillis() - time) + " ms (Old Serialization)");
} else {
long time = System.currentTimeMillis();
SchematicUtil.paste(ID);
@@ -650,7 +658,7 @@ public void remove() {
for (PlotMember member : this.getMembers()) {
removeMember(member);
}
- PlotManager.removeDynMapMarker(this);
+ DynmapManager.removeDynMapMarker(this);
try {
Database.getInstance().getStatement().execute("DELETE FROM `" + VirtualRealty.getPluginConfiguration().mysql.plotsTableName + "` WHERE `ID` = '" + ID + "';");
} catch (SQLException e) {
@@ -658,6 +666,7 @@ public void remove() {
}
SchematicUtil.deletePlotFile(ID);
PlotManager.removePlotFromList(this);
+ VirtualRealty.debug("Removed plot #" + this.ID);
}
public Direction getCreatedDirection() {
@@ -665,7 +674,8 @@ public Direction getCreatedDirection() {
}
public void updateMarker() {
- PlotManager.resetPlotMarker(this);
+ DynmapManager.resetPlotMarker(this);
+ VirtualRealty.debug("Updated marker #" + this.ID);
}
@Override
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java
new file mode 100644
index 0000000..3c975c8
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotItem.java
@@ -0,0 +1,149 @@
+package com.modnmetl.virtualrealty.objects.data;
+
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.enums.PlotSize;
+import com.modnmetl.virtualrealty.enums.items.VItem;
+import com.modnmetl.virtualrealty.utils.data.ItemBuilder;
+import com.modnmetl.virtualrealty.utils.data.SkullUtil;
+import de.tr7zw.nbtapi.NBTItem;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.RequiredArgsConstructor;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.UUID;
+
+@Data
+@AllArgsConstructor
+@RequiredArgsConstructor
+public class PlotItem {
+
+ public static final String NBT_PREFIX = "vrplot_";
+
+ private final VItem itemType;
+ private final PlotSize plotSize;
+ private final int length;
+ private final int height;
+ private final int width;
+ private final Map.Entry floorData;
+ private final Map.Entry borderData;
+ private final boolean natural;
+ private int additionalDays;
+ private UUID uuid;
+
+ public ItemStack getItemStack() {
+ ItemBuilder itemBuilder;
+ if (uuid == null) {
+ itemBuilder = new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b"));
+ } else {
+ itemBuilder = new ItemBuilder(SkullUtil.getSkull("16bb9fb97ba87cb727cd0ff477f769370bea19ccbfafb581629cd5639f2fec2b", uuid));
+ }
+ switch (itemType) {
+ case CLAIM: {
+ itemBuilder
+ .setName("§a" + plotSize.name().toCharArray()[0] + plotSize.name().substring(1).toLowerCase() + " Plot Claim");
+ break;
+ }
+ case DRAFT: {
+ itemBuilder
+ .setName("§a" + plotSize.name().toCharArray()[0] + plotSize.name().substring(1).toLowerCase() + " Plot Draft Claim")
+ .addEnchant(Enchantment.ARROW_INFINITE, 10);
+ break;
+ }
+ }
+ Material floor;
+ Material border;
+ if (VirtualRealty.legacyVersion) {
+ floor = Material.valueOf(floorData.getKey());
+ border = Material.valueOf(borderData.getKey());
+ } else {
+ floor = Bukkit.createBlockData(floorData.getKey()).getMaterial();
+ border = Bukkit.createBlockData(borderData.getKey()).getMaterial();
+ }
+ itemBuilder
+ .addLoreLine(" §8┏ §fSize: §7" + plotSize.name())
+ .addLoreLine(" §8┣ §fNatural: §7" + (natural ? "Yes" : "No"))
+ .addLoreLine(" §8┣ §fLength: §7" + length)
+ .addLoreLine(" §8┣ §fHeight: §7" + height)
+ .addLoreLine(" §8┣ §fWidth: §7" + width)
+ .addLoreLine(" §8┣ §fFloor: §7" + (floor == Material.AIR ? "NONE" : floor.name()))
+ .addLoreLine(" §8┣ §fBorder: §7" + (border == Material.AIR ? "NONE" : border.name()))
+ .addLoreLine(" §8┗ §fLease days: §7" + (additionalDays == 0 ? "No Expiry" : additionalDays));
+ ItemStack itemStack = itemBuilder.toItemStack();
+ NBTItem nbtItem = new NBTItem(itemStack);
+
+ nbtItem.setString(NBT_PREFIX + "item", itemType.name());
+ nbtItem.setString(NBT_PREFIX + "size", plotSize.name());
+ nbtItem.setInteger(NBT_PREFIX + "length", length);
+ nbtItem.setInteger(NBT_PREFIX + "height", height);
+ nbtItem.setInteger(NBT_PREFIX + "width", width);
+ nbtItem.setString(NBT_PREFIX + "floor_material", floorData.getKey());
+ nbtItem.setByte(NBT_PREFIX + "floor_data", floorData.getValue());
+ nbtItem.setString(NBT_PREFIX + "border_material", borderData.getKey());
+ nbtItem.setByte(NBT_PREFIX + "border_data", borderData.getValue());
+ nbtItem.setBoolean(NBT_PREFIX + "natural", natural);
+ nbtItem.setInteger(NBT_PREFIX + "additional_days", additionalDays);
+ nbtItem.setString(NBT_PREFIX + "stack_uuid", uuid == null ? UUID.randomUUID().toString() : uuid.toString());
+ nbtItem.applyNBT(itemStack);
+ return itemStack;
+ }
+
+ public Map.Entry getLegacyFloorData() {
+ return floorData;
+ }
+
+ public BlockData getFloorData() {
+ return Bukkit.createBlockData(floorData.getKey());
+ }
+
+ public Map.Entry getLegacyBorderData() {
+ return borderData;
+ }
+
+ public BlockData getBorderData() {
+ return Bukkit.createBlockData(borderData.getKey());
+ }
+
+ public static PlotItem fromItemStack(ItemStack itemStack) {
+ NBTItem nbtItem = new NBTItem(itemStack);
+ Map.Entry floorData = new AbstractMap.SimpleEntry<>(nbtItem.getString("vrplot_floor_material"), nbtItem.getByte("vrplot_floor_data"));
+ Map.Entry borderData = new AbstractMap.SimpleEntry<>(nbtItem.getString("vrplot_border_material"), nbtItem.getByte("vrplot_border_data"));
+ PlotSize plotSize = PlotSize.valueOf(nbtItem.getString("vrplot_size"));
+ return new PlotItem(
+ VItem.valueOf(nbtItem.getString(NBT_PREFIX + "item")),
+ plotSize,
+ nbtItem.getInteger(NBT_PREFIX + "length"),
+ nbtItem.getInteger(NBT_PREFIX + "height"),
+ nbtItem.getInteger(NBT_PREFIX + "width"),
+ floorData,
+ borderData,
+ nbtItem.getBoolean(NBT_PREFIX + "natural"),
+ nbtItem.getInteger(NBT_PREFIX + "additional_days"),
+ UUID.fromString(nbtItem.getString(NBT_PREFIX + "stack_uuid"))
+ );
+ }
+
+ public static PlotItem fromItemStack(ItemStack itemStack, VItem itemType) {
+ PlotItem plotItem = fromItemStack(itemStack);
+ return new PlotItem(itemType, plotItem.getPlotSize(), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.floorData, plotItem.borderData, plotItem.isNatural(), plotItem.getAdditionalDays(), plotItem.getUuid());
+ }
+
+ public int getLength() {
+ return ((plotSize == PlotSize.AREA || plotSize == PlotSize.CUSTOM) ? length : plotSize.getLength());
+ }
+
+ public int getHeight() {
+ return ((plotSize == PlotSize.AREA || plotSize == PlotSize.CUSTOM) ? height : plotSize.getHeight());
+ }
+
+ public int getWidth() {
+ return ((plotSize == PlotSize.AREA || plotSize == PlotSize.CUSTOM) ? width : plotSize.getWidth());
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/PlotMember.java b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java
similarity index 98%
rename from src/main/java/com/modnmetl/virtualrealty/objects/PlotMember.java
rename to src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java
index b9a2575..7abf8f4 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/PlotMember.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/data/PlotMember.java
@@ -1,9 +1,10 @@
-package com.modnmetl.virtualrealty.objects;
+package com.modnmetl.virtualrealty.objects.data;
import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.enums.permissions.ManagementPermission;
import com.modnmetl.virtualrealty.enums.permissions.RegionPermission;
import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
import com.modnmetl.virtualrealty.sql.Database;
import lombok.Data;
import lombok.Setter;
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java b/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
index 6512d7e..2d3ff64 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/math/BlockVector2.java
@@ -1,5 +1,8 @@
package com.modnmetl.virtualrealty.objects.math;
+import org.bukkit.Location;
+import org.bukkit.World;
+
import java.util.Vector;
public class BlockVector2 extends Vector {
@@ -36,6 +39,10 @@ public boolean containedWithin(BlockVector2 min, BlockVector2 max) {
return this.x >= min.x && this.x <= max.x && this.z >= min.z && this.z <= max.z;
}
+ public Location toLocation(World world, int y) {
+ return new Location(world, x, y, z);
+ }
+
@Override
public String toString() {
return "(" + x + ", " + z + ")";
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java b/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
index 88d72ba..17063a9 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/region/Cuboid.java
@@ -2,15 +2,14 @@
import com.modnmetl.virtualrealty.objects.math.BlockVector2;
import com.modnmetl.virtualrealty.objects.math.BlockVector3;
+import org.bukkit.Bukkit;
import org.bukkit.Location;
+import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
public class Cuboid {
@@ -20,12 +19,6 @@ public class Cuboid {
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) {
@@ -36,12 +29,6 @@ public Cuboid(Location point1, Location point2) {
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) {
@@ -52,28 +39,39 @@ public Cuboid(BlockVector3 point1, BlockVector3 point2, World world) {
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<>();
+ public List getBlocks() {
+ List blocks = new ArrayList<>();
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);
+ blocks.add(this.world.getBlockAt(x, y, z));
}
}
}
- return bL;
+ return blocks;
+ }
+
+ public List getFlatBlocks() {
+ List blocks = new ArrayList<>();
+ for(int x = this.xMin; x <= this.xMax; ++x) {
+ for(int z = this.zMin; z <= this.zMax; ++z) {
+ blocks.add(this.world.getBlockAt(x, 0, z));
+ }
+ }
+ return blocks;
+ }
+
+ public List getFlatRegion() {
+ List blocksVector = new ArrayList<>();
+ for (Block block : getFlatBlocks()) {
+ blocksVector.add(BlockVector2.at(block.getLocation().getBlockX(), block.getLocation().getBlockZ()));
+ }
+ return blocksVector;
}
+
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);
}
@@ -110,25 +108,12 @@ 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) {
+ public boolean isIn(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() {
+ public int getCuboidSize() {
return this.getHeight() * this.getXWidth() * this.getZWidth();
}
@@ -145,18 +130,19 @@ public boolean isIn(Location loc) {
.getBlockZ() >= this.zMin && loc.getBlockZ() <= this.zMax;
}
- public boolean isIn(Player player) {
- return this.isIn(player.getLocation());
+ public boolean isIn(BlockVector2 vector2, World world, int spacing) {
+ return world == this.world && vector2.getBlockX() >= this.xMin - spacing && vector2.getBlockX() <= this.xMax + spacing &&
+ vector2.getBlockZ() >= this.zMin - spacing && vector2.getBlockZ() <= this.zMax + spacing;
}
- 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 isIn(BlockVector2 vector2, World world) {
+ return this.isIn(vector2, world, 0);
}
- public boolean isColliding(Cuboid region) {
+ public boolean isColliding(Cuboid cuboid) {
+ if (cuboid.getWorld() != world) return false;
List flatRegion1 = new ArrayList<>(this.getFlatRegion());
- List flatRegion2 = new ArrayList<>(region.getFlatRegion());
+ List flatRegion2 = new ArrayList<>(cuboid.getFlatRegion());
for (BlockVector2 vector1 : flatRegion1) {
for (BlockVector2 vector2 : flatRegion2)
if (vector1.getBlockX() == vector2.getBlockX() && vector1.getBlockZ() == vector2.getBlockZ()) return true;
@@ -164,12 +150,13 @@ public boolean isColliding(Cuboid region) {
return false;
}
- public List getFlatRegion() {
- List blocksVector = new ArrayList<>();
- for (Block block : blockList()) {
- blocksVector.add(BlockVector2.at(block.getLocation().getBlockX(), block.getLocation().getBlockZ()));
+ public boolean containsBlock(Block block) {
+ Location blockLocation = block.getLocation();
+ if (block.getWorld() != world) return false;
+ for (BlockVector2 vector2 : getFlatRegion()) {
+ if (vector2.getBlockX() == blockLocation.getBlockX() && vector2.getBlockZ() == blockLocation.getBlockZ()) return true;
}
- return blocksVector;
+ return false;
}
public List getWalls() {
diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java b/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java
index d90c789..87a4087 100644
--- a/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java
+++ b/src/main/java/com/modnmetl/virtualrealty/objects/region/GridStructure.java
@@ -54,11 +54,11 @@ 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(boolean visualization, boolean colliding) {
+ preview(null, visualization, colliding);
}
- public void preview(Location playerPreviewLocation) {
+ public void preview(Location playerPreviewLocation, boolean visualization, boolean colliding) {
changedBlocks.clear();
Plot plot = PlotManager.getPlot(cuboidId);
Location location = previewLocation;
@@ -162,7 +162,7 @@ public void preview(Location playerPreviewLocation) {
}
swapBlocks(
blocks,
- PlotManager.isColliding(RegionUtil.getRegion(location, Direction.byYaw(location.getYaw()), getLength(), getHeight(), getWidth()))
+ visualization && colliding
);
if (displayTicks == 0) return;
new BukkitRunnable() {
diff --git a/src/main/java/com/modnmetl/virtualrealty/sql/Database.java b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
index ee8caeb..afde87a 100644
--- a/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
+++ b/src/main/java/com/modnmetl/virtualrealty/sql/Database.java
@@ -19,6 +19,7 @@
public class Database {
+ @Getter
private static Database instance;
@Getter
@@ -38,6 +39,7 @@ public Database(File file) throws SQLException {
dataSource = sqLiteDataSource;
connection = dataSource.getConnection();
statement = connection.createStatement();
+ instance = this;
createTables();
updateTables();
}
@@ -54,6 +56,7 @@ public Database(String hostname, int port, String username, String password, Str
dataSource.setLogWriter(new PrintWriter(System.out));
connection = dataSource.getConnection();
statement = connection.createStatement();
+ instance = this;
createTables();
updateTables();
}
@@ -105,12 +108,20 @@ private void updateTables() {
}
}
- public static Database getInstance() {
- return instance;
- }
-
- public static void setInstance(Database database) {
- instance = database;
+ public static void connectToDatabase(File databaseFile) throws SQLException {
+ if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.SQLITE) {
+ new Database(databaseFile);
+ }
+ if (VirtualRealty.getPluginConfiguration().dataModel == PluginConfiguration.DataModel.MYSQL) {
+ new Database(
+ VirtualRealty.getPluginConfiguration().mysql.hostname,
+ VirtualRealty.getPluginConfiguration().mysql.port,
+ VirtualRealty.getPluginConfiguration().mysql.user,
+ VirtualRealty.getPluginConfiguration().mysql.password,
+ VirtualRealty.getPluginConfiguration().mysql.database
+ );
+ }
+ VirtualRealty.debug("Connected to database");
}
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java b/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java
new file mode 100644
index 0000000..35fdf50
--- /dev/null
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/Loader.java
@@ -0,0 +1,87 @@
+package com.modnmetl.virtualrealty.utils;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.modnmetl.virtualrealty.VirtualRealty;
+import com.modnmetl.virtualrealty.utils.loader.CustomClassLoader;
+import lombok.SneakyThrows;
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.jar.JarFile;
+
+public class Loader {
+
+ public Loader(String licenseKey, String licenseEmail, String pluginVersion, ClassLoader classLoader, boolean debug) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ runLoader(licenseKey, licenseEmail, pluginVersion, classLoader, debug);
+ }
+
+ private void runLoader(String licenseKey, String licenseEmail, String pluginVersion, ClassLoader classLoader, boolean debug) throws IOException {
+ VirtualRealty.debug("Injecting premium..");
+ URL url;
+ HttpURLConnection httpConn;
+ if (debug) {
+ url = new URL("http://localhost/virtualrealty/premium" + "?license=" + licenseKey + "&email=" + licenseEmail + "&version=" + pluginVersion);
+ httpConn = (HttpURLConnection) url.openConnection();
+ } else {
+ url = new URL("https://api.modnmetl.com/auth/key");
+ 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) {
+ VirtualRealty.debug("Authentication error | " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage());
+ return;
+ }
+ File loaderFile;
+ try (InputStream in = httpConn.getInputStream()) {
+ loaderFile = File.createTempFile(String.valueOf(Arrays.asList(new Random().nextInt(9), new Random().nextInt(9), new Random().nextInt(9))), ".tmp");
+ VirtualRealty.setLoaderFile(loaderFile);
+ FileUtils.deleteQuietly(loaderFile);
+ Files.copy(in, Paths.get(loaderFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
+ VirtualRealty.getInstance().jarFiles.add(new JarFile(loaderFile));
+ }
+ httpConn.disconnect();
+ URL jarUrl = loaderFile.toURI().toURL();
+ VirtualRealty.getInstance().setClassLoader(new CustomClassLoader(
+ new URL[]{ jarUrl }, classLoader)
+ );
+ try {
+ Class> clazz = Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, VirtualRealty.getLoader());
+ VirtualRealty.setPremium(clazz.newInstance());
+ } catch (Exception ignored) {
+ VirtualRealty.debug("Premium injection failed");
+ return;
+ }
+ VirtualRealty.debug("Premium injected");
+ }
+
+}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
index a4bb4d3..57246c7 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/RegionUtil.java
@@ -1,9 +1,15 @@
package com.modnmetl.virtualrealty.utils;
+import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.enums.Direction;
+import com.modnmetl.virtualrealty.managers.PlotManager;
+import com.modnmetl.virtualrealty.objects.Plot;
+import com.modnmetl.virtualrealty.objects.math.BlockVector2;
import com.modnmetl.virtualrealty.objects.region.Cuboid;
import com.modnmetl.virtualrealty.objects.math.BlockVector3;
import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
public class RegionUtil {
@@ -38,4 +44,25 @@ public static Cuboid getRegion(Location location, Direction direction, int lengt
BlockVector3.at(location2.getBlockX(), location2.getBlockY(), location2.getBlockZ()), location.getWorld());
}
+ public static boolean isCollidingWithBedrock(Cuboid cuboid) {
+ for (Block block : cuboid.getBlocks()) {
+ if (block.getType() == Material.BEDROCK) return true;
+ }
+ return false;
+ }
+
+ public static boolean isCollidingWithAnotherPlot(Cuboid cuboid) {
+ long time = System.currentTimeMillis();
+ for (Plot plot : PlotManager.getPlots(cuboid.getWorld().getName())) {
+ for (BlockVector2 blockVector2 : plot.getCuboid().getFlatRegion()) {
+ if (cuboid.isIn(blockVector2, cuboid.getWorld(), 1)) {
+ VirtualRealty.debug("Collision checked! (Found) " + (System.currentTimeMillis() - time) + " ms | Spacing: 1");
+ return true;
+ }
+ }
+ }
+ VirtualRealty.debug("Collision checked! " + (System.currentTimeMillis() - time) + " ms | Spacing: 1");
+ return false;
+ }
+
}
diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java
index 0d64ab7..90c3cab 100644
--- a/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java
+++ b/src/main/java/com/modnmetl/virtualrealty/utils/data/SchematicUtil.java
@@ -51,7 +51,7 @@ public static LinkedList getStructure(Block block, Block block2) {
}
public static void paste(int plotID) {
- LinkedList blocks = load(plotID);
+ List blocks = load(plotID);
if (blocks == null) return;
Plot plot = PlotManager.getPlot(plotID);
if (plot == null) return;
@@ -145,14 +145,23 @@ public static boolean isPlotFileLegacy(int plotID) throws 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);
+ if (file.exists()) {
+ if (file.delete()) {
+ VirtualRealty.debug("Deleted plot file (" + file.getName() + ")");
+ }
+ }
+ file = new File(VirtualRealty.plotsSchemaFolder, REGION_PREFIX + id + REGION_SUFFIX);
+ if (file.exists()) {
+ if (file.delete()) {
+ VirtualRealty.debug("Deleted plot file (" + file.getName() + ")");
+ }
+ }
+ file = new File(VirtualRealty.plotsSchemaFolder, LEGACY_REGION_PREFIX + id + REGION_SUFFIX);
+ if (file.exists()) {
+ if (file.delete()) {
+ VirtualRealty.debug("Deleted plot file (" + file.getName() + ")");
+ }
+ }
}
public static boolean isOldSerialization(int plotID) {
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index b98223e..b7cea9c 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
+main: com.modnmetl.virtualrealty.VirtualRealty
name: VirtualRealty
version: ${project.version}
-main: com.modnmetl.virtualrealty.VirtualRealty
prefix: Virtual Realty
authors: [ plytki ]
api-version: 1.13
@@ -10,5 +10,4 @@ commands:
virtualrealty:
aliases: [ vrplot, virtualr ]
plot:
- aliases: [ p ]
- test:
\ No newline at end of file
+ aliases: [ p ]
\ No newline at end of file