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
12 changes: 11 additions & 1 deletion 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.6.0</version>
<version>1.6.1</version>
<packaging>jar</packaging>

<name>VirtualRealty</name>
Expand Down Expand Up @@ -111,6 +111,10 @@
<id>dynmap-repo</id>
<url>http://repo.mikeprimm.com/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -177,6 +181,12 @@
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
31 changes: 28 additions & 3 deletions src/main/java/me/plytki/virtualrealty/VirtualRealty.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -94,6 +95,7 @@ public void onEnable() {
plotsSchemaFolder = new File(plotsFolder.getAbsolutePath(), "primary-terrain");
plotsSchemaFolder.mkdirs();
spawnLocales();
reformatConfig();
reloadConfigs();
registerMetrics();
loadSizesConfiguration();
Expand All @@ -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());
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<String> 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;
Expand Down
34 changes: 12 additions & 22 deletions src/main/java/me/plytki/virtualrealty/commands/PlotCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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!";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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());
}
}
}
}
Expand All @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/me/plytki/virtualrealty/objects/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
* <br>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.
* <br>This is what tells PlaceholderAPI to call our onRequest
* method to obtain a value if a placeholder starts with our
* identifier.
* <br>The identifier has to be lowercase and can't contain _ or %
*
* @return The identifier in {@code %<identifier>_<value>%} as String.
*/
@Override
public String getIdentifier(){
return "virtualrealty";
}

/**
* This is the version of the expansion.
* <br>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.
* <br>We specify the value identifier in this method.
* <br>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;
}

}
Loading