From 41052b27a08d4f6781196f070bbaa575afa4e47f Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Tue, 13 Aug 2019 21:57:49 +0200 Subject: [PATCH] I have some random ideas sometimes - Adjusting some RequiredTypes fitting their partners/default behavior - A plot doesn't need to be claimed to get the center - Adapting another gamemode acronym - Fix copyFile to adapt the latest changes - Removing HastebinUtility, we have our own paste service --- .../plotsquared/plot/PlotSquared.java | 2 +- .../plotsquared/plot/commands/Leave.java | 2 +- .../plotsquared/plot/commands/Middle.java | 5 +- .../plotsquared/plot/commands/Relight.java | 2 +- .../plotsquared/plot/commands/Remove.java | 2 +- .../plotsquared/plot/commands/SetHome.java | 2 +- .../plotsquared/plot/flag/GameModeFlag.java | 1 + .../plot/util/HastebinUtility.java | 70 ------------------- 8 files changed, 7 insertions(+), 79 deletions(-) delete mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 2f8fc8235..31c7710c2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -251,12 +251,12 @@ import java.util.zip.ZipInputStream; copyFile("addplots.js", Settings.Paths.SCRIPTS); copyFile("addsigns.js", Settings.Paths.SCRIPTS); copyFile("automerge.js", Settings.Paths.SCRIPTS); + copyFile("fixborders.js", Settings.Paths.SCRIPTS); copyFile("furthest.js", Settings.Paths.SCRIPTS); copyFile("mycommand.js", Settings.Paths.SCRIPTS); copyFile("setbiomes.js", Settings.Paths.SCRIPTS); copyFile("start.js", Settings.Paths.SCRIPTS); copyFile("town.template", Settings.Paths.TEMPLATES); - copyFile("skyblock.template", Settings.Paths.TEMPLATES); copyFile("bridge.template", Settings.Paths.TEMPLATES); copyFile("de-DE.yml", Settings.Paths.TRANSLATIONS); copyFile("es-ES.yml", Settings.Paths.TRANSLATIONS); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java index cbc227bd3..b51993326 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java @@ -16,7 +16,7 @@ import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "leave", description = "Removes self from being trusted or a member of the plot", permission = "plots.leave", category = CommandCategory.CLAIMING, - requiredType = RequiredType.NONE) public class Leave extends Command { + requiredType = RequiredType.PLAYER) public class Leave extends Command { public Leave() { super(MainCommand.getInstance(), true); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java index 8fbec1ecb..f3acaf5a0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Middle.java @@ -11,7 +11,7 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; */ @CommandDeclaration(command = "middle", aliases = {"center", "centre"}, description = "Teleports you to the center of the plot", usage = "/plot middle", - category = CommandCategory.TELEPORT, requiredType = RequiredType.NONE) public class Middle + category = CommandCategory.TELEPORT, requiredType = RequiredType.PLAYER) public class Middle extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] arguments) { @@ -20,9 +20,6 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; if (plot == null) { return sendMessage(player, Captions.NOT_IN_PLOT); } - if (!plot.hasOwner()) { - return sendMessage(player, Captions.PLOT_UNOWNED); - } player.teleport(plot.getCenter()); return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java index 321f91d24..5af706df3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java @@ -10,7 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "relight", description = "Relight your plot", usage = "/plot relight", - category = CommandCategory.DEBUG) public class Relight extends Command { + category = CommandCategory.DEBUG, requiredType = RequiredType.PLAYER) public class Relight extends Command { public Relight() { super(MainCommand.getInstance(), true); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java index 875eb6e4c..af1c0024d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java @@ -19,7 +19,7 @@ import java.util.UUID; @CommandDeclaration(command = "remove", aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"}, description = "Remove a player from a plot", usage = "/plot remove ", - category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, + category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER, permission = "plots.remove") public class Remove extends SubCommand { public Remove() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java index af0968a92..7a208ebd5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetHome.java @@ -10,7 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; @CommandDeclaration(command = "sethome", permission = "plots.set.home", description = "Set the plot home to your current position", usage = "/plot sethome [none]", - aliases = {"sh", "seth"}, category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE) + aliases = {"sh", "seth"}, category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER) public class SetHome extends SetCommand { @Override public boolean set(PlotPlayer player, Plot plot, String value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java index 3467171f2..80225c2aa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java @@ -27,6 +27,7 @@ public class GameModeFlag extends Flag { case "2": return PlotGameMode.ADVENTURE; case "spectator": + case "sp": case "3": return PlotGameMode.SPECTATOR; default: diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java deleted file mode 100644 index 3b0563a3d..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.util; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class HastebinUtility { - - public static final String BIN_URL = "https://hastebin.com/documents", USER_AGENT = - "Mozilla/5.0"; - public static final Pattern PATTERN = Pattern.compile("\\{\"key\":\"([\\S\\s]*)\"\\}"); - - public static String upload(final String string) throws IOException { - final URL url = new URL(BIN_URL); - final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - - connection.setRequestMethod("POST"); - connection.setRequestProperty("User-Agent", USER_AGENT); - connection.setDoOutput(true); - - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { - outputStream.write(string.getBytes()); - outputStream.flush(); - } - - StringBuilder response; - try (BufferedReader in = new BufferedReader( - new InputStreamReader(connection.getInputStream()))) { - response = new StringBuilder(); - - String inputLine; - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - } - - Matcher matcher = PATTERN.matcher(response.toString()); - if (matcher.matches()) { - return "https://hastebin.com/" + matcher.group(1); - } else { - throw new RuntimeException("Couldn't read response!"); - } - } - - public static String upload(final File file) throws IOException { - List lines = new ArrayList<>(); - try (BufferedReader reader = new BufferedReader(new FileReader(file))) { - String line; - int i = 0; - while ((line = reader.readLine()) != null) { - lines.add(line); - } - } - final StringBuilder content = new StringBuilder(); - for (int i = Math.max(0, lines.size() - 1000); i < lines.size(); i++) { - content.append(lines.get(i)).append("\n"); - } - return upload(content.toString()); - } - -}