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