diff --git a/pom.xml b/pom.xml
index ce7bb77..56c6833 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.plytki
VirtualRealty
- 1.6.0
+ 1.6.1
jar
VirtualRealty
@@ -111,6 +111,10 @@
dynmap-repo
http://repo.mikeprimm.com/
+
+ placeholderapi
+ http://repo.extendedclip.com/content/repositories/placeholderapi/
+
@@ -177,6 +181,12 @@
2.0
provided
+
+ me.clip
+ placeholderapi
+ 2.10.9
+ provided
+
diff --git a/src/main/java/me/plytki/virtualrealty/VirtualRealty.java b/src/main/java/me/plytki/virtualrealty/VirtualRealty.java
index 86fcbd9..2d2f15c 100644
--- a/src/main/java/me/plytki/virtualrealty/VirtualRealty.java
+++ b/src/main/java/me/plytki/virtualrealty/VirtualRealty.java
@@ -13,8 +13,8 @@
import me.plytki.virtualrealty.listeners.world.WorldListener;
import me.plytki.virtualrealty.managers.PlotManager;
import me.plytki.virtualrealty.objects.Plot;
+import me.plytki.virtualrealty.registry.VirtualPlaceholders;
import me.plytki.virtualrealty.sql.SQL;
-import me.plytki.virtualrealty.tasks.PlotExpireTask;
import me.plytki.virtualrealty.utils.ConfigurationFactory;
import me.plytki.virtualrealty.utils.SchematicUtil;
import me.plytki.virtualrealty.utils.UpdateChecker;
@@ -35,6 +35,7 @@
import org.dynmap.markers.MarkerSet;
import java.io.*;
+import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.Callable;
@@ -94,6 +95,7 @@ public void onEnable() {
plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain");
plotsSchemaFolder.mkdirs();
spawnLocales();
+ reformatConfig();
reloadConfigs();
registerMetrics();
loadSizesConfiguration();
@@ -106,6 +108,10 @@ public void onEnable() {
registerListeners();
registerTasks();
checkForOldSchemas();
+ if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){
+ new VirtualPlaceholders(this).register();
+ debug("Registered new placeholders");
+ }
debug("Server version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion());
}
@@ -224,8 +230,7 @@ private void registerListeners() {
}
private void registerTasks() {
- tasks.add(new PlotExpireTask().runTaskTimer(this, 20 * 30, 20 * 30));
- debug("Registered tasks");
+ //debug("Registered tasks");
}
private void registerMetrics() {
@@ -368,6 +373,26 @@ public void setPostVersions() {
postVersions.add("1.13");
}
+ public void reformatConfig() {
+ File configFile = new File(this.getDataFolder(), "config.yml");
+ File newFile = new File(this.getDataFolder(), "config.yml");
+ if (configFile.exists()) {
+ try {
+ List lines = FileUtils.readLines(configFile, StandardCharsets.UTF_8);
+ for (int i = 0; i < lines.size(); i++) {
+ if (lines.get(i).startsWith("force-plot-gamemode:")) {
+ lines.set(i, lines.get(i).replaceAll("force-plot-gamemode:", "lock-plot-gamemode:"));
+ }
+ }
+ FileUtils.writeLines(newFile, lines);
+ FileUtils.deleteQuietly(configFile);
+ newFile.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
public void checkConfig() throws IOException {
File oldConfigFile = new File(this.getDataFolder(), "config.yml");
if (!oldConfigFile.exists()) return;
diff --git a/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java b/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java
index f6a15e6..71946d2 100644
--- a/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java
+++ b/src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java
@@ -256,7 +256,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
break;
}
case "GM": {
- if (!VirtualRealty.getPluginConfiguration().enablePlotGameMode || VirtualRealty.getPluginConfiguration().forcePlotGameMode) {
+ if (VirtualRealty.getPluginConfiguration().lockPlotGameMode) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeFeatureDisabled);
return false;
}
@@ -273,41 +273,31 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return false;
}
}
- if (!(gameModeID != 1 && gameModeID != 2)) {
+ GameMode defaultGamemode = VirtualRealty.getInstance().getServer().getDefaultGameMode();
+ GameMode configGamemode = VirtualRealty.getPluginConfiguration().getGameMode();
+ if (!(gameModeID != configGamemode.getValue() && gameModeID != defaultGamemode.getValue())) {
gameMode = GameMode.getByValue(Integer.parseInt(args[1]));
} else {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeDisabled);
return false;
}
-
Plot plot = PlotManager.getBorderedPlot(p.getLocation());
if (plot != null) {
- if (plot.getOwnedBy() == null || (plot.getOwnedBy() != null && !plot.getOwnedBy().equals(p.getUniqueId()))) {
- if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
- return false;
- }
+ if (!plot.hasPlotMembership(p)) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().cantSwitchGamemode);
} else {
- if (plot.getOwnedUntilDate().isBefore(LocalDateTime.now())) {
+ if (plot.isOwnershipExpired()) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().ownershipExpired);
} else {
- if (plot.getSelectedGameMode().equals(gameMode)) {
- if (plot.getSelectedGameMode().equals(GameMode.CREATIVE)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeIsEnabled);
- } else {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeIsDisabled);
- }
+ if (p.getGameMode().equals(gameMode)) {
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeAlreadySelected);
return false;
}
- plot.setSelectedGameMode(gameMode);
- p.setGameMode(plot.getSelectedGameMode());
- if (plot.getSelectedGameMode().equals(GameMode.CREATIVE)) {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeEnabled);
- } else {
- sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().creativeDisabled);
+ if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(p.getUniqueId())) {
+ plot.setSelectedGameMode(gameMode);
}
-
+ p.setGameMode(gameMode);
+ sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().gamemodeSwitched);
}
}
} else {
diff --git a/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java
index 1b1d881..cdfa228 100644
--- a/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java
+++ b/src/main/java/me/plytki/virtualrealty/configs/MessagesConfiguration.java
@@ -13,10 +13,6 @@ public class MessagesConfiguration extends OkaeriConfig {
public String incorrectGamemode = "§cIncorrect gamemode value!";
public String gamemodeDisabled = "§cThis gamemode is disabled!";
public String cantSwitchGamemode = "§cYou can't switch gamemode here!";
- public String creativeIsEnabled = "§cPlot Creative-Mode is already enabled!";
- public String creativeIsDisabled = "§cPlot Creative-Mode is already disabled!";
- public String creativeEnabled = "§aPlot Creative-Mode has been enabled!";
- public String creativeDisabled = "§ePlot Creative-Mode has been disabled!";
public String notStandingOnPlot = "§cYou aren't standing on any plot!";
public String assignedByConsole = "§eConsole";
public String assignedByShopPurchase = "§eShop Purchase";
@@ -67,5 +63,7 @@ public class MessagesConfiguration extends OkaeriConfig {
public String cantDoAnyDMG = "§cYou can't do any damage here!";
public String playerKick = "§aPlayer §7%player% §ahas been kicked out of your plot!";
public String playerAdd = "§aPlayer §7%player% §ahas been added to your plot!";
+ public String gamemodeSwitched = "§aYour gamemode has changed!";
+ public String gamemodeAlreadySelected = "§cThis gamemode is already selected!";
}
diff --git a/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java b/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java
index 96ca40d..d8043a7 100644
--- a/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java
+++ b/src/main/java/me/plytki/virtualrealty/configs/PluginConfiguration.java
@@ -36,9 +36,9 @@ public class PluginConfiguration extends OkaeriConfig {
@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;
+ @Comment("Lock gamemode to plot default when player enters their plot (disables '/plot gm' command)")
+ @CustomKey("lock-plot-gamemode")
+ public boolean lockPlotGameMode = false;
public GameMode getGameMode() {
try {
diff --git a/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java b/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java
index 6d8bdaa..6d7e24a 100644
--- a/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java
+++ b/src/main/java/me/plytki/virtualrealty/listeners/plot/PlotListener.java
@@ -40,12 +40,13 @@ public void onPlotMove(PlayerMoveEvent e) {
if (!enteredPlot.containsKey(player)) {
enteredPlot.put(player, new AbstractMap.SimpleEntry<>(plot, true));
if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) {
- if (plot.getOwnedBy() != null && plot.getOwnedBy().equals(player.getUniqueId())) {
- if (VirtualRealty.getPluginConfiguration().forcePlotGameMode) {
- player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode());
- } else {
- player.setGameMode(plot.getSelectedGameMode());
+ if (plot.getOwnedBy().equals(player.getUniqueId())) {
+ if (plot.getSelectedGameMode() != VirtualRealty.getInstance().getServer().getDefaultGameMode() || plot.getSelectedGameMode() != VirtualRealty.getPluginConfiguration().getGameMode()) {
+ plot.setSelectedGameMode(VirtualRealty.getPluginConfiguration().getGameMode());
}
+ player.setGameMode(plot.getSelectedGameMode());
+ } else if (plot.getMembers().contains(player.getUniqueId())) {
+ player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode());
}
}
if (!VirtualRealty.getInstance().getServer().getBukkitVersion().startsWith("1.8")) {
@@ -60,11 +61,7 @@ public void onPlotMove(PlayerMoveEvent e) {
if (!enteredPlot.get(player).getValue()) {
enteredPlot.replace(player, new AbstractMap.SimpleEntry<>(plot, true));
if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) {
- if (VirtualRealty.getPluginConfiguration().forcePlotGameMode) {
player.setGameMode(VirtualRealty.getPluginConfiguration().getGameMode());
- } else {
- player.setGameMode(plot.getSelectedGameMode());
- }
}
}
}
@@ -77,7 +74,7 @@ public void onPlotMove(PlayerMoveEvent e) {
offlinePlayer = Bukkit.getOfflinePlayer(enteredPlot.get(player).getKey().getOwnedBy());
leavePlotString = VirtualRealty.getMessages().leftOwnedPlot.replaceAll("%owner%", offlinePlayer.getName());
if (VirtualRealty.getPluginConfiguration().enablePlotGameMode) {
- if (enteredPlot.get(player).getKey().getOwnedBy() != null && enteredPlot.get(player).getKey().getOwnedBy().equals(player.getUniqueId())) {
+ if (enteredPlot.get(player).getKey().hasPlotMembership(player)) {
player.setGameMode(Bukkit.getServer().getDefaultGameMode());
}
}
diff --git a/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java b/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java
index d5f2b8f..325cc46 100644
--- a/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java
+++ b/src/main/java/me/plytki/virtualrealty/managers/PlotManager.java
@@ -176,7 +176,6 @@ public static void resetPlotMarker(Plot plot) {
marker.setFillStyle(opacity, color);
marker.setLineStyle(2, 0.8, 0x474747);
marker.setMarkerSet(VirtualRealty.markerset);
- //VirtualRealty.markerset.createMarker(String.valueOf(plot.getID()), ownedBy, plot.getCreatedWorld(), plot.getCenter().getBlockX(), plot.getCenter().getBlockY(), plot.getCenter().getBlockZ(), VirtualRealty.markerIcon, true);
}
public static void removeDynMapMarker(Plot plot) {
diff --git a/src/main/java/me/plytki/virtualrealty/objects/Plot.java b/src/main/java/me/plytki/virtualrealty/objects/Plot.java
index ab1c982..6fc1233 100644
--- a/src/main/java/me/plytki/virtualrealty/objects/Plot.java
+++ b/src/main/java/me/plytki/virtualrealty/objects/Plot.java
@@ -152,6 +152,11 @@ public boolean hasPermissionToPlot(Player player) {
return ownedBy != null && ownedBy.equals(player.getUniqueId());
}
+ public boolean hasPlotMembership(Player player) {
+ if (members.contains(player.getUniqueId())) return true;
+ return ownedBy != null && ownedBy.equals(player.getUniqueId());
+ }
+
public boolean isOwnershipExpired() {
return ownedUntilDate.isBefore(LocalDateTime.now());
}
diff --git a/src/main/java/me/plytki/virtualrealty/registry/VirtualPlaceholders.java b/src/main/java/me/plytki/virtualrealty/registry/VirtualPlaceholders.java
new file mode 100644
index 0000000..3d86be8
--- /dev/null
+++ b/src/main/java/me/plytki/virtualrealty/registry/VirtualPlaceholders.java
@@ -0,0 +1,123 @@
+package me.plytki.virtualrealty.registry;
+
+import me.clip.placeholderapi.expansion.PlaceholderExpansion;
+import me.plytki.virtualrealty.VirtualRealty;
+import me.plytki.virtualrealty.managers.PlotManager;
+import me.plytki.virtualrealty.objects.Plot;
+import org.bukkit.entity.Player;
+
+public class VirtualPlaceholders extends PlaceholderExpansion {
+
+ private final VirtualRealty plugin;
+
+ /**
+ * Since we register the expansion inside our own plugin, we
+ * can simply use this method here to get an instance of our
+ * plugin.
+ *
+ * @param plugin
+ * The instance of our plugin.
+ */
+ public VirtualPlaceholders(VirtualRealty plugin){
+ this.plugin = plugin;
+ }
+
+ /**
+ * Because this is an internal class,
+ * you must override this method to let PlaceholderAPI know to not unregister your expansion class when
+ * PlaceholderAPI is reloaded
+ *
+ * @return true to persist through reloads
+ */
+ @Override
+ public boolean persist(){
+ return true;
+ }
+
+ /**
+ * Because this is a internal class, this check is not needed
+ * and we can simply return {@code true}
+ *
+ * @return Always true since it's an internal class.
+ */
+ @Override
+ public boolean canRegister(){
+ return true;
+ }
+
+ /**
+ * The name of the person who created this expansion should go here.
+ *
For convienience do we return the author from the plugin.yml
+ *
+ * @return The name of the author as a String.
+ */
+ @Override
+ public String getAuthor(){
+ return plugin.getDescription().getAuthors().toString();
+ }
+
+ /**
+ * The placeholder identifier should go here.
+ *
This is what tells PlaceholderAPI to call our onRequest
+ * method to obtain a value if a placeholder starts with our
+ * identifier.
+ *
The identifier has to be lowercase and can't contain _ or %
+ *
+ * @return The identifier in {@code %_%} as String.
+ */
+ @Override
+ public String getIdentifier(){
+ return "virtualrealty";
+ }
+
+ /**
+ * This is the version of the expansion.
+ *
You don't have to use numbers, since it is set as a String.
+ *
+ * For convienience do we return the version from the plugin.yml
+ *
+ * @return The version as a String.
+ */
+ @Override
+ public String getVersion(){
+ return plugin.getDescription().getVersion();
+ }
+
+ /**
+ * This is the method called when a placeholder with our identifier
+ * is found and needs a value.
+ *
We specify the value identifier in this method.
+ *
Since version 2.9.1 can you use OfflinePlayers in your requests.
+ *
+ * @param player
+ * A {@link org.bukkit.entity.Player Player}.
+ * @param identifier
+ * A String containing the identifier/value.
+ *
+ * @return possibly-null String of the requested identifier.
+ */
+ @Override
+ public String onPlaceholderRequest(Player player, String identifier){
+ if(player == null)
+ return "";
+
+ Plot plot = PlotManager.getBorderedPlot(player.getLocation());
+ if (identifier.equals("plot_id")) {
+ if (plot == null) return "";
+ return String.valueOf(plot.getID());
+ }
+ if (identifier.equals("plot_owner")) {
+ if (plot == null) return "";
+ if (plot.getOwnedBy() == null) return "";
+ return String.valueOf(plot.getPlotOwner().getName());
+ }
+ if (identifier.equals("is_plot_owner")) {
+ if (plot == null) return "";
+ if (plot.getOwnedBy() == null) return "false";
+ if (plot.getOwnedBy().equals(player.getUniqueId())) return "true";
+ return "false";
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/me/plytki/virtualrealty/tasks/PlotExpireTask.java b/src/main/java/me/plytki/virtualrealty/tasks/PlotExpireTask.java
deleted file mode 100644
index 73dd498..0000000
--- a/src/main/java/me/plytki/virtualrealty/tasks/PlotExpireTask.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package me.plytki.virtualrealty.tasks;
-
-import me.plytki.virtualrealty.managers.PlotManager;
-import me.plytki.virtualrealty.objects.Plot;
-import org.bukkit.Bukkit;
-import org.bukkit.scheduler.BukkitRunnable;
-
-import java.time.LocalDateTime;
-
-public class PlotExpireTask extends BukkitRunnable {
-
- @Override
- public void run() {
- Bukkit.getOnlinePlayers().forEach(player -> {
-
- });
- }
-
-}
diff --git a/src/main/resources/messages_es_ES.yml b/src/main/resources/messages_es_ES.yml
index b941110..f50e1ff 100644
--- a/src/main/resources/messages_es_ES.yml
+++ b/src/main/resources/messages_es_ES.yml
@@ -57,4 +57,6 @@ alreadyInMembers: §c¡Este jugador ya es miembro de la parcela!
notInMembers: §c¡Este jugador no es miembro de la parcela!
cantDoAnyDMG: §c¡No puedes hacer daño aquí!
playerKick: §a¡El jugador §7%player% §aha sido expulsado de tu parcela!
-playerAdd: §a¡El jugador §7%player% §aha sido añadido a tu parcela!
\ No newline at end of file
+playerAdd: §a¡El jugador §7%player% §aha sido añadido a tu parcela!
+gamemodeSwitched: §aEl modo de juego ya está seleccionado.
+gamemodeAlreadySelected: §cEste modo de juego ya está seleccionado.
\ No newline at end of file
diff --git a/src/main/resources/messages_pl_PL.yml b/src/main/resources/messages_pl_PL.yml
index a5cc46a..e18e3b0 100644
--- a/src/main/resources/messages_pl_PL.yml
+++ b/src/main/resources/messages_pl_PL.yml
@@ -60,3 +60,5 @@ notInMembers: §cTen gracz nie jest członkiem twojej działki!
cantDoAnyDMG: §cNie możesz tutaj zdawać żadnych obrażeń!
playerKick: §aGracz §7%player% §azostał wyrzucony z działki!
playerAdd: §aGracz §7%player% §azostał dodany do działki!
+gamemodeSwitched: §aTwój tryb gry się zmienił!
+gamemodeAlreadySelected: §cTen tryb gry jest już wybrany!
\ No newline at end of file