Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.plytki</groupId>
<artifactId>VirtualRealty</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<packaging>jar</packaging>

<name>VirtualRealty</name>
Expand Down Expand Up @@ -53,6 +53,9 @@
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>me.plytki.virtualrealty.utils</shadedPattern>
</relocation><relocation>
<pattern>org.apache.commons.io</pattern>
<shadedPattern>me.plytki.virtualrealty.utils</shadedPattern>
</relocation>
<relocation>
<pattern>org.h2</pattern>
Expand Down Expand Up @@ -101,6 +104,10 @@
<id>panda-repository</id>
<url>https://repo.panda-lang.org/</url>
</repository>
<repository>
<id>okaeri-repo</id>
<url>https://storehouse.okaeri.eu/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -135,9 +142,32 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.diorite</groupId>
<artifactId>diorite-config-minimal</artifactId>
<version>1.2</version>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-yaml-bukkit</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-serdes-commons</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-validator-okaeri</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
49 changes: 26 additions & 23 deletions src/main/java/me/plytki/virtualrealty/VirtualRealty.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import me.plytki.virtualrealty.commands.PlotCommand;
import me.plytki.virtualrealty.commands.VirtualRealtyCommand;
import me.plytki.virtualrealty.configs.PluginConfiguration;
import me.plytki.virtualrealty.configs.SizesConfiguration;
import me.plytki.virtualrealty.enums.PlotSize;
import me.plytki.virtualrealty.exceptions.MaterialMatchException;
import me.plytki.virtualrealty.listeners.PlotListener;
import me.plytki.virtualrealty.listeners.PlotProtectionListener;
import me.plytki.virtualrealty.listeners.WorldListener;
import me.plytki.virtualrealty.loaders.PluginConfiguration;
import me.plytki.virtualrealty.loaders.SizesConfiguration;
import me.plytki.virtualrealty.managers.PlotManager;
import me.plytki.virtualrealty.objects.Plot;
import me.plytki.virtualrealty.sql.SQL;
import me.plytki.virtualrealty.tasks.PlotExpireTask;
import me.plytki.virtualrealty.utils.ConfigUtil;
import me.plytki.virtualrealty.utils.ConfigurationFactory;
import me.plytki.virtualrealty.utils.UpdateChecker;
import me.plytki.virtualrealty.utils.multiversion.VMaterial;
import org.apache.commons.io.FileUtils;
Expand All @@ -38,8 +39,8 @@ public final class VirtualRealty extends JavaPlugin {
public static File plotsFolder;
public static File plotsSchemaFolder;

private PluginConfiguration pluginConfiguration;
private SizesConfiguration sizesConfiguration;
public static PluginConfiguration pluginConfiguration;
public static SizesConfiguration sizesConfiguration;
private final File pluginConfigurationFile = new File(this.getDataFolder(), "config.yml");
private final File sizesConfigurationFile = new File(this.getDataFolder(), "sizes.yml");

Expand Down Expand Up @@ -78,14 +79,16 @@ public void onEnable() {
plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain");
plotsSchemaFolder.mkdirs();
try {
this.pluginConfiguration = ConfigUtil.loadConfig(this.pluginConfigurationFile, PluginConfiguration.class);
this.sizesConfiguration = ConfigUtil.loadConfig(this.sizesConfigurationFile, SizesConfiguration.class);
} catch (Exception exception) {
ConfigurationFactory configFactory = new ConfigurationFactory();
pluginConfiguration = configFactory.createPluginConfiguration(pluginConfigurationFile);
sizesConfiguration = configFactory.createSizesConfiguration(sizesConfigurationFile);
}
catch (Exception exception) {
exception.printStackTrace();
configError = true;
this.getServer().getPluginManager().disablePlugin(this);
//shutdown("Critical error has been encountered!");
return;
}

//createSizesConfig();
loadSizesConfiguration();
connectToDatabase();
Expand Down Expand Up @@ -170,36 +173,36 @@ private void connectToDatabase() {
public static void loadSizesConfiguration() {
for (PlotSize plotSize : PlotSize.values()) {
if (plotSize == PlotSize.CUSTOM) return;
SizesConfiguration.Size classSize = null;
SizesConfiguration.PlotSizes.Size classSize = null;
switch (plotSize) {
case SMALL: {
classSize = getInstance().sizesConfiguration.plotSizes.SMALL;
classSize = sizesConfiguration.plotSizes.SMALL;
break;
}
case MEDIUM: {
classSize = getInstance().sizesConfiguration.plotSizes.MEDIUM;
classSize = sizesConfiguration.plotSizes.MEDIUM;
break;
}
case LARGE: {
classSize = getInstance().sizesConfiguration.plotSizes.LARGE;
classSize = sizesConfiguration.plotSizes.LARGE;
break;
}
}
Material floorMaterial;
try {
floorMaterial = VMaterial.getMaterial(classSize.floorMaterial.toUpperCase());
floorMaterial.name();
} catch (Exception e) {
floorMaterial = VMaterial.catchMaterial(classSize.floorMaterial.toUpperCase());
} catch (MaterialMatchException e) {
floorMaterial = VirtualRealty.isLegacy ? Material.GRASS : Material.GRASS_BLOCK;
VirtualRealty.getInstance().getLogger().warning("Couldn't parse floor-material from sizes.yml | Using default: " + (VirtualRealty.isLegacy ? Material.GRASS : Material.GRASS_BLOCK));
e.printStackTrace();
//throw new MaterialMatchException("Couldn't parse floor-material from sizes.yml | Using default: " + (VirtualRealty.isLegacy ? Material.GRASS : Material.GRASS_BLOCK));
}
Material borderMaterial;
try {
borderMaterial = VMaterial.getMaterial(classSize.borderMaterial.toUpperCase());
borderMaterial.name();
} catch (Exception e) {
borderMaterial = VMaterial.catchMaterial(classSize.borderMaterial.toUpperCase());
} catch (MaterialMatchException e) {
borderMaterial = VirtualRealty.isLegacy ? Material.getMaterial("STEP") : Material.STONE_BRICK_SLAB;
VirtualRealty.getInstance().getLogger().warning("Couldn't parse border-material from sizes.yml | Using default: " + (VirtualRealty.isLegacy ? Material.getMaterial("STEP") : Material.STONE_BRICK_SLAB));
e.printStackTrace();
//throw new MaterialMatchException("Couldn't parse border-material from sizes.yml | Using default: " + (VirtualRealty.isLegacy ? Material.getMaterial("STEP") : Material.STONE_BRICK_SLAB));
}
plotSize.setFloorMaterial(floorMaterial);
plotSize.setFloorData(classSize.floorData);
Expand All @@ -216,7 +219,7 @@ public static VirtualRealty getInstance() {
}

public static PluginConfiguration getPluginConfiguration() {
return getInstance().pluginConfiguration;
return pluginConfiguration;
}

public boolean checkLegacyVersions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.plytki.virtualrealty.VirtualRealty;
import me.plytki.virtualrealty.enums.Direction;
import me.plytki.virtualrealty.enums.PlotSize;
import me.plytki.virtualrealty.exceptions.MaterialMatchException;
import me.plytki.virtualrealty.managers.PlotManager;
import me.plytki.virtualrealty.objects.Plot;
import me.plytki.virtualrealty.utils.Permissions;
Expand Down Expand Up @@ -169,7 +170,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
case "CREATE": {
if (!Permissions.hasPermission(sender, commandPermission, "create")) return false;
if (sender instanceof Player) {
if (args.length == 2 || args.length == 3) {
if ((args.length == 2 || args.length == 3) && !args[1].equalsIgnoreCase("custom")) {
PlotSize plotSize = null;
try {
plotSize = PlotSize.valueOf(args[1].toUpperCase());
Expand All @@ -193,16 +194,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
sender.sendMessage(VirtualRealty.PREFIX + "§aNot colliding. Creating plot..");
long timeStart = System.currentTimeMillis();
PlotManager.createPlot(location, plotSize, material);
Plot plot = PlotManager.createPlot(location, plotSize, material);
long timeEnd = System.currentTimeMillis();
sender.sendMessage(VirtualRealty.PREFIX + "§aPlot created! §8(§7" + (timeEnd - timeStart) + " ms§8)");
BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aPlot ");
BaseComponent textComponent2 = new TextComponent("§8#§7" + plot.getID());
BaseComponent textComponent3 = new TextComponent(" §acreated! §8(§7" + (timeEnd - timeStart) + " ms§8)");
textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick to show detailed information about the plot! §8(§7ID: §f" + plot.getID() + "§8)")}));
textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
new Chat(textComponent, textComponent2, textComponent3).sendTo(p);
}
} else {
sender.sendMessage(VirtualRealty.PREFIX + "§cSize not recognized!");
return false;
}
} else {
PlotSize plotSize = PlotSize.CUSTOM;
int length;
int width;
int height;
Expand All @@ -222,7 +227,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage(VirtualRealty.PREFIX + "§cYou cant create new plot on the existing plot!");
return false;
} else {
Material material = Material.GRASS;
Material material = Material.matchMaterial(VirtualRealty.isLegacy ? "GRASS" : "GRASS_BLOCK");
if (args.length >= 5) {
try {
//String[] materialText = Arrays.copyOfRange(args, 5, args.length);
Expand All @@ -234,9 +239,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
sender.sendMessage(VirtualRealty.PREFIX + "§aNot colliding. Creating plot..");
long timeStart = System.currentTimeMillis();
PlotManager.createPlot(location, length, width, height, material);
Plot plot = PlotManager.createPlot(location, length, width, height, material);
long timeEnd = System.currentTimeMillis();
sender.sendMessage(VirtualRealty.PREFIX + "§aPlot created! §8(§7" + (timeEnd - timeStart) + " ms§8)");
BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + "§aPlot ");
BaseComponent textComponent2 = new TextComponent("§8#§7" + plot.getID());
BaseComponent textComponent3 = new TextComponent(" §acreated! §8(§7" + (timeEnd - timeStart) + " ms§8)");
textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§a§oClick to show detailed information about the plot! §8(§7ID: §f" + plot.getID() + "§8)")}));
textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/vrplot info " + plot.getID()));
new Chat(textComponent, textComponent2, textComponent3).sendTo(p);
}
}
}
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package me.plytki.virtualrealty.configs;

import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.*;
import me.plytki.virtualrealty.VirtualRealty;
import org.bukkit.GameMode;


@Header("################################################################")
@Header("# #")
@Header("# Virtual Realty #")
@Header("# #")
@Header("################################################################")
@Names(strategy = NameStrategy.IDENTITY, modifier = NameModifier.TO_LOWER_CASE)
public class PluginConfiguration extends OkaeriConfig {

@Comment(" ")
@Comment("-------------------------")
@Comment("Don't change this value!")
@CustomKey("config-version")
public String configVersion = VirtualRealty.getInstance().getDescription().getVersion();

@Comment("-------------------------")
@Comment("Set player gamemode to change when they enter their plot")
@CustomKey("enable-plot-gamemode")
public boolean enablePlotGameMode = false;

@Comment("Set which gamemode players change to when they enter their plot")
@CustomKey("default-plot-gamemode")
public String plotGameMode = "SURVIVAL";

@Comment("Set forced change to plot gamemode when players enter their plot")
@CustomKey("force-plot-gamemode")
public boolean forcePlotGameMode = false;

public GameMode getGameMode() {
try {
return GameMode.valueOf(plotGameMode);
} catch (Exception e) {
VirtualRealty.getInstance().getLogger().warning("Couldn't parse plot-gamemode from config.yml\nUsing default: SURVIVAL");
return GameMode.SURVIVAL;
}
}

@Comment("Allow players to build outside of their plots")
@CustomKey("allow-outplot-build")
public boolean allowOutPlotBuild = true;

@Comment("Type of data recording")
@Comment("H2 - Local database (Automatically started with our plugin)")
@Comment("MYSQL - External database")
@CustomKey("data-model")
public DataModel dataModel = DataModel.H2;

@Comment("Data required to connect to the database")
@Comment("The plotsTableName section is the name of the VR data table in the database")
@Comment("It is best to change these names only if you really need to (e.g. there is a conflict with another plugin)")
@Comment("To rename tables when you already have some VR data in the database:")
@Comment("1. Turn off the server")
@Comment("2. Change data in VR config")
@Comment("3. Rename database tables using phpMyAdmin for example")
@CustomKey("mysql")
public MySQL mysql = new MySQL("localhost", 3306, "db", "root", "passwd", true, "vr_plots");


public enum DataModel {
H2,
MYSQL
}

@Names(strategy = NameStrategy.IDENTITY)
public static class MySQL extends OkaeriConfig {

@Variable("VR_MYSQL_HOSTNAME")
public String hostname;
@Variable("VR_MYSQL_PORT")
public int port;
@Variable("VR_MYSQL_DATABASE")
public String database;
@Variable("VR_MYSQL_USER")
public String user;
@Variable("VR_MYSQL_PASSWORD")
public String password;
@Variable("VR_MYSQL_USE_SSL")
public boolean useSSL;
@Variable("VR_MYSQL_USERS_TABLE_NAME")
public String plotsTableName;

public MySQL() {
}

public MySQL(String hostname, int port, String database, String user, String password, boolean useSSL, String plotsTableName) {
this.hostname = hostname;
this.port = port;
this.database = database;
this.user = user;
this.password = password;
this.useSSL = useSSL;
this.plotsTableName = plotsTableName;
}
}

}
Loading