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
13 changes: 2 additions & 11 deletions src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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.listeners.stake.ConfirmationListener;
import com.modnmetl.virtualrealty.managers.DynmapManager;
import com.modnmetl.virtualrealty.managers.MetricsManager;
import com.modnmetl.virtualrealty.managers.PlotManager;
Expand All @@ -24,13 +24,11 @@
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 lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand All @@ -41,20 +39,13 @@

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.URI;
import java.net.URISyntaxException;
import java.net.URL;
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 {

Expand Down Expand Up @@ -266,7 +257,7 @@ private void registerListeners() {
new PlotEntranceListener(this);
new PlayerActionListener(this);
new DraftListener(this);
new StakeConfirmationListener(this);
new ConfirmationListener(this);
try {
List<Class<?>> classes = new ArrayList<>();
classes.add(Class.forName("com.modnmetl.virtualrealty.listeners.premium.PanelListener", true, getLoader()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,30 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
} else if (args.length < 6) {
switch (args.length) {
case 3: {
tabCompleter.add(String.valueOf(plotSize.getLength()));
String length = String.valueOf(plotSize.getLength());
if (args[args.length - 1].isEmpty()) {
tabCompleter.add(length.toLowerCase());
} else if (length.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
tabCompleter.add(length.toLowerCase());
}
break;
}
case 4: {
tabCompleter.add(String.valueOf(plotSize.getHeight()));
String height = String.valueOf(plotSize.getHeight());
if (args[args.length - 1].isEmpty()) {
tabCompleter.add(height.toLowerCase());
} else if (height.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
tabCompleter.add(height.toLowerCase());
}
break;
}
case 5: {
tabCompleter.add(String.valueOf(plotSize.getWidth()));
String width = String.valueOf(plotSize.getWidth());
if (args[args.length - 1].isEmpty()) {
tabCompleter.add(width.toLowerCase());
} else if (width.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
tabCompleter.add(width.toLowerCase());
}
break;
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@ public abstract class SubCommand {
private final String[] args;
private final CommandSender commandSender;
private final LinkedList<String> helpList;
private final boolean bypass;

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

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

Expand Down Expand Up @@ -62,6 +73,10 @@ public void assertPermission(String permission) throws InsufficientPermissionsEx
}
}

public boolean isBypass() {
return this.bypass;
}

public void printHelp() throws FailedCommandException {
for (String s : helpList) {
commandSender.sendMessage(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ public class PlotCommand implements CommandExecutor {

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
boolean displayError = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--error"));
args = Arrays.stream(args).filter(s1 -> !s1.equalsIgnoreCase("--error")).toArray(String[]::new);
boolean displayError = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--error") || s.equalsIgnoreCase("-e"));
boolean bypass = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--yes") || s.equalsIgnoreCase("-y"));
args = Arrays.stream(args).filter(s1 ->
!s1.equalsIgnoreCase("--error") &&
!s1.equalsIgnoreCase("--yes") &&
!s1.equalsIgnoreCase("-e") &&
!s1.equalsIgnoreCase("-y"))
.toArray(String[]::new);
if ((args.length > 0 && args[0].equalsIgnoreCase("help")) || args.length == 0) {
printHelp(sender);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AddSubCommand extends SubCommand {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,38 @@

import com.modnmetl.virtualrealty.VirtualRealty;
import com.modnmetl.virtualrealty.commands.SubCommand;
import com.modnmetl.virtualrealty.enums.ConfirmationType;
import com.modnmetl.virtualrealty.enums.Direction;
import com.modnmetl.virtualrealty.enums.PlotSize;
import com.modnmetl.virtualrealty.exceptions.FailedCommandException;
import com.modnmetl.virtualrealty.listeners.stake.DraftListener;
import com.modnmetl.virtualrealty.managers.ConfirmationManager;
import com.modnmetl.virtualrealty.managers.PlotManager;
import com.modnmetl.virtualrealty.objects.Plot;
import com.modnmetl.virtualrealty.objects.data.Confirmation;
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 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.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import java.time.LocalDateTime;
import java.util.*;

public class StakeSubCommand extends SubCommand {

public static Set<UUID> stakeConfirmations = new HashSet<>();

public StakeSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException {
super(sender, command, label, args, new LinkedList<>());
}
Expand All @@ -45,10 +60,78 @@ public void exec(CommandSender sender, Command command, String label, String[] a
player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision);
return;
}
stakeConfirmations.add(player.getUniqueId());
for (String s : VirtualRealty.getMessages().stakeConfirmation) {
sender.sendMessage(VirtualRealty.PREFIX + s);
}
Confirmation confirmation = new Confirmation(ConfirmationType.STAKE, (Player) sender, "YES") {
@Override
public void success() {
GridStructure gridStructure = DraftListener.DRAFT_MAP.get(this.getSender()).getKey();
PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey();
PlotSize plotSize = plotItem.getPlotSize();
ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack();
NBTItem item = new NBTItem(plotItemStack);
gridStructure.removeGrid();
this.getSender().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<String, Byte> floorData = new AbstractMap.SimpleEntry<>(item.getString("vrplot_floor_material"), item.getByte("vrplot_floor_data"));
AbstractMap.SimpleEntry<String, Byte> 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(this.getSender().getUniqueId());
if (plotItem.getAdditionalDays() == 0) {
plot.setOwnedUntilDate(Plot.MAX_DATE);
} else {
plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays()));
}
this.getSender().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(this.getSender());
new BukkitRunnable() {
@Override
public void run() {
gridStructure.setCuboidId(plot.getID());
gridStructure.setDisplayTicks(20 * 6);
gridStructure.preview(true, false);
}
}.runTaskLater(VirtualRealty.getInstance(), 20);
DraftListener.DRAFT_MAP.remove(this.getSender());
ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId());
}

@Override
public void failed() {
this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack());
this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack());
this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack());
DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid();
DraftListener.DRAFT_MAP.remove(this.getSender());
this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled);
DraftListener.DRAFT_MAP.remove(this.getSender());
ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId());
}

@Override
public void expiry() {
ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId());
}
};
ConfirmationManager.confirmations.add(confirmation);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.permissions.Permission;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.logging.Level;
Expand Down Expand Up @@ -37,8 +38,14 @@ public class VirtualRealtyCommand implements CommandExecutor {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
boolean displayError = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--error"));
args = Arrays.stream(args).filter(s1 -> !s1.equalsIgnoreCase("--error")).toArray(String[]::new);
boolean displayError = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--error") || s.equalsIgnoreCase("-e"));
boolean bypass = Arrays.stream(args).anyMatch(s -> s.equalsIgnoreCase("--yes") || s.equalsIgnoreCase("-y"));
args = Arrays.stream(args).filter(s1 ->
!s1.equalsIgnoreCase("--error") &&
!s1.equalsIgnoreCase("--yes") &&
!s1.equalsIgnoreCase("-e") &&
!s1.equalsIgnoreCase("-y"))
.toArray(String[]::new);
if (!sender.hasPermission(COMMAND_PERMISSION)) {
sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().insufficientPermissions.replaceAll("%permission%", COMMAND_PERMISSION.getName()));
return false;
Expand All @@ -48,8 +55,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
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.getLoader());
clazz.getConstructors()[0].newInstance(sender, command, label, args);
Class<?> clazz = Class.forName("com.modnmetl.virtualrealty.commands.vrplot.subcommand." + String.valueOf(args[0].toCharArray()[0]).toUpperCase() + args[0].substring(1) + "SubCommand", true, VirtualRealty.getLoader());
if (bypass) {
clazz.getConstructors()[1].newInstance(sender, command, label, args, true);
} else {
clazz.getConstructors()[0].newInstance(sender, command, label, args);
}
} catch (Exception e) {
if(!(e instanceof InvocationTargetException)) {
printHelp(sender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class AssignSubCommand extends SubCommand {
HELP.add(" §a/vrplot assign §8<§7plot§8> §8<§7username§8>");
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.*;

public class CreateSubCommand extends SubCommand {

Expand Down Expand Up @@ -77,10 +76,6 @@ public void exec(CommandSender sender, Command command, String label, String[] a
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);
Expand Down
Loading