mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Cleanup of code
This commit is contained in:
parent
feee63b3af
commit
8d4f042abc
@ -13,7 +13,7 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class APlotMeConnector {
|
||||
abstract class APlotMeConnector {
|
||||
|
||||
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
@ -8,14 +7,11 @@ import com.intellectualcrafters.plot.util.PlotGameMode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.WeatherType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -28,8 +24,8 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
private long last = 0;
|
||||
|
||||
/**
|
||||
* <p>Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
|
||||
* as it caches player objects.</p>
|
||||
* <p>Please do not use this method. Instead use
|
||||
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
||||
* @param player
|
||||
*/
|
||||
public BukkitPlayer(Player player) {
|
||||
@ -73,29 +69,6 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
return this.player.hasPermission(permission);
|
||||
}
|
||||
|
||||
public Permission getPermission(String node) {
|
||||
PluginManager manager = Bukkit.getPluginManager();
|
||||
Permission perm = manager.getPermission(node);
|
||||
if (perm == null) {
|
||||
String[] nodes = node.split("\\.");
|
||||
perm = new Permission(node);
|
||||
StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < nodes.length - 1; i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (!node.equals(n + C.PERMISSION_STAR.s())) {
|
||||
Permission parent = getPermission(n + C.PERMISSION_STAR.s());
|
||||
if (parent != null) {
|
||||
perm.addParent(parent, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
manager.addPermission(perm);
|
||||
}
|
||||
manager.recalculatePermissionDefaults(perm);
|
||||
perm.recalculatePermissibles();
|
||||
return perm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
this.player.sendMessage(message);
|
||||
@ -166,7 +139,7 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
case SURVIVAL:
|
||||
return PlotGameMode.SURVIVAL;
|
||||
default:
|
||||
return PlotGameMode.SURVIVAL;
|
||||
return PlotGameMode.NOT_SET;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ public class DefaultTitleManager {
|
||||
* Load spigot and NMS classes
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private void loadClasses() throws ClassNotFoundException {
|
||||
private void loadClasses() {
|
||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
||||
this.packetActions = Reflection.getNMSClass("EnumTitleAction");
|
||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||
|
@ -127,7 +127,7 @@ public class DefaultTitleManager_183 {
|
||||
* Load spigot and NMS classes
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private void loadClasses() throws ClassNotFoundException {
|
||||
private void loadClasses() {
|
||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
||||
|
@ -116,7 +116,7 @@ public class HackTitleManager {
|
||||
* Load spigot and NMS classes.
|
||||
* @throws ClassNotFoundException Spigot Error.
|
||||
*/
|
||||
private void loadClasses() throws ClassNotFoundException {
|
||||
private void loadClasses() {
|
||||
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
||||
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||
|
@ -4,16 +4,17 @@ import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.bukkit.commands.DebugUUID;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
public BukkitCommand() {
|
||||
@ -25,7 +26,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
if (commandSender instanceof Player) {
|
||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
||||
}
|
||||
if (commandSender == null || commandSender.getClass() == Bukkit.getConsoleSender().getClass()) {
|
||||
if (commandSender.getClass() == Bukkit.getConsoleSender().getClass()) {
|
||||
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -34,8 +34,7 @@ public class BukkitEconHandler extends EconHandler {
|
||||
}
|
||||
|
||||
private boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
this.perms = permissionProvider.getProvider();
|
||||
}
|
||||
@ -43,8 +42,10 @@ public class BukkitEconHandler extends EconHandler {
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
RegisteredServiceProvider<Economy> economyProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
this.econ = economyProvider.getProvider();
|
||||
}
|
||||
@ -79,7 +80,7 @@ public class BukkitEconHandler extends EconHandler {
|
||||
public boolean hasPermission(String world, String player, String perm) {
|
||||
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getBalance(PlotPlayer player) {
|
||||
return this.econ.getBalance(player.getName());
|
||||
|
@ -53,6 +53,7 @@ import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.util.area.QuadMap;
|
||||
import com.plotsquared.listener.WESubscriber;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@ -1902,7 +1903,7 @@ public class PS {
|
||||
case "3":
|
||||
return PlotGameMode.SPECTATOR;
|
||||
default:
|
||||
return null;
|
||||
return PlotGameMode.NOT_SET;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2246,23 +2247,23 @@ public class PS {
|
||||
log("Failed to save storage.yml");
|
||||
}
|
||||
try {
|
||||
commandsFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "commands.yml");
|
||||
if (!commandsFile.exists()) {
|
||||
if (!commandsFile.createNewFile()) {
|
||||
this.commandsFile = new File(this.IMP.getDirectory() + File.separator + "config" + File.separator + "commands.yml");
|
||||
if (!this.commandsFile.exists()) {
|
||||
if (!this.commandsFile.createNewFile()) {
|
||||
log("Could not the storage settings file, please create \"commands.yml\" manually.");
|
||||
}
|
||||
}
|
||||
commands = YamlConfiguration.loadConfiguration(commandsFile);
|
||||
this.commands = YamlConfiguration.loadConfiguration(this.commandsFile);
|
||||
setupStorage();
|
||||
} catch (IOException err_trans) {
|
||||
log("Failed to save commands.yml");
|
||||
}
|
||||
try {
|
||||
style.save(styleFile);
|
||||
config.save(configFile);
|
||||
storage.save(storageFile);
|
||||
commands.save(commandsFile);
|
||||
} catch (final IOException e) {
|
||||
this.style.save(this.styleFile);
|
||||
this.config.save(this.configFile);
|
||||
this.storage.save(this.storageFile);
|
||||
this.commands.save(this.commandsFile);
|
||||
} catch (IOException e) {
|
||||
log("Configuration file saving failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -1,64 +1,55 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
/**
|
||||
* CommandCategory
|
||||
*
|
||||
|
||||
|
||||
* CommandCategory.
|
||||
*/
|
||||
public enum CommandCategory {
|
||||
/**
|
||||
* Claiming CommandConfig
|
||||
*
|
||||
* Claiming CommandConfig.
|
||||
* Such as: /plot claim
|
||||
*/
|
||||
CLAIMING("Claiming"),
|
||||
/**
|
||||
* Teleportation CommandConfig
|
||||
*
|
||||
* Teleportation CommandConfig.
|
||||
* Such as: /plot visit
|
||||
*/
|
||||
TELEPORT("Teleport"),
|
||||
/**
|
||||
* Protection
|
||||
* Protection.
|
||||
*/
|
||||
SETTINGS("Protection"),
|
||||
/**
|
||||
* Chat
|
||||
* Chat.
|
||||
*/
|
||||
CHAT("Chat"),
|
||||
/**
|
||||
* Web
|
||||
* Web.
|
||||
*/
|
||||
SCHEMATIC("Web"),
|
||||
/**
|
||||
* Cosmetic
|
||||
* Cosmetic.
|
||||
*/
|
||||
APPEARANCE("Cosmetic"),
|
||||
/**
|
||||
* Information CommandConfig
|
||||
*
|
||||
* Information CommandConfig.
|
||||
* Such as: /plot info
|
||||
*/
|
||||
INFO("Info"),
|
||||
/**
|
||||
* Debug CommandConfig
|
||||
*
|
||||
* Debug CommandConfig.
|
||||
* Such as: /plot debug
|
||||
*/
|
||||
DEBUG("Debug"),
|
||||
/**
|
||||
* Administration commands
|
||||
* Administration commands.
|
||||
*/
|
||||
ADMINISTRATION("Admin");
|
||||
|
||||
/**
|
||||
* The category name (Readable)
|
||||
* The category name (Readable).
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param name readable name
|
||||
*/
|
||||
|
@ -45,7 +45,8 @@ public class Toggle extends Command {
|
||||
aliases = {"spy"},
|
||||
permission = "plots.admin.command.chat",
|
||||
description = "Toggle admin chat spying")
|
||||
public void chatspy(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public void chatspy(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
if (toggle(player, "chatspy")) {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
|
||||
} else {
|
||||
@ -58,7 +59,8 @@ public class Toggle extends Command {
|
||||
aliases = {"we", "wea"},
|
||||
permission = "plots.worldedit.bypass",
|
||||
description = "Toggle worldedit area restrictions")
|
||||
public void worldedit(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public void worldedit(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
if (toggle(player, "worldedit")) {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
|
||||
} else {
|
||||
@ -70,7 +72,8 @@ public class Toggle extends Command {
|
||||
command = "chat",
|
||||
permission = "plots.toggle.chat",
|
||||
description = "Toggle plot chat")
|
||||
public void chat(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public void chat(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
if (toggle(player, "chat")) {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
|
||||
} else {
|
||||
@ -82,7 +85,8 @@ public class Toggle extends Command {
|
||||
command = "titles",
|
||||
permission = "plots.toggle.titles",
|
||||
description = "Toggle plot title messages")
|
||||
public void titles(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public void titles(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
if (toggle(player, "titles")) {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
|
||||
} else {
|
||||
|
@ -85,11 +85,11 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
return true;
|
||||
}
|
||||
createSchemAbs(hpw, pos1, pos2, 0, true);
|
||||
createSchemAbs(hpw, pos1, pos2, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void createSchemAbs(HybridPlotWorld hpw, Location pos1, Location pos2, int height, boolean clear) {
|
||||
private void createSchemAbs(HybridPlotWorld hpw, Location pos1, Location pos2, boolean clear) {
|
||||
int size = hpw.SIZE;
|
||||
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
|
||||
short absX = (short) ((x - hpw.ROAD_OFFSET_X) % size);
|
||||
@ -103,13 +103,13 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
}
|
||||
HashMap<Integer, PlotBlock> blocks = hpw.G_SCH.get(MathMan.pair(absX, absZ));
|
||||
if (clear) {
|
||||
for (short y = (short) height; y <= (height + hpw.SCHEMATIC_HEIGHT); y++) {
|
||||
for (short y = (short) 0; y <= hpw.SCHEMATIC_HEIGHT; y++) {
|
||||
SetQueue.IMP.setBlock(hpw.worldname, x, y, z, 0);
|
||||
}
|
||||
}
|
||||
if (blocks != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) {
|
||||
SetQueue.IMP.setBlock(hpw.worldname, x, height + entry.getKey(), z, entry.getValue());
|
||||
SetQueue.IMP.setBlock(hpw.worldname, x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,7 +130,7 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
return true;
|
||||
}
|
||||
createSchemAbs(hpw, pos1, pos2, 0, true);
|
||||
createSchemAbs(hpw, pos1, pos2, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -144,11 +144,11 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
Location pos2 = getPlotBottomLocAbs(hpw, id2);
|
||||
pos1.setY(0);
|
||||
pos2.setY(256);
|
||||
createSchemAbs(hpw, pos1, pos2, 0, true);
|
||||
createSchemAbs(hpw, pos1, pos2, true);
|
||||
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
return true;
|
||||
}
|
||||
createSchemAbs(hpw, pos1, pos2, 0, true);
|
||||
createSchemAbs(hpw, pos1, pos2, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -221,6 +221,6 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
if (!plotworld.PLOT_SCHEMATIC) {
|
||||
return;
|
||||
}
|
||||
createSchemAbs(plotworld, l1, l2, 0, false);
|
||||
createSchemAbs(plotworld, l1, l2, false);
|
||||
}
|
||||
}
|
||||
|
@ -20,25 +20,6 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
@ -60,6 +41,25 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.plotsquared.listener.PlotListener;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* The plot class<br>
|
||||
* [IMPORTANT]
|
||||
@ -1128,15 +1128,14 @@ public class Plot {
|
||||
|
||||
/**
|
||||
* Set the home location
|
||||
* @param loc
|
||||
* @param location
|
||||
*/
|
||||
public void setHome(BlockLoc loc) {
|
||||
public void setHome(BlockLoc location) {
|
||||
Plot plot = this.getBasePlot(false);
|
||||
BlockLoc pos = plot.getSettings().getPosition();
|
||||
if (new BlockLoc(0, 0, 0).equals(loc)) {
|
||||
if (new BlockLoc(0, 0, 0).equals(location)) {
|
||||
return;
|
||||
}
|
||||
plot.getSettings().setPosition(loc);
|
||||
plot.getSettings().setPosition(location);
|
||||
DBFunc.setPosition(plot, plot.getSettings().getPosition().toString());
|
||||
}
|
||||
|
||||
@ -1273,7 +1272,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plot sign if plot signs are enabled
|
||||
* Set the plot sign if plot signs are enabled.
|
||||
*/
|
||||
public void setSign() {
|
||||
if (this.owner == null) {
|
||||
@ -1338,6 +1337,8 @@ public class Plot {
|
||||
* - The plot will not be created if the owner is null<br>
|
||||
* - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot
|
||||
* creation.
|
||||
* @param uuid
|
||||
* @param notify
|
||||
* @return true if plot was created successfully
|
||||
*/
|
||||
public boolean create(final UUID uuid, final boolean notify) {
|
||||
@ -1377,7 +1378,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set components such as border, wall, floor
|
||||
* Set components such as border, wall, floor.
|
||||
* (components are generator specific)
|
||||
*/
|
||||
public boolean setComponent(String component, String blocks) {
|
||||
@ -1386,7 +1387,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the biome (String)
|
||||
* Get the biome.
|
||||
*/
|
||||
public String getBiome() {
|
||||
Location loc = this.getBottomAbs();
|
||||
@ -1394,7 +1395,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the top location for the plot
|
||||
* Return the top location for the plot.
|
||||
* @return
|
||||
*/
|
||||
public Location getTopAbs() {
|
||||
@ -1402,7 +1403,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bottom location for the plot
|
||||
* Return the bottom location for the plot.
|
||||
* @return
|
||||
*/
|
||||
public Location getBottomAbs() {
|
||||
@ -1410,43 +1411,43 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the settings for two plots
|
||||
* @param p2
|
||||
* Swap the settings for two plots.
|
||||
* @param plot
|
||||
* @param whenDone
|
||||
* @return
|
||||
*/
|
||||
public boolean swapData(Plot p2, Runnable whenDone) {
|
||||
public boolean swapData(Plot plot, Runnable whenDone) {
|
||||
if (this.owner == null) {
|
||||
if (p2 != null && p2.hasOwner()) {
|
||||
p2.moveData(this, whenDone);
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
plot.moveData(this, whenDone);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (p2 == null || p2.owner == null) {
|
||||
this.moveData(p2, whenDone);
|
||||
if (plot == null || plot.owner == null) {
|
||||
this.moveData(plot, whenDone);
|
||||
return true;
|
||||
}
|
||||
// Swap cached
|
||||
PlotId temp = new PlotId(this.getId().x, this.getId().y);
|
||||
this.getId().x = p2.getId().x;
|
||||
this.getId().y = p2.getId().y;
|
||||
p2.getId().x = temp.x;
|
||||
p2.getId().y = temp.y;
|
||||
this.getId().x = plot.getId().x;
|
||||
this.getId().y = plot.getId().y;
|
||||
plot.getId().x = temp.x;
|
||||
plot.getId().y = temp.y;
|
||||
this.area.removePlot(this.getId());
|
||||
p2.area.removePlot(p2.getId());
|
||||
plot.area.removePlot(plot.getId());
|
||||
this.getId().recalculateHash();
|
||||
p2.getId().recalculateHash();
|
||||
plot.getId().recalculateHash();
|
||||
this.area.addPlotAbs(this);
|
||||
p2.area.addPlotAbs(p2);
|
||||
plot.area.addPlotAbs(plot);
|
||||
// Swap database
|
||||
DBFunc.dbManager.swapPlots(p2, this);
|
||||
DBFunc.dbManager.swapPlots(plot, this);
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the settings for a plot
|
||||
* Move the settings for a plot.
|
||||
* @param pos2
|
||||
* @param whenDone
|
||||
* @return
|
||||
@ -1621,7 +1622,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plot display name
|
||||
* Get plot display name.
|
||||
*
|
||||
* @return alias if set, else id
|
||||
*/
|
||||
@ -1718,7 +1719,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the plot as a schematic to the configured output directory
|
||||
* Export the plot as a schematic to the configured output directory.
|
||||
* @return
|
||||
*/
|
||||
public void export(final RunnableVal<Boolean> whenDone) {
|
||||
@ -1764,7 +1765,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload the plot as a schematic to the configured web interface<br>
|
||||
* Upload the plot as a schematic to the configured web interface.
|
||||
* @param whenDone value will be null if uploading fails
|
||||
*/
|
||||
public void upload(final RunnableVal<URL> whenDone) {
|
||||
@ -1838,7 +1839,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag for this plot
|
||||
* Set a flag for this plot.
|
||||
* @param flags
|
||||
*/
|
||||
public void setFlags(Set<Flag> flags) {
|
||||
@ -1846,9 +1847,9 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot Alias<br>
|
||||
* Get the plot alias.
|
||||
* - Returns an empty string if no alias is set
|
||||
* @return
|
||||
* @return The plot alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
if (this.settings == null) {
|
||||
@ -1858,8 +1859,8 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plot alias
|
||||
* @param alias
|
||||
* Set the plot alias.
|
||||
* @param alias The alias
|
||||
*/
|
||||
public void setAlias(String alias) {
|
||||
for (Plot current : this.getConnectedPlots()) {
|
||||
@ -1912,7 +1913,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the merged array
|
||||
* Get the merged array.
|
||||
* @return boolean [ north, east, south, west ]
|
||||
*/
|
||||
public boolean[] getMerged() {
|
||||
@ -2512,8 +2513,8 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the corners of the plot (supports non-rectangular shapes)<br>
|
||||
* @return
|
||||
* Get all the corners of the plot (supports non-rectangular shapes).
|
||||
* @return A list of the plot corners
|
||||
*/
|
||||
public List<Location> getAllCorners() {
|
||||
Area area = new Area();
|
||||
@ -2536,7 +2537,7 @@ public class Plot {
|
||||
|
||||
/**
|
||||
* Teleport a player to a plot and send them the teleport message.
|
||||
* @param player
|
||||
* @param player The player
|
||||
* @return If the teleportation is allowed.
|
||||
*/
|
||||
public boolean teleportPlayer(final PlotPlayer player) {
|
||||
@ -2605,7 +2606,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the world border to include the provided plot (if applicable)
|
||||
* Expand the world border to include the provided plot (if applicable).
|
||||
*/
|
||||
public void updateWorldBorder() {
|
||||
if (this.owner == null) {
|
||||
@ -2672,7 +2673,7 @@ public class Plot {
|
||||
greaterPlot.setMerged(3, true);
|
||||
lesserPlot.mergeData(greaterPlot);
|
||||
if (removeRoads) {
|
||||
final Plot other = lesserPlot.getRelative(0);
|
||||
Plot other = lesserPlot.getRelative(0);
|
||||
if (other.getMerged(2) && other.getMerged(1)) {
|
||||
greaterPlot.mergePlot(other, removeRoads);
|
||||
other.removeRoadSouthEast();
|
||||
|
@ -274,7 +274,7 @@ public abstract class PlotArea {
|
||||
this.GAMEMODE = PlotGameMode.SPECTATOR;
|
||||
break;
|
||||
default:
|
||||
PS.debug("&cInvalid gamemode set for: " + this.worldname);
|
||||
this.GAMEMODE = PlotGameMode.NOT_SET;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,33 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
public enum PlotGameMode {
|
||||
ADVENTURE, SURVIVAL, CREATIVE, SPECTATOR
|
||||
NOT_SET(-1, ""),
|
||||
SURVIVAL(0, "survival"),
|
||||
CREATIVE(1, "creative"),
|
||||
ADVENTURE(2, "adventure"),
|
||||
SPECTATOR(3, "spectator");
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
|
||||
PlotGameMode(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The magic-value id of the GameMode.
|
||||
* @return the GameMode id
|
||||
*/
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this GameMode
|
||||
* @return the GameMode name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class UUIDHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map containing all names/uuids
|
||||
* Get the map containing all names/uuids.
|
||||
*
|
||||
* @return map with names + uuids
|
||||
*
|
||||
|
@ -189,12 +189,6 @@ public abstract class UUIDHandlerImplementation {
|
||||
if (uuid == null) {
|
||||
return null;
|
||||
}
|
||||
// // check online
|
||||
// final PlotPlayer player = getPlayer(uuid);
|
||||
// if (player != null) {
|
||||
// return player.getName();
|
||||
// }
|
||||
// check cache
|
||||
StringWrapper name = this.uuidMap.inverse().get(uuid);
|
||||
if (name != null) {
|
||||
return name.value;
|
||||
@ -203,7 +197,7 @@ public abstract class UUIDHandlerImplementation {
|
||||
}
|
||||
|
||||
public UUID getUUID(String name, RunnableVal<UUID> ifFetch) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
if (name.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// check online
|
||||
|
@ -14,6 +14,7 @@ import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -32,36 +33,77 @@ import java.util.Set;
|
||||
public abstract class Command {
|
||||
|
||||
// May be none
|
||||
private ArrayList<Command> allCommands = new ArrayList<>();
|
||||
private ArrayList<Command> dynamicCommands = new ArrayList<>();
|
||||
private HashMap<String, Command> staticCommands = new HashMap<>();
|
||||
private final ArrayList<Command> allCommands = new ArrayList<>();
|
||||
private final ArrayList<Command> dynamicCommands = new ArrayList<>();
|
||||
private final HashMap<String, Command> staticCommands = new HashMap<>();
|
||||
|
||||
// Parent command (may be null)
|
||||
private Command parent;
|
||||
|
||||
private final Command parent;
|
||||
private final boolean isStatic;
|
||||
// The command ID
|
||||
private String id;
|
||||
private List<String> aliases;
|
||||
private RequiredType required;
|
||||
private String usage;
|
||||
private String description;
|
||||
private boolean isStatic;
|
||||
private String perm;
|
||||
private boolean confirmation;
|
||||
private CommandCategory category;
|
||||
private Argument[] arguments;
|
||||
|
||||
public Command(Command parent, boolean isStatic, String id, String perm, RequiredType required, CommandCategory cat) {
|
||||
this.parent = parent;
|
||||
this.isStatic = isStatic;
|
||||
this.id = id;
|
||||
this.perm = perm;
|
||||
this.required = required;
|
||||
this.category = cat;
|
||||
this.aliases = Arrays.asList(id);
|
||||
}
|
||||
|
||||
public Command(Command parent, boolean isStatic) {
|
||||
this.parent = parent;
|
||||
this.isStatic = isStatic;
|
||||
Annotation cdAnnotation = getClass().getAnnotation(CommandDeclaration.class);
|
||||
if (cdAnnotation != null) {
|
||||
CommandDeclaration declaration = (CommandDeclaration) cdAnnotation;
|
||||
init(declaration);
|
||||
}
|
||||
for (final Method method : getClass().getDeclaredMethods()) {
|
||||
if (method.isAnnotationPresent(CommandDeclaration.class)) {
|
||||
Class<?>[] types = method.getParameterTypes();
|
||||
// final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult>
|
||||
// whenDone
|
||||
if (types.length == 5 && types[0] == Command.class && types[1] == PlotPlayer.class && types[2] == String[].class
|
||||
&& types[3] == RunnableVal3.class && types[4] == RunnableVal2.class) {
|
||||
Command tmp = new Command(this, true) {
|
||||
@Override
|
||||
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
try {
|
||||
method.invoke(Command.this, this, player, args, confirm, whenDone);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
tmp.init(method.getAnnotation(CommandDeclaration.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Command getParent() {
|
||||
return parent;
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public List<Command> getCommands(PlotPlayer player) {
|
||||
List<Command> commands = new ArrayList<>();
|
||||
for (Command cmd : allCommands) {
|
||||
for (Command cmd : this.allCommands) {
|
||||
if (cmd.canExecute(player, false)) {
|
||||
commands.add(cmd);
|
||||
}
|
||||
@ -83,74 +125,33 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public List<Command> getCommands() {
|
||||
return allCommands;
|
||||
return this.allCommands;
|
||||
}
|
||||
|
||||
public boolean hasConfirmation(PlotPlayer player) {
|
||||
return confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
|
||||
return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public RequiredType getRequiredType() {
|
||||
return required;
|
||||
return this.required;
|
||||
}
|
||||
|
||||
public Argument[] getRequiredArguments() {
|
||||
return arguments;
|
||||
return this.arguments;
|
||||
}
|
||||
|
||||
public void setRequiredArguments(Argument[] arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public Command(Command parent, boolean isStatic, String id, String perm, RequiredType required, CommandCategory cat) {
|
||||
this.parent = parent;
|
||||
this.isStatic = isStatic;
|
||||
this.id = id;
|
||||
this.perm = perm;
|
||||
this.required = required;
|
||||
this.category = cat;
|
||||
this.aliases = Arrays.asList(id);
|
||||
}
|
||||
|
||||
public Command(Command parent, boolean isStatic) {
|
||||
this.parent = parent;
|
||||
this.isStatic = isStatic;
|
||||
final Annotation cdAnnotation = getClass().getAnnotation(CommandDeclaration.class);
|
||||
if (cdAnnotation != null) {
|
||||
final CommandDeclaration declaration = (CommandDeclaration) cdAnnotation;
|
||||
init(declaration);
|
||||
}
|
||||
for (final Method method : getClass().getDeclaredMethods()) {
|
||||
if (method.isAnnotationPresent(CommandDeclaration.class)) {
|
||||
Class<?>[] types = method.getParameterTypes();
|
||||
// final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone
|
||||
if (types.length == 5 && types[0] == Command.class && types[1] == PlotPlayer.class && types[2] == String[].class && types[3] == RunnableVal3.class && types[4] == RunnableVal2.class) {
|
||||
Command tmp = new Command(this, true) {
|
||||
@Override
|
||||
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
try {
|
||||
method.invoke(Command.this, this, player, args, confirm, whenDone);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
tmp.init(method.getAnnotation(CommandDeclaration.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void init(CommandDeclaration declaration) {
|
||||
this.id = declaration.command();
|
||||
this.perm = declaration.permission();
|
||||
@ -158,7 +159,7 @@ public abstract class Command {
|
||||
this.category = declaration.category();
|
||||
HashMap<String, Object> options = new HashMap<>();
|
||||
List<String> aliasOptions = new ArrayList<>();
|
||||
aliasOptions.add(id);
|
||||
aliasOptions.add(this.id);
|
||||
aliasOptions.addAll(Arrays.asList(declaration.aliases()));
|
||||
options.put("aliases", aliasOptions);
|
||||
options.put("description", declaration.description());
|
||||
@ -166,7 +167,7 @@ public abstract class Command {
|
||||
options.put("confirmation", declaration.confirmation());
|
||||
boolean set = false;
|
||||
for (Map.Entry<String, Object> entry : options.entrySet()) {
|
||||
String key = id + "." + entry.getKey();
|
||||
String key = this.id + "." + entry.getKey();
|
||||
if (!PS.get().commands.contains(key)) {
|
||||
PS.get().commands.set(key, entry.getValue());
|
||||
set = true;
|
||||
@ -180,50 +181,46 @@ public abstract class Command {
|
||||
|
||||
}
|
||||
}
|
||||
aliases = PS.get().commands.getStringList(id + ".aliases");
|
||||
description = PS.get().commands.getString(id + ".description");
|
||||
usage = PS.get().commands.getString(id + ".usage");
|
||||
confirmation = PS.get().commands.getBoolean(id + ".confirmation");
|
||||
if (parent != null) {
|
||||
parent.register(this);
|
||||
this.aliases = PS.get().commands.getStringList(this.id + ".aliases");
|
||||
this.description = PS.get().commands.getString(this.id + ".description");
|
||||
this.usage = PS.get().commands.getString(this.id + ".usage");
|
||||
this.confirmation = PS.get().commands.getBoolean(this.id + ".confirmation");
|
||||
if (this.parent != null) {
|
||||
this.parent.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void register(Command command) {
|
||||
if (command.isStatic) {
|
||||
for (String alias : command.aliases) {
|
||||
staticCommands.put(alias.toLowerCase(), command);
|
||||
this.staticCommands.put(alias.toLowerCase(), command);
|
||||
}
|
||||
} else {
|
||||
dynamicCommands.add(command);
|
||||
this.dynamicCommands.add(command);
|
||||
}
|
||||
allCommands.add(command);
|
||||
}
|
||||
|
||||
public enum CommandResult {
|
||||
FAILURE,
|
||||
SUCCESS
|
||||
this.allCommands.add(command);
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
if (perm != null && perm.length() != 0) {
|
||||
return perm;
|
||||
if (this.perm != null && !this.perm.isEmpty()) {
|
||||
return this.perm;
|
||||
}
|
||||
if (parent == null) {
|
||||
if (this.parent == null) {
|
||||
return "plots.use";
|
||||
}
|
||||
if (parent.parent == null) {
|
||||
return "plots." + id;
|
||||
if (this.parent.parent == null) {
|
||||
return "plots." + this.id;
|
||||
}
|
||||
return parent.getPermission() + "." + id;
|
||||
return this.parent.getPermission() + "." + this.id;
|
||||
}
|
||||
|
||||
public <T> void paginate(PlotPlayer player, List<T> c, int size, int page, RunnableVal3<Integer, T, PlotMessage> add, String baseCommand, String header) {
|
||||
public <T> void paginate(PlotPlayer player, List<T> c, int size, int page, RunnableVal3<Integer, T, PlotMessage> add, String baseCommand,
|
||||
String header) {
|
||||
// Calculate pages & index
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
final int totalPages = (int) Math.ceil(c.size() / size);
|
||||
int totalPages = (int) Math.ceil(c.size() / size);
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
@ -232,12 +229,13 @@ public abstract class Command {
|
||||
max = c.size();
|
||||
}
|
||||
// Send the header
|
||||
header = header.replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%amount%", c.size() + "").replaceAll("%word%", "all");
|
||||
header = header.replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%amount%", c.size() + "")
|
||||
.replaceAll("%word%", "all");
|
||||
MainUtil.sendMessage(player, header);
|
||||
// Send the page content
|
||||
final List<T> subList = c.subList(page * size, max);
|
||||
List<T> subList = c.subList(page * size, max);
|
||||
int i = page * size;
|
||||
for (final T obj : subList) {
|
||||
for (T obj : subList) {
|
||||
i++;
|
||||
PlotMessage msg = new PlotMessage();
|
||||
add.run(i, obj, msg);
|
||||
@ -251,7 +249,8 @@ public abstract class Command {
|
||||
return;
|
||||
}
|
||||
if (page == 0 && totalPages != 0) { // Next
|
||||
new PlotMessage().text("<-").color("$3").text(" | ").color("$3").text("->").color("$1").command(baseCommand + " " + (page + 2)).text(C.CLICKABLE.s()).color("$2").send(player);
|
||||
new PlotMessage().text("<-").color("$3").text(" | ").color("$3").text("->").color("$1").command(baseCommand + " " + (page + 2))
|
||||
.text(C.CLICKABLE.s()).color("$2").send(player);
|
||||
return;
|
||||
}
|
||||
if (page == totalPages && totalPages != 0) { // Back
|
||||
@ -267,22 +266,23 @@ public abstract class Command {
|
||||
* @param confirm Instance, Success, Failure
|
||||
* @return
|
||||
*/
|
||||
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
||||
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
if (args.length == 0 || args[0] == null) {
|
||||
if (parent == null) {
|
||||
if (this.parent == null) {
|
||||
MainCommand.getInstance().help.displayHelp(player, null, 0);
|
||||
} else {
|
||||
C.COMMAND_SYNTAX.send(player, getUsage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (allCommands == null || allCommands.size() == 0) {
|
||||
if (this.allCommands == null || this.allCommands.isEmpty()) {
|
||||
player.sendMessage("Not Implemented: https://github.com/IntellectualSites/PlotSquared/issues/new");
|
||||
return;
|
||||
}
|
||||
Command cmd = getCommand(args[0]);
|
||||
if (cmd == null) {
|
||||
if (parent != null) {
|
||||
if (this.parent != null) {
|
||||
C.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return;
|
||||
}
|
||||
@ -294,7 +294,8 @@ public abstract class Command {
|
||||
MainCommand.getInstance().help.execute(player, args, null, null);
|
||||
return;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {}
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
// Command recommendation
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
||||
{
|
||||
@ -316,7 +317,7 @@ public abstract class Command {
|
||||
}
|
||||
}
|
||||
if (cmd == null) {
|
||||
cmd = new StringComparison<>(args[0], allCommands).getMatchObject();
|
||||
cmd = new StringComparison<>(args[0], this.allCommands).getMatchObject();
|
||||
}
|
||||
MainUtil.sendMessage(player, C.DID_YOU_MEAN, cmd.getUsage());
|
||||
}
|
||||
@ -383,9 +384,9 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public Command getCommand(String arg) {
|
||||
Command cmd = staticCommands.get(arg.toLowerCase());
|
||||
Command cmd = this.staticCommands.get(arg.toLowerCase());
|
||||
if (cmd == null) {
|
||||
for (Command command : dynamicCommands) {
|
||||
for (Command command : this.dynamicCommands) {
|
||||
if (command.matches(arg)) {
|
||||
return command;
|
||||
}
|
||||
@ -395,7 +396,7 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public Command getCommand(Class clazz) {
|
||||
for (Command cmd : allCommands) {
|
||||
for (Command cmd : this.allCommands) {
|
||||
if (cmd.getClass() == clazz) {
|
||||
return cmd;
|
||||
}
|
||||
@ -404,11 +405,11 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public Command getCommandById(String id) {
|
||||
Command exact = staticCommands.get(id);
|
||||
Command exact = this.staticCommands.get(id);
|
||||
if (exact != null) {
|
||||
return exact;
|
||||
}
|
||||
for (Command cmd : allCommands) {
|
||||
for (Command cmd : this.allCommands) {
|
||||
if (cmd.getId().equals(id)) {
|
||||
return cmd;
|
||||
}
|
||||
@ -417,9 +418,9 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public boolean canExecute(PlotPlayer player, boolean message) {
|
||||
if (!required.allows(player)) {
|
||||
if (!this.required.allows(player)) {
|
||||
if (message) {
|
||||
MainUtil.sendMessage(player, required == RequiredType.PLAYER ? C.IS_CONSOLE : C.NOT_CONSOLE);
|
||||
MainUtil.sendMessage(player, this.required == RequiredType.PLAYER ? C.IS_CONSOLE : C.NOT_CONSOLE);
|
||||
}
|
||||
} else if (!Permissions.hasPermission(player, getPermission())) {
|
||||
if (message) {
|
||||
@ -433,31 +434,31 @@ public abstract class Command {
|
||||
|
||||
public boolean matches(String arg) {
|
||||
arg = arg.toLowerCase();
|
||||
return StringMan.isEqual(arg, id) || aliases.contains(arg);
|
||||
return StringMan.isEqual(arg, this.id) || this.aliases.contains(arg);
|
||||
}
|
||||
|
||||
public String getCommandString() {
|
||||
String base;
|
||||
if (parent == null) {
|
||||
if (this.parent == null) {
|
||||
return "/" + toString();
|
||||
} else {
|
||||
return parent.getCommandString() + " " + toString();
|
||||
return this.parent.getCommandString() + " " + toString();
|
||||
}
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
if (usage != null && usage.length() != 0) {
|
||||
if (usage.startsWith("/")) {
|
||||
return usage;
|
||||
if (this.usage != null && this.usage.length() != 0) {
|
||||
if (this.usage.startsWith("/")) {
|
||||
return this.usage;
|
||||
}
|
||||
return getCommandString() + " " + usage;
|
||||
return getCommandString() + " " + this.usage;
|
||||
}
|
||||
if (allCommands.size() == 0) {
|
||||
if (this.allCommands.size() == 0) {
|
||||
return getCommandString();
|
||||
}
|
||||
StringBuilder args = new StringBuilder("[");
|
||||
String prefix = "";
|
||||
for (Command cmd : allCommands) {
|
||||
for (Command cmd : this.allCommands) {
|
||||
args.append(prefix).append(cmd.isStatic ? cmd.toString() : "<" + cmd + ">");
|
||||
prefix = "|";
|
||||
}
|
||||
@ -467,15 +468,15 @@ public abstract class Command {
|
||||
public Collection tab(PlotPlayer player, String[] args, boolean space) {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
return allCommands;
|
||||
return this.allCommands;
|
||||
case 1:
|
||||
String arg = args[0].toLowerCase();
|
||||
if (space) {
|
||||
Command cmd = getCommand(arg);
|
||||
return (cmd != null && cmd.canExecute(player, false)) ? (cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space)) : null;
|
||||
return (cmd != null && cmd.canExecute(player, false)) ? cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space) : null;
|
||||
} else {
|
||||
Set<Command> commands = new HashSet<Command>();
|
||||
for (Map.Entry<String, Command> entry : staticCommands.entrySet()) {
|
||||
for (Map.Entry<String, Command> entry : this.staticCommands.entrySet()) {
|
||||
if (entry.getKey().startsWith(arg) && entry.getValue().canExecute(player, false)) {
|
||||
commands.add(entry.getValue());
|
||||
}
|
||||
@ -490,7 +491,7 @@ public abstract class Command {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return aliases.size() > 0 ? aliases.get(0) : id;
|
||||
return this.aliases.size() > 0 ? this.aliases.get(0) : this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -501,7 +502,7 @@ public abstract class Command {
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Command other = (Command) obj;
|
||||
Command other = (Command) obj;
|
||||
if (this.hashCode() != other.hashCode()) {
|
||||
return false;
|
||||
}
|
||||
@ -510,6 +511,11 @@ public abstract class Command {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
public enum CommandResult {
|
||||
FAILURE,
|
||||
SUCCESS
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,96 @@
|
||||
//package com.intellectualcrafters.plot;
|
||||
//
|
||||
//import static com.intellectualcrafters.plot.PS.log;
|
||||
//
|
||||
//import com.google.gson.Gson;
|
||||
//import com.google.gson.annotations.SerializedName;
|
||||
//
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStreamReader;
|
||||
//import java.net.URL;
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class UpdaterTest {
|
||||
//
|
||||
// @org.junit.Test
|
||||
// public void getUpdate() throws Exception {
|
||||
// String str = null;
|
||||
// BufferedReader reader = null;
|
||||
// try {
|
||||
// URL url = new URL("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
|
||||
// reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
// StringBuilder buffer = new StringBuilder();
|
||||
// int read;
|
||||
// char[] chars = new char[1024];
|
||||
// while ((read = reader.read(chars)) != -1) {
|
||||
// buffer.append(chars, 0, read);
|
||||
// }
|
||||
//
|
||||
// str = buffer.toString();
|
||||
// } catch (IOException e) {
|
||||
// log("&dCould not check for updates (0)");
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// try {
|
||||
// if (reader != null) {
|
||||
// reader.close();
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// if (str == null) {
|
||||
// return;
|
||||
// }
|
||||
// Gson gson = new Gson();
|
||||
// Release release = gson.fromJson(str, Release.class);
|
||||
// System.out.println(release.name);
|
||||
// for (Release.Assets asset : release.assets) {
|
||||
// System.out.println(asset.name);
|
||||
// System.out.println(asset.downloadUrl);
|
||||
// }
|
||||
// }
|
||||
// private static class Release {
|
||||
// String name;
|
||||
// List<Assets> assets;
|
||||
// private static class Assets {
|
||||
// String name;
|
||||
// @SerializedName("browser_download_url") String downloadUrl;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import static com.intellectualcrafters.plot.PS.log;
|
||||
|
||||
import com.intellectualcrafters.json.JSONArray;
|
||||
import com.intellectualcrafters.json.JSONObject;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class UpdaterTest {
|
||||
|
||||
private static String readUrl(String urlString) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
int read;
|
||||
char[] chars = new char[1024];
|
||||
while ((read = reader.read(chars)) != -1) {
|
||||
buffer.append(chars, 0, read);
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
} catch (IOException e) {
|
||||
log("&dCould not check for updates (0)");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUpdate() throws Exception {
|
||||
String str = readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
|
||||
JSONObject release = new JSONObject(str);
|
||||
JSONArray assets = (JSONArray) release.get("assets");
|
||||
System.out.println(assets.toString());
|
||||
String downloadURL = String.format("PlotSquared-%s.jar", "Bukkit");
|
||||
for (int i = 0; i < assets.length(); i++) {
|
||||
System.out.println(i);
|
||||
JSONObject asset = assets.getJSONObject(i);
|
||||
String name = asset.getString("name");
|
||||
System.out.println(name);
|
||||
System.out.println(downloadURL);
|
||||
if (downloadURL.equals(name)) {
|
||||
try {
|
||||
String[] split = release.getString("name").split("\\.");
|
||||
int[] version;
|
||||
if (split.length == 3) {
|
||||
version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
|
||||
} else {
|
||||
version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), 0};
|
||||
}
|
||||
System.out.println(Arrays.toString(version));
|
||||
URL url = new URL(asset.getString("browser_download_url"));
|
||||
// If current version >= update
|
||||
if (checkVersion(new int[]{3, 3, 1}, version)) {
|
||||
System.out.println("&7PlotSquared is already up to date!");
|
||||
return;
|
||||
}
|
||||
System.out.println("&6PlotSquared " + StringMan.join(split, ".") + " is available:");
|
||||
System.out.println("&8 - &3Use: &7/plot update");
|
||||
System.out.println("&8 - &3Or: &7" + downloadURL);
|
||||
return;
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("&dCould not check for updates (1)");
|
||||
System.out.println("&7 - Manually check for updates: https://github.com/IntellectualSites/PlotSquared/releases");
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("You are running the latest version of PlotSquared");
|
||||
return;
|
||||
}
|
||||
|
||||
public boolean checkVersion(int[] version, int... version2) {
|
||||
return version[0] > version2[0] || version[0] == version2[0] && version[1] > version2[1] || version[0] == version2[0]
|
||||
&& version[1] == version2[1] && version[2] >= version2[2];
|
||||
}
|
||||
|
||||
}
|
@ -8,8 +8,6 @@ import com.intellectualcrafters.plot.util.PlotGameMode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.data.manipulator.mutable.TargetedLocationData;
|
||||
@ -22,6 +20,9 @@ import org.spongepowered.api.service.ban.BanService;
|
||||
import org.spongepowered.api.text.chat.ChatTypes;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongePlayer extends PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
@ -139,7 +140,9 @@ public class SpongePlayer extends PlotPlayer {
|
||||
if (gamemode == GameModes.SURVIVAL) {
|
||||
return PlotGameMode.SURVIVAL;
|
||||
}
|
||||
throw new UnsupportedOperationException("INVALID GAMEMODE");
|
||||
if (gamemode == GameModes.NOT_SET) {
|
||||
return PlotGameMode.NOT_SET;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,6 +160,11 @@ public class SpongePlayer extends PlotPlayer {
|
||||
case SURVIVAL:
|
||||
this.player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
||||
return;
|
||||
case NOT_SET:
|
||||
this.player.offer(Keys.GAME_MODE, GameModes.NOT_SET);
|
||||
return;
|
||||
default:
|
||||
this.player.offer(Keys.GAME_MODE, GameModes.NOT_SET);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user