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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.modnmetl</groupId>
<artifactId>virtualrealty</artifactId>
<version>2.5.6</version>
<version>2.6.0</version>
<packaging>jar</packaging>

<description>A plot creation and management plugin for Minecraft</description>
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.modnmetl.virtualrealty.commands.plot.PlotCommand;
import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand;
import com.modnmetl.virtualrealty.configs.*;
import com.modnmetl.virtualrealty.listener.player.PlayerListener;
import com.modnmetl.virtualrealty.model.plot.PlotSize;
import com.modnmetl.virtualrealty.model.other.ServerVersion;
import com.modnmetl.virtualrealty.exception.MaterialMatchException;
Expand Down Expand Up @@ -46,6 +47,7 @@
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 {

Expand Down Expand Up @@ -149,6 +151,7 @@ public void onEnable() {
loadDynMapHook();
registerCommands();
loadCommandsConfiguration();
updateCommandsConfig();
registerListeners();
registerPlaceholders();
debug("Server version: " + this.getServer().getBukkitVersion() + " | " + this.getServer().getVersion());
Expand Down Expand Up @@ -190,6 +193,43 @@ public void registerPlaceholders() {
debug("Registered new placeholders");
}

private void updateCommandsConfig() {
{
List<String> messages = VirtualRealty.getCommands().plotCommandsHelp.get("plot");
Set<String> subCommands = VirtualRealty.getCommands().plotAliases.getAliasesMap().keySet();
List<String> missingSubCommands = subCommands.stream()
.filter(subCommand -> messages
.stream()
.noneMatch(helpMessage -> helpMessage.contains("%" + subCommand + "_command%"))
).collect(Collectors.toList());
for (String subCommand : missingSubCommands) {
PlotCommand.HELP_LIST.stream()
.filter(helpMessage -> helpMessage.contains("%" + subCommand + "_command%"))
.forEach(messages::add);
}
if (!missingSubCommands.isEmpty()) {
VirtualRealty.getCommands().save();
}
}
{
List<String> messages = VirtualRealty.getCommands().vrplotCommandsHelp.get("vrplot");
Set<String> subCommands = VirtualRealty.getCommands().vrplotAliases.keySet();
List<String> missingSubCommands = subCommands.stream()
.filter(subCommand -> messages
.stream()
.noneMatch(helpMessage -> helpMessage.contains("%" + subCommand + "_command%"))
).collect(Collectors.toList());
for (String subCommand : missingSubCommands) {
VirtualRealtyCommand.HELP_LIST.stream()
.filter(helpMessage -> helpMessage.contains("%" + subCommand + "_command%"))
.forEach(messages::add);
}
if (!missingSubCommands.isEmpty()) {
VirtualRealty.getCommands().save();
}
}
}

public void checkUpdates() {
String[] currentVersionNumbers = this.getDescription().getVersion().split("\\.");
String[] updateCheck = UpdateChecker.getUpdate();
Expand Down Expand Up @@ -332,6 +372,7 @@ public void registerSubCommands(Class<?> mainCommandClass, String... names) {

private void registerListeners() {
new BorderProtectionListener(this);
new PlayerListener(this);
new PlotProtectionListener(this);
new WorldProtectionListener(this);
new PlotEntranceListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,19 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
}
break;
}
case "LEAVE": {
if (args.length == 2) {
String trim = finalArgs[1].trim();
PlotManager.getInstance().getMembershipPlots(player.getUniqueId()).forEach((integer, plot) -> {
if (trim.isEmpty()) {
tabCompleter.add(String.valueOf(plot.getID()));
} else if (String.valueOf(plot.getID()).toLowerCase().startsWith(trim.toLowerCase())) {
tabCompleter.add(String.valueOf(plot.getID()));
}
});
}
return tabCompleter;
}
case "KICK": {
if (args.length == 2) {
PlotManager.getInstance().getAccessPlots(player.getUniqueId()).forEach((integer, plot) -> {
Expand All @@ -422,7 +435,13 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
return tabCompleter;
}
if (args.length == 3) {
Plot plot = PlotManager.getInstance().getPlot(Integer.parseInt(args[1]));
String arg = args[1];
try {
Integer.parseInt(arg.trim());
} catch (NumberFormatException e) {
return tabCompleter;
}
Plot plot = PlotManager.getInstance().getPlot(Integer.parseInt(arg));
if (plot == null) return null;
for (OfflinePlayer offlinePlayer : plot.getPlayerMembers()) {
if (Objects.equals(offlinePlayer.getName(), player.getName())) continue;
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.modnmetl.virtualrealty.commands;

import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand;
import com.modnmetl.virtualrealty.model.other.CommandType;
import com.modnmetl.virtualrealty.exception.FailedCommandException;
import com.modnmetl.virtualrealty.exception.InsufficientPermissionsException;
Expand All @@ -11,12 +10,12 @@
import lombok.Setter;
import lombok.SneakyThrows;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand All @@ -27,7 +26,7 @@ public abstract class SubCommand {
private final String[] args;
private final CommandSender commandSender;
@Getter
public LinkedList<String> HELP_LIST;
public LinkedList<String> helpMessages;
private final boolean bypass;
@Getter
@Setter
Expand All @@ -37,25 +36,25 @@ public abstract class SubCommand {
public SubCommand() {
this.args = null;
this.commandSender = null;
this.HELP_LIST = null;
this.helpMessages = null;
this.bypass = false;
this.alias = null;
}

@SneakyThrows
public SubCommand(CommandSender sender, Command command, String label, String[] args, boolean bypass, LinkedList<String> HELP_LIST) throws FailedCommandException {
public SubCommand(CommandSender sender, Command command, String label, String[] args, boolean bypass, LinkedList<String> helpMessages) throws FailedCommandException {
this.args = args;
this.HELP_LIST = HELP_LIST;
this.helpMessages = helpMessages;
this.commandSender = sender;
this.bypass = bypass;
this.alias = null;
exec(sender, command, label, args);
}

@SneakyThrows
public SubCommand(CommandSender sender, Command command, String label, String[] args, LinkedList<String> HELP_LIST) throws FailedCommandException {
public SubCommand(CommandSender sender, Command command, String label, String[] args, LinkedList<String> helpMessages) throws FailedCommandException {
this.args = args;
this.HELP_LIST = HELP_LIST;
this.helpMessages = helpMessages;
this.commandSender = sender;
this.bypass = false;
this.alias = null;
Expand Down Expand Up @@ -140,7 +139,13 @@ public void printHelp(CommandType commandType) throws FailedCommandException {
}
String subCommandName = getSubCommandName();
String keyByValue = MapUtils.getKeyByValue(commandsAliases, subCommandName);
for (String s : commandsHelp.get(keyByValue)) {
List<String> subCommandHelpMessages = commandsHelp.get(keyByValue);
if (subCommandHelpMessages == null) {
commandsHelp.put(subCommandName, getHelpMessages());
subCommandHelpMessages = getHelpMessages();
VirtualRealty.getCommands().save();
}
for (String s : subCommandHelpMessages) {
String message = s.replaceAll("%command%", subCommandName);
ChatMessage.of(message).send(commandSender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;

public class PlotCommand implements CommandExecutor {

Expand All @@ -28,6 +29,7 @@ public class PlotCommand implements CommandExecutor {
HELP_LIST.add(" §a/plot %gm_command% §8- §7Changes gamemode");
HELP_LIST.add(" §a/plot %add_command% §8- §7Adds a member");
HELP_LIST.add(" §a/plot %kick_command% §8- §7Kicks a member");
HELP_LIST.add(" §a/plot %leave_command% §8- §7Leaves a plot");
HELP_LIST.add(" §a/plot %list_command% §8- §7Shows your plots");
HELP_LIST.add(" §a/plot %tp_command% §8- §7Teleports to the plot");
}
Expand Down Expand Up @@ -81,7 +83,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

private static void printHelp(CommandSender sender) {
for (String message : VirtualRealty.getCommands().plotCommandsHelp.get("plot")) {
final String[] finalMessage = { message };
final String[] finalMessage = {message};
CommandRegistry.PLOT_PLACEHOLDERS.forEach((s, s2) -> {
finalMessage[0] = finalMessage[0].replaceAll(s, s2);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.modnmetl.virtualrealty.commands.plot.subcommand;

import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
import com.modnmetl.virtualrealty.exception.FailedCommandException;
import com.modnmetl.virtualrealty.manager.PlotManager;
import com.modnmetl.virtualrealty.model.other.ChatMessage;
import com.modnmetl.virtualrealty.model.other.CommandType;
import com.modnmetl.virtualrealty.model.permission.ManagementPermission;
import com.modnmetl.virtualrealty.model.plot.Plot;
import com.modnmetl.virtualrealty.model.plot.PlotMember;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.time.LocalDateTime;
import java.util.LinkedList;

public class LeaveSubCommand extends SubCommand {

public static LinkedList<String> HELP = new LinkedList<>();

static {
HELP.add(" ");
HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»");
HELP.add(" §a/plot %command% §8<§7plot§8>");
}

public LeaveSubCommand() {}

public LeaveSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
super(sender, command, label, args, HELP);
}

@Override
public void exec(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
assertPlayer();
Player player = ((Player) sender);
if (args.length < 2) {
printHelp(CommandType.PLOT);
return;
}
int plotID;
try {
plotID = Integer.parseInt(args[1]);
} catch (IllegalArgumentException e) {
ChatMessage.of(VirtualRealty.getMessages().useNaturalNumbersOnly).sendWithPrefix(sender);
return;
}
Plot plot = PlotManager.getInstance().getPlot(plotID);
if (plot == null) {
ChatMessage.of(VirtualRealty.getMessages().noPlotFound).sendWithPrefix(sender);
return;
}
if (!plot.hasMembershipAccess(player.getUniqueId())) {
ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender);
return;
}
PlotMember plotMember = plot.getMember(player.getUniqueId());
if (plot.getOwnedBy().equals(player.getUniqueId())) {
ChatMessage.of(VirtualRealty.getMessages().cantLeaveOwnPlot).sendWithPrefix(sender);
return;
}
plot.removeMember(plotMember);
ChatMessage.of(VirtualRealty.getMessages().plotLeave.replaceAll("%plot_id%", String.valueOf(plot.getID()))).sendWithPrefix(sender);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public void exec(CommandSender sender, Command command, String label, String[] a
ChatMessage.of(VirtualRealty.getMessages().notYourPlot).sendWithPrefix(sender);
return;
}
if (plot.isOwnershipExpired()) {
ChatMessage.of(VirtualRealty.getMessages().ownershipExpired).sendWithPrefix(sender);
return;
}
plot.teleportPlayer(player);
ChatMessage.of(VirtualRealty.getMessages().teleportedToPlot).sendWithPrefix(sender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class CommandsConfiguration extends OkaeriConfig {
public Map<String, LinkedList<String>> vrplotCommandsHelp = getCommandsHelp(CommandType.VRPLOT);



@Names(strategy = NameStrategy.HYPHEN_CASE)
public static class PlotAliases extends OkaeriConfig {

Expand All @@ -37,6 +36,7 @@ public static class PlotAliases extends OkaeriConfig {
public String gm = "gm";
public String info = "info";
public String kick = "kick";
public String leave = "leave";
public String list = "list";
public String tp = "tp";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class MessagesConfiguration extends OkaeriConfig {
public String noPlotFound = "§cCouldn't get plot with specified ID!";
public String notYourPlot = "§cIt's not your plot!";
public String ownershipExpired = "§cYour ownership has expired!";
public String ownershipExpiredJoinMessage = "§cYour %plot_size% plot %plot_id% has expired!";
public String daysUntilExpirationThresholdMessage = "§6Your %plot_size% plot %plot_id% is due to expire in %days% days and %hours% hours," +
" use another plot claim item of the same size type while standing inside it to extend its lease," +
" or it could be claimed by another player after that time!";
public String teleportedToPlot = "§aYou have been teleported to the plot!";
public String gamemodeFeatureDisabled = "§cGamemode feature is disabled!";
public String gamemodeDisabled = "§cThis gamemode is disabled!";
Expand All @@ -84,6 +88,8 @@ public class MessagesConfiguration extends OkaeriConfig {
public String standingOnPlot = "§cYou are standing on a plot!";
public String notStandingOnPlot = "§cYou aren't standing on any plot!";
public String playerKick = "§aPlayer §7%player% §ahas been kicked out of your plot!";
public String plotLeave = "§aYou have left the plot with id %plot_id%!";
public String cantLeaveOwnPlot = "§6You can't leave your own 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!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static class License extends OkaeriConfig {
@CustomKey("default-plot-gamemode")
public String plotGamemode = "SURVIVAL";

@Comment("The number of days before plot expiration when players should be notified")
public int daysUntilExpirationThreshold = 2;

@Comment("Disable natural spawning of all mobs in plots/areas")
public boolean disablePlotMobsSpawn = false;

Expand Down
Loading