mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 11:55:38 +01:00
Cleaning
This commit is contained in:
parent
48f22eaed4
commit
a62b9a334d
@ -45,6 +45,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -78,7 +79,8 @@ public class PlotAPI {
|
||||
* @deprecated Use new PlotAPI() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotAPI(final JavaPlugin plugin) {}
|
||||
public PlotAPI(JavaPlugin plugin) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PS
|
||||
@ -91,7 +93,8 @@ public class PlotAPI {
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotAPI() {}
|
||||
public PlotAPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots
|
||||
@ -111,7 +114,7 @@ public class PlotAPI {
|
||||
*
|
||||
* @return all plots that a player owns
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(final Player player) {
|
||||
public Set<Plot> getPlayerPlots(Player player) {
|
||||
return PS.get().getPlots(BukkitUtil.getPlayer(player));
|
||||
}
|
||||
|
||||
@ -121,7 +124,7 @@ public class PlotAPI {
|
||||
* @param plotArea Plot World Object
|
||||
* @see PS#addPlotArea(PlotArea)
|
||||
*/
|
||||
public void addPlotArea(final PlotArea plotArea) {
|
||||
public void addPlotArea(PlotArea plotArea) {
|
||||
PS.get().addPlotArea(plotArea);
|
||||
}
|
||||
|
||||
@ -226,9 +229,9 @@ public class PlotAPI {
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] getPermissions() {
|
||||
final ArrayList<String> perms = new ArrayList<>();
|
||||
for (final C c : C.values()) {
|
||||
if ("static.permissions".equals(c.getCat())) {
|
||||
ArrayList<String> perms = new ArrayList<>();
|
||||
for (C c : C.values()) {
|
||||
if ("static.permissions".equals(c.getCategory())) {
|
||||
perms.add(c.s());
|
||||
}
|
||||
}
|
||||
@ -269,7 +272,7 @@ public class PlotAPI {
|
||||
* @see PS#getPlotManager(Plot)
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotManager getPlotManager(final World world) {
|
||||
public PlotManager getPlotManager(World world) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
@ -295,7 +298,7 @@ public class PlotAPI {
|
||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotManager getPlotManager(final String world) {
|
||||
public PlotManager getPlotManager(String world) {
|
||||
Set<PlotArea> areas = PS.get().getPlotAreas(world);
|
||||
switch (areas.size()) {
|
||||
case 0:
|
||||
@ -320,7 +323,7 @@ public class PlotAPI {
|
||||
* @see com.intellectualcrafters.plot.object.PlotArea
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotArea getWorldSettings(final World world) {
|
||||
public PlotArea getWorldSettings(World world) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
@ -338,7 +341,7 @@ public class PlotAPI {
|
||||
* @see com.intellectualcrafters.plot.object.PlotArea
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotArea getWorldSettings(final String world) {
|
||||
public PlotArea getWorldSettings(String world) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
@ -363,7 +366,7 @@ public class PlotAPI {
|
||||
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
* com.intellectualcrafters.plot.config.C, String...)
|
||||
*/
|
||||
public void sendMessage(final Player player, final C c) {
|
||||
public void sendMessage(Player player, C c) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
|
||||
}
|
||||
|
||||
@ -375,7 +378,7 @@ public class PlotAPI {
|
||||
*
|
||||
* @see MainUtil#sendMessage(PlotPlayer, String)
|
||||
*/
|
||||
public void sendMessage(final Player player, final String string) {
|
||||
public void sendMessage(Player player, String string) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||
}
|
||||
|
||||
@ -386,7 +389,7 @@ public class PlotAPI {
|
||||
*
|
||||
* @see MainUtil#sendConsoleMessage(C, String...)
|
||||
*/
|
||||
public void sendConsoleMessage(final String msg) {
|
||||
public void sendConsoleMessage(String msg) {
|
||||
PS.log(msg);
|
||||
}
|
||||
|
||||
@ -398,8 +401,8 @@ public class PlotAPI {
|
||||
* @see #sendConsoleMessage(String)
|
||||
* @see com.intellectualcrafters.plot.config.C
|
||||
*/
|
||||
public void sendConsoleMessage(final C c) {
|
||||
sendConsoleMessage(c);
|
||||
public void sendConsoleMessage(C c) {
|
||||
sendConsoleMessage(c.s());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -410,7 +413,7 @@ public class PlotAPI {
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||
*/
|
||||
public void addFlag(final AbstractFlag flag) {
|
||||
public void addFlag(AbstractFlag flag) {
|
||||
FlagManager.addFlag(flag);
|
||||
}
|
||||
|
||||
@ -427,7 +430,7 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the ID
|
||||
* Get a plot based on the ID.
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param x Plot Location X Co-ord
|
||||
@ -438,7 +441,7 @@ public class PlotAPI {
|
||||
* @see PlotArea#getPlot(PlotId)
|
||||
*/
|
||||
@Deprecated
|
||||
public Plot getPlot(final World world, final int x, final int z) {
|
||||
public Plot getPlot(World world, int x, int z) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
@ -450,7 +453,7 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the location
|
||||
* Get a plot based on the location.
|
||||
*
|
||||
* @param l The location that you want to to retrieve the plot from
|
||||
*
|
||||
@ -458,7 +461,7 @@ public class PlotAPI {
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
public Plot getPlot(final Location l) {
|
||||
public Plot getPlot(Location l) {
|
||||
if (l == null) {
|
||||
return null;
|
||||
}
|
||||
@ -466,7 +469,7 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the player location
|
||||
* Get a plot based on the player location.
|
||||
*
|
||||
* @param player Get the current plot for the player location
|
||||
*
|
||||
@ -475,12 +478,12 @@ public class PlotAPI {
|
||||
* @see #getPlot(org.bukkit.Location)
|
||||
* @see Plot
|
||||
*/
|
||||
public Plot getPlot(final Player player) {
|
||||
public Plot getPlot(Player player) {
|
||||
return this.getPlot(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player has a plot
|
||||
* Check whether or not a player has a plot.
|
||||
*
|
||||
* @param player Player that you want to check for
|
||||
*
|
||||
@ -489,22 +492,23 @@ public class PlotAPI {
|
||||
* @see #getPlots(World, Player, boolean)
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasPlot(final World world, final Player player) {
|
||||
public boolean hasPlot(World world, Player player) {
|
||||
return getPlots(world, player, true) != null && getPlots(world, player, true).length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots for the player
|
||||
* Get all plots for the player.
|
||||
*
|
||||
* @param plr to search for
|
||||
* @param just_owner should we just search for owner? Or with rights?
|
||||
* @param world
|
||||
* @param player The player to search for
|
||||
* @param justOwner should we just search for owner? Or with rights?
|
||||
*/
|
||||
@Deprecated
|
||||
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
|
||||
final ArrayList<Plot> pPlots = new ArrayList<>();
|
||||
UUID uuid = BukkitUtil.getPlayer(plr).getUUID();
|
||||
for (final Plot plot : PS.get().getPlots(world.getName())) {
|
||||
if (just_owner) {
|
||||
public Plot[] getPlots(World world, Player player, boolean justOwner) {
|
||||
ArrayList<Plot> pPlots = new ArrayList<>();
|
||||
UUID uuid = BukkitUtil.getPlayer(player).getUUID();
|
||||
for (Plot plot : PS.get().getPlots(world.getName())) {
|
||||
if (justOwner) {
|
||||
if (plot.hasOwner() && plot.isOwner(uuid)) {
|
||||
pPlots.add(plot);
|
||||
}
|
||||
@ -518,7 +522,7 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots for the world
|
||||
* Get all plots for the world.
|
||||
*
|
||||
* @param world to get plots of
|
||||
*
|
||||
@ -528,7 +532,7 @@ public class PlotAPI {
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Plot[] getPlots(final World world) {
|
||||
public Plot[] getPlots(World world) {
|
||||
if (world == null) {
|
||||
return new Plot[0];
|
||||
}
|
||||
@ -537,7 +541,7 @@ public class PlotAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plot worlds
|
||||
* Get all plot worlds.
|
||||
*
|
||||
* @return World[] - array of plot worlds
|
||||
*
|
||||
@ -558,7 +562,7 @@ public class PlotAPI {
|
||||
* @see PS#hasPlotArea(String)
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isPlotWorld(final World world) {
|
||||
public boolean isPlotWorld(World world) {
|
||||
return PS.get().hasPlotArea(world.getName());
|
||||
}
|
||||
|
||||
@ -574,8 +578,8 @@ public class PlotAPI {
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Location[] getLocations(final Plot p) {
|
||||
return new Location[] { BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome()) };
|
||||
public Location[] getLocations(Plot p) {
|
||||
return new Location[]{BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome())};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -587,7 +591,7 @@ public class PlotAPI {
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
public Location getHomeLocation(final Plot p) {
|
||||
public Location getHomeLocation(Plot p) {
|
||||
return BukkitUtil.getLocation(p.getHome());
|
||||
}
|
||||
|
||||
@ -603,7 +607,7 @@ public class PlotAPI {
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Location getBottomLocation(final Plot p) {
|
||||
public Location getBottomLocation(Plot p) {
|
||||
return BukkitUtil.getLocation(p.getBottom());
|
||||
}
|
||||
|
||||
@ -619,7 +623,7 @@ public class PlotAPI {
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Location getTopLocation(final Plot p) {
|
||||
public Location getTopLocation(Plot p) {
|
||||
return BukkitUtil.getLocation(p.getTop());
|
||||
}
|
||||
|
||||
@ -631,7 +635,7 @@ public class PlotAPI {
|
||||
* @return true if the player is in a plot, false if not-
|
||||
*
|
||||
*/
|
||||
public boolean isInPlot(final Player player) {
|
||||
public boolean isInPlot(Player player) {
|
||||
return getPlot(player) != null;
|
||||
}
|
||||
|
||||
@ -642,7 +646,7 @@ public class PlotAPI {
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.commands.SubCommand
|
||||
*/
|
||||
public void registerCommand(final SubCommand c) {
|
||||
public void registerCommand(SubCommand c) {
|
||||
if (c.getCommand() != null) {
|
||||
MainCommand.getInstance().addCommand(c);
|
||||
} else {
|
||||
@ -670,7 +674,7 @@ public class PlotAPI {
|
||||
* @return the number of plots the player has
|
||||
*
|
||||
*/
|
||||
public int getPlayerPlotCount(final World world, final Player player) {
|
||||
public int getPlayerPlotCount(World world, Player player) {
|
||||
if (world == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -689,7 +693,7 @@ public class PlotAPI {
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(final World world, final Player player) {
|
||||
public Set<Plot> getPlayerPlots(World world, Player player) {
|
||||
if (world == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
@ -704,8 +708,8 @@ public class PlotAPI {
|
||||
* @return the number of allowed plots
|
||||
*
|
||||
*/
|
||||
public int getAllowedPlots(final Player player) {
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
public int getAllowedPlots(Player player) {
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
return pp.getAllowedPlots();
|
||||
}
|
||||
|
||||
@ -718,7 +722,7 @@ public class PlotAPI {
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final Player player) {
|
||||
public PlotPlayer wrapPlayer(Player player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
@ -730,7 +734,7 @@ public class PlotAPI {
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final UUID uuid) {
|
||||
public PlotPlayer wrapPlayer(UUID uuid) {
|
||||
return PlotPlayer.wrap(uuid);
|
||||
}
|
||||
|
||||
@ -742,7 +746,7 @@ public class PlotAPI {
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final String player) {
|
||||
public PlotPlayer wrapPlayer(String player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
@ -755,7 +759,7 @@ public class PlotAPI {
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final OfflinePlayer player) {
|
||||
public PlotPlayer wrapPlayer(OfflinePlayer player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,6 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@ -139,13 +138,13 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
if (THIS != null && Bukkit.getServer().getConsoleSender() != null) {
|
||||
if (THIS != null) {
|
||||
try {
|
||||
message = C.color(message);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
this.getServer().getConsoleSender().sendMessage(message);
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
//ignored
|
||||
@ -575,13 +574,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Override
|
||||
public void startMetrics() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
log(C.PREFIX + "&6Metrics enabled.");
|
||||
} catch (IOException e) {
|
||||
log(C.PREFIX + "&cFailed to load up metrics.");
|
||||
}
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
log(C.PREFIX + "&6Metrics enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,8 +114,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a fancy message from its JSON representation. This JSON representation is of the format of
|
||||
* that returned by {@link #toJSONString()}, and is compatible with vanilla inputs.
|
||||
* Deserialize a fancy message from its JSON representation. This JSON
|
||||
* representation is of the format of hat returned by
|
||||
* {@link #toJSONString()}, and is compatible with vanilla inputs.
|
||||
* @param json The JSON string which represents a fancy message.
|
||||
* @return A {@code FancyMessage} representing the parametrized JSON message.
|
||||
*/
|
||||
|
@ -30,10 +30,6 @@ public final class Reflection {
|
||||
*/
|
||||
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
|
||||
|
||||
private Reflection() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version string from the package name of the CraftBukkit server implementation.
|
||||
* This is needed to bypass the JAR package name changing on each update.
|
||||
@ -103,7 +99,7 @@ public final class Reflection {
|
||||
* @param obj The object for which to retrieve an NMS handle.
|
||||
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
|
||||
*/
|
||||
public synchronized static Object getHandle(Object obj) {
|
||||
public static synchronized Object getHandle(Object obj) {
|
||||
try {
|
||||
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
|
||||
@ -114,8 +110,9 @@ public final class Reflection {
|
||||
|
||||
/**
|
||||
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
|
||||
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
||||
* returned will be an instance or static field.
|
||||
* Java access modifiers are ignored during this retrieval.
|
||||
* No guarantee is made as to whether the field returned will be an
|
||||
* instance or static field.
|
||||
* <p>
|
||||
* A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that
|
||||
* no field will be reflectively looked up twice.
|
||||
@ -130,7 +127,7 @@ public final class Reflection {
|
||||
* @return A field object with the specified name declared by the specified class.
|
||||
* @see Class#getDeclaredField(String)
|
||||
*/
|
||||
public synchronized static Field getField(Class<?> clazz, String name) {
|
||||
public static synchronized Field getField(Class<?> clazz, String name) {
|
||||
Map<String, Field> loaded;
|
||||
if (!_loadedFields.containsKey(clazz)) {
|
||||
loaded = new HashMap<>();
|
||||
@ -169,6 +166,7 @@ public final class Reflection {
|
||||
* true} before it is returned.
|
||||
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This method does <em>not</em> search superclasses of the specified type for methods with the specified signature.
|
||||
* Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}.
|
||||
@ -177,7 +175,7 @@ public final class Reflection {
|
||||
* @param args The formal argument types of the method.
|
||||
* @return A method object with the specified name declared by the specified class.
|
||||
*/
|
||||
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
public static synchronized Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
if (!_loadedMethods.containsKey(clazz)) {
|
||||
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
||||
}
|
||||
|
@ -27,10 +27,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when a flag is removed from a plot
|
||||
*
|
||||
|
||||
|
||||
* Called when a flag is removed from a plot.
|
||||
*/
|
||||
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||
|
||||
@ -40,7 +37,7 @@ public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot.
|
||||
*
|
||||
* @param flag Flag that was removed
|
||||
* @param cluster PlotCluster from which the flag was removed
|
||||
@ -55,7 +52,7 @@ public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster involved
|
||||
* Get the cluster involved.
|
||||
*
|
||||
* @return PlotCluster
|
||||
*/
|
||||
@ -64,7 +61,7 @@ public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
* Get the flag involved.
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
|
@ -26,10 +26,6 @@ import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*/
|
||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@ -38,7 +34,7 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlayerClaimPlotEvent: Called when a plot is claimed
|
||||
* PlayerClaimPlotEvent: Called when a plot is claimed.
|
||||
*
|
||||
* @param player Player that claimed the plot
|
||||
* @param plot Plot that was claimed
|
||||
|
@ -25,17 +25,13 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*/
|
||||
public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||
* Called when a player leaves a plot.
|
||||
*
|
||||
* @param player Player that entered the plot
|
||||
* @param plot Plot that was entered
|
||||
@ -50,7 +46,7 @@ public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
* Get the plot involved.
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
|
@ -26,10 +26,6 @@ import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*/
|
||||
public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@ -38,7 +34,7 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
|
||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot.
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
@ -57,7 +53,7 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user was added
|
||||
* If a user was added.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@ -66,7 +62,7 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
* The player added/removed.
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
@ -75,7 +71,7 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
* The player initiating the action.
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
|
@ -28,8 +28,6 @@ import org.bukkit.event.HandlerList;
|
||||
/**
|
||||
* Called when a plot is cleared
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class PlotClearEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
@ -44,7 +42,7 @@ public class PlotClearEvent extends PlotEvent implements Cancellable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
* Get the PlotId.
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
@ -53,7 +51,7 @@ public class PlotClearEvent extends PlotEvent implements Cancellable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
* Get the world name.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
|
@ -27,8 +27,6 @@ import org.bukkit.event.HandlerList;
|
||||
/**
|
||||
* Called when a plot is deleted
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class PlotDeleteEvent extends PlotEvent {
|
||||
|
||||
|
@ -26,10 +26,8 @@ import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when a Flag is added to a plot
|
||||
* Called when a Flag is added to a plot.
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
@ -38,7 +36,7 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagAddEvent: Called when a Flag is added to a plot
|
||||
* PlotFlagAddEvent: Called when a Flag is added to a plot.
|
||||
*
|
||||
* @param flag Flag that was added
|
||||
* @param plot Plot to which the flag was added
|
||||
@ -53,7 +51,7 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
* Get the flag involved.
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
|
@ -28,8 +28,6 @@ import org.bukkit.event.HandlerList;
|
||||
/**
|
||||
* Called when a flag is removed from a plot
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
|
@ -24,21 +24,16 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
public class PlotMergeEvent extends Event implements Cancellable {
|
||||
public class PlotMergeEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final ArrayList<PlotId> plots;
|
||||
private final World world;
|
||||
private boolean cancelled;
|
||||
private Plot plot;
|
||||
private World world;
|
||||
|
||||
/**
|
||||
* PlotMergeEvent: Called when plots are merged
|
||||
@ -48,6 +43,8 @@ public class PlotMergeEvent extends Event implements Cancellable {
|
||||
* @param plots A list of plots involved in the event
|
||||
*/
|
||||
public PlotMergeEvent(World world, Plot plot, ArrayList<PlotId> plots) {
|
||||
super(plot);
|
||||
this.world = world;
|
||||
this.plots = plots;
|
||||
}
|
||||
|
||||
@ -56,7 +53,7 @@ public class PlotMergeEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots being added;
|
||||
* Get the plots being added.
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
@ -64,15 +61,6 @@ public class PlotMergeEvent extends Event implements Cancellable {
|
||||
return this.plots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main plot
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
@ -5,11 +5,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Created 2015-07-13 for PlotSquaredGit
|
||||
*
|
||||
|
||||
*/
|
||||
public class PlotRateEvent extends PlotEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -29,9 +29,6 @@ import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
public class PlotUnlinkEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@ -57,9 +54,9 @@ public class PlotUnlinkEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots involved
|
||||
* Get the plots involved.
|
||||
*
|
||||
* @return PlotId
|
||||
* @return The {@link PlotId}'s of the plots involved
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return this.plots;
|
||||
|
@ -257,8 +257,8 @@ public class ChunkListener implements Listener {
|
||||
this.lastChunk = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanChunk(final Chunk chunk) {
|
||||
|
||||
private void cleanChunk(final Chunk chunk) {
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
|
@ -7,9 +7,9 @@ import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
public class DefaultTitle extends AbstractTitle {
|
||||
|
||||
@Override
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||
try {
|
||||
final DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out);
|
||||
DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out);
|
||||
title.send(((BukkitPlayer) player).player);
|
||||
} catch (Throwable e) {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_183();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.plotsquared.bukkit.titles;
|
||||
|
||||
import com.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -121,10 +122,10 @@ public class DefaultTitleManager {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private void loadClasses() throws ClassNotFoundException {
|
||||
this.packetTitle = getNMSClass("PacketPlayOutTitle");
|
||||
this.packetActions = getNMSClass("EnumTitleAction");
|
||||
this.chatBaseComponent = getNMSClass("IChatBaseComponent");
|
||||
this.nmsChatSerializer = getNMSClass("ChatSerializer");
|
||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
||||
this.packetActions = Reflection.getNMSClass("EnumTitleAction");
|
||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,16 +344,6 @@ public class DefaultTitleManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
private Class<?> getNMSClass(String className) throws ClassNotFoundException {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
return Class.forName(fullName);
|
||||
}
|
||||
|
||||
private Field getField(Class<?> clazz, String name) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.plotsquared.bukkit.titles;
|
||||
|
||||
import com.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -127,10 +128,10 @@ public class DefaultTitleManager_183 {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private void loadClasses() throws ClassNotFoundException {
|
||||
this.packetTitle = getNMSClass("PacketPlayOutTitle");
|
||||
this.chatBaseComponent = getNMSClass("IChatBaseComponent");
|
||||
this.packetActions = getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
||||
this.nmsChatSerializer = getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
|
||||
}
|
||||
|
||||
@ -366,23 +367,12 @@ public class DefaultTitleManager_183 {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
String version = name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
return version;
|
||||
}
|
||||
|
||||
private Class<?> getNMSClass(String className) throws ClassNotFoundException {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
return Class.forName(fullName);
|
||||
}
|
||||
|
||||
private Field getField(Class<?> clazz, String name) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
@ -5,12 +5,13 @@ import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
|
||||
public class DefaultTitle_183 extends AbstractTitle {
|
||||
|
||||
@Override
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||
try {
|
||||
final DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, in, delay, out);
|
||||
DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, in, delay, out);
|
||||
title.send(((BukkitPlayer) player).player);
|
||||
} catch (final Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
AbstractTitle.TITLE_CLASS = new HackTitle();
|
||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
||||
}
|
||||
|
@ -7,19 +7,19 @@ import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DefaultTitle_19 extends AbstractTitle {
|
||||
|
||||
@Override
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||
try {
|
||||
final Player playerObj = ((BukkitPlayer) player).player;
|
||||
playerObj.sendTitle(head,sub);
|
||||
playerObj.sendTitle(head, sub);
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
playerObj.sendTitle("","");
|
||||
playerObj.sendTitle("", "");
|
||||
}
|
||||
}, delay * 20);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle();
|
||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
||||
}
|
||||
|
@ -7,10 +7,11 @@ import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
|
||||
public class HackTitle extends AbstractTitle {
|
||||
|
||||
@Override
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||
try {
|
||||
final HackTitleManager title = new HackTitleManager(head, sub, in, delay, out);
|
||||
HackTitleManager title = new HackTitleManager(head, sub, in, delay, out);
|
||||
title.send(((BukkitPlayer) player).player);
|
||||
} catch (Throwable e) {
|
||||
PS.debug("&cYour server version does not support titles!");
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.plotsquared.bukkit.titles;
|
||||
|
||||
import com.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -118,7 +119,7 @@ public class HackTitleManager {
|
||||
private void loadClasses() throws ClassNotFoundException {
|
||||
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
||||
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
||||
this.nmsChatSerializer = getNMSClass("ChatSerializer");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,14 +243,16 @@ public class HackTitleManager {
|
||||
// Send title
|
||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[0], serialized);
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
||||
.newInstance(actions[0], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
if (!this.subtitle.isEmpty()) {
|
||||
// Send subtitle if present
|
||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name()
|
||||
.toLowerCase() + "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[1], serialized);
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
||||
.newInstance(actions[1], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
}
|
||||
@ -381,16 +384,6 @@ public class HackTitleManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
private Class<?> getNMSClass(String className) throws ClassNotFoundException {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
return Class.forName(fullName);
|
||||
}
|
||||
|
||||
private Field getField(Class<?> clazz, String name) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
|
@ -38,7 +38,6 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
private final SendChunk chunksender;
|
||||
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
private final RefMethod methodGetHandleChunk;
|
||||
private final RefConstructor MapChunk;
|
||||
private final RefMethod methodInitLighting;
|
||||
private final RefConstructor classBlockPositionConstructor;
|
||||
private final RefConstructor classChunkSectionConstructor;
|
||||
@ -53,8 +52,6 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||
this.MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||
RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
||||
this.classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||
RefClass classWorld = getRefClass("{nms}.World");
|
||||
|
@ -11,26 +11,27 @@ import org.bukkit.OfflinePlayer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@Override
|
||||
public UUID getUUID(PlotPlayer player) {
|
||||
return ((BukkitPlayer) player).player.getUniqueId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(OfflinePlotPlayer player) {
|
||||
return player.getUUID();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name) {
|
||||
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||
@ -40,7 +41,7 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||
|
@ -1,106 +1,32 @@
|
||||
package com.plotsquared.bukkit.uuid;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
|
||||
private final Object[] arg = new Object[0];
|
||||
private Method getOnline = null;
|
||||
|
||||
public LowerOfflineUUIDWrapper() {
|
||||
try {
|
||||
this.getOnline = Server.class.getMethod("getOnlinePlayers");
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(PlotPlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(OfflinePlotPlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(OfflinePlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
||||
String name;
|
||||
try {
|
||||
name = map.get(uuid).value;
|
||||
} catch (NullPointerException e) {
|
||||
name = null;
|
||||
}
|
||||
if (name != null) {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(name);
|
||||
if (op.hasPlayedBefore()) {
|
||||
return new BukkitOfflinePlayer(op);
|
||||
}
|
||||
}
|
||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||
if (getUUID(player).equals(uuid)) {
|
||||
return new BukkitOfflinePlayer(player);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player[] getOnlinePlayers() {
|
||||
if (this.getOnline == null) {
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||
}
|
||||
try {
|
||||
Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
|
||||
if (players instanceof Player[]) {
|
||||
return (Player[]) players;
|
||||
} else {
|
||||
@SuppressWarnings("unchecked") Collection<? extends Player> p = (Collection<? extends Player>) players;
|
||||
return p.toArray(new Player[p.size()]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
PS.debug("Failed to resolve online players");
|
||||
this.getOnline = null;
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
||||
for (int i = 0; i < ops.length; i++) {
|
||||
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,9 +19,10 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
private final Object[] arg = new Object[0];
|
||||
private Method getOnline = null;
|
||||
|
||||
|
||||
public OfflineUUIDWrapper() {
|
||||
try {
|
||||
this.getOnline = Server.class.getMethod("getOnlinePlayers");
|
||||
@ -29,12 +30,12 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(PlotPlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(OfflinePlotPlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
@ -43,7 +44,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
public UUID getUUID(OfflinePlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
||||
@ -66,7 +67,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Player[] getOnlinePlayers() {
|
||||
if (this.getOnline == null) {
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
@ -87,12 +88,12 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||
@ -102,7 +103,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||
|
@ -70,7 +70,7 @@ public class JSONObject {
|
||||
* Construct an empty JSONObject.
|
||||
*/
|
||||
public JSONObject() {
|
||||
map = new HashMap<String, Object>();
|
||||
this.map = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,9 +83,9 @@ public class JSONObject {
|
||||
* @throws JSONException
|
||||
* @throws JSONException If a value is a non-finite number or if a name is duplicated.
|
||||
*/
|
||||
public JSONObject(final JSONObject jo, final String[] names) {
|
||||
public JSONObject(JSONObject jo, String[] names) {
|
||||
this();
|
||||
for (final String name : names) {
|
||||
for (String name : names) {
|
||||
try {
|
||||
putOnce(name, jo.opt(name));
|
||||
} catch (JSONException ignore) {
|
||||
@ -100,7 +100,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If there is a syntax error in the source string or a duplicated key.
|
||||
*/
|
||||
public JSONObject(final JSONTokener x) throws JSONException {
|
||||
public JSONObject(JSONTokener x) throws JSONException {
|
||||
this();
|
||||
char c;
|
||||
String key;
|
||||
@ -148,11 +148,11 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public JSONObject(final Map<String, Object> map) {
|
||||
public JSONObject(Map<String, Object> map) {
|
||||
this.map = new HashMap<String, Object>();
|
||||
if (map != null) {
|
||||
for (final Entry<String, Object> entry : map.entrySet()) {
|
||||
final Object value = entry.getValue();
|
||||
for (Entry<String, Object> entry : map.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if (value != null) {
|
||||
this.map.put(entry.getKey(), wrap(value));
|
||||
}
|
||||
@ -175,7 +175,7 @@ public class JSONObject {
|
||||
*
|
||||
* @param bean An object that has getter methods that should be used to make a JSONObject.
|
||||
*/
|
||||
public JSONObject(final Object bean) {
|
||||
public JSONObject(Object bean) {
|
||||
this();
|
||||
populateMap(bean);
|
||||
}
|
||||
@ -188,10 +188,10 @@ public class JSONObject {
|
||||
* @param object An object that has fields that should be used to make a JSONObject.
|
||||
* @param names An array of strings, the names of the fields to be obtained from the object.
|
||||
*/
|
||||
public JSONObject(final Object object, final String names[]) {
|
||||
public JSONObject(Object object, String names[]) {
|
||||
this();
|
||||
final Class c = object.getClass();
|
||||
for (final String name : names) {
|
||||
Class c = object.getClass();
|
||||
for (String name : names) {
|
||||
try {
|
||||
putOpt(name, c.getField(name).get(object));
|
||||
} catch (JSONException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignore) {
|
||||
@ -207,7 +207,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If there is a syntax error in the source string or a duplicated key.
|
||||
*/
|
||||
public JSONObject(final String source) throws JSONException {
|
||||
public JSONObject(String source) throws JSONException {
|
||||
this(new JSONTokener(source));
|
||||
}
|
||||
|
||||
@ -219,24 +219,24 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If any JSONExceptions are detected.
|
||||
*/
|
||||
public JSONObject(final String baseName, final Locale locale) throws JSONException {
|
||||
public JSONObject(String baseName, Locale locale) throws JSONException {
|
||||
this();
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
|
||||
// Iterate through the keys in the bundle.
|
||||
final Enumeration<String> keys = bundle.getKeys();
|
||||
Enumeration<String> keys = bundle.getKeys();
|
||||
while (keys.hasMoreElements()) {
|
||||
final Object key = keys.nextElement();
|
||||
Object key = keys.nextElement();
|
||||
if (key != null) {
|
||||
// Go through the path, ensuring that there is a nested
|
||||
// JSONObject for each
|
||||
// segment except the last. Add the value using the last
|
||||
// segment's name into
|
||||
// the deepest nested JSONObject.
|
||||
final String[] path = ((String) key).split("\\.");
|
||||
final int last = path.length - 1;
|
||||
String[] path = ((String) key).split("\\.");
|
||||
int last = path.length - 1;
|
||||
JSONObject target = this;
|
||||
for (int i = 0; i < last; i += 1) {
|
||||
final String segment = path[i];
|
||||
String segment = path[i];
|
||||
JSONObject nextTarget = target.optJSONObject(segment);
|
||||
if (nextTarget == null) {
|
||||
nextTarget = new JSONObject();
|
||||
@ -256,7 +256,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return A String.
|
||||
*/
|
||||
public static String doubleToString(final double d) {
|
||||
public static String doubleToString(double d) {
|
||||
if (Double.isInfinite(d) || Double.isNaN(d)) {
|
||||
return "null";
|
||||
}
|
||||
@ -278,13 +278,13 @@ public class JSONObject {
|
||||
*
|
||||
* @return An array of field names, or null if there are no names.
|
||||
*/
|
||||
public static String[] getNames(final JSONObject jo) {
|
||||
final int length = jo.length();
|
||||
public static String[] getNames(JSONObject jo) {
|
||||
int length = jo.length();
|
||||
if (length == 0) {
|
||||
return null;
|
||||
}
|
||||
final Iterator<String> iterator = jo.keys();
|
||||
final String[] names = new String[length];
|
||||
Iterator<String> iterator = jo.keys();
|
||||
String[] names = new String[length];
|
||||
int i = 0;
|
||||
while (iterator.hasNext()) {
|
||||
names[i] = iterator.next();
|
||||
@ -298,17 +298,17 @@ public class JSONObject {
|
||||
*
|
||||
* @return An array of field names, or null if there are no names.
|
||||
*/
|
||||
public static String[] getNames(final Object object) {
|
||||
public static String[] getNames(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
final Class klass = object.getClass();
|
||||
final Field[] fields = klass.getFields();
|
||||
final int length = fields.length;
|
||||
Class klass = object.getClass();
|
||||
Field[] fields = klass.getFields();
|
||||
int length = fields.length;
|
||||
if (length == 0) {
|
||||
return null;
|
||||
}
|
||||
final String[] names = new String[length];
|
||||
String[] names = new String[length];
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
names[i] = fields[i].getName();
|
||||
}
|
||||
@ -324,7 +324,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If n is a non-finite number.
|
||||
*/
|
||||
public static String numberToString(final Number number) throws JSONException {
|
||||
public static String numberToString(Number number) throws JSONException {
|
||||
if (number == null) {
|
||||
throw new JSONException("Null pointer");
|
||||
}
|
||||
@ -350,19 +350,19 @@ public class JSONObject {
|
||||
*
|
||||
* @return A String correctly formatted for insertion in a JSON text.
|
||||
*/
|
||||
public static String quote(final String string) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
public static String quote(String string) {
|
||||
StringWriter sw = new StringWriter();
|
||||
synchronized (sw.getBuffer()) {
|
||||
try {
|
||||
return quote(string, sw).toString();
|
||||
} catch (final IOException ignored) {
|
||||
} catch (IOException ignored) {
|
||||
// will never happen - we are writing to a string writer
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Writer quote(final String string, final Writer w) throws IOException {
|
||||
|
||||
public static Writer quote(String string, Writer w) throws IOException {
|
||||
if ((string == null) || string.isEmpty()) {
|
||||
w.write("\"\"");
|
||||
return w;
|
||||
@ -371,7 +371,7 @@ public class JSONObject {
|
||||
char c = 0;
|
||||
String hhhh;
|
||||
int i;
|
||||
final int len = string.length();
|
||||
int len = string.length();
|
||||
w.write('"');
|
||||
for (i = 0; i < len; i += 1) {
|
||||
b = c;
|
||||
@ -425,7 +425,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return A simple JSON value.
|
||||
*/
|
||||
public static Object stringToValue(final String string) {
|
||||
public static Object stringToValue(String string) {
|
||||
Double d;
|
||||
if (string.isEmpty()) {
|
||||
return string;
|
||||
@ -443,7 +443,7 @@ public class JSONObject {
|
||||
* If it might be a number, try converting it. If a number cannot be
|
||||
* produced, then the value will just be a string.
|
||||
*/
|
||||
final char b = string.charAt(0);
|
||||
char b = string.charAt(0);
|
||||
if (((b >= '0') && (b <= '9')) || (b == '-')) {
|
||||
try {
|
||||
if ((string.indexOf('.') > -1) || (string.indexOf('e') > -1) || (string.indexOf('E') > -1)) {
|
||||
@ -452,7 +452,7 @@ public class JSONObject {
|
||||
return d;
|
||||
}
|
||||
} else {
|
||||
final Long myLong = Long.valueOf(string);
|
||||
Long myLong = Long.valueOf(string);
|
||||
if (string.equals(myLong.toString())) {
|
||||
if (myLong == myLong.intValue()) {
|
||||
return myLong.intValue();
|
||||
@ -474,7 +474,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If o is a non-finite number.
|
||||
*/
|
||||
public static void testValidity(final Object o) throws JSONException {
|
||||
public static void testValidity(Object o) throws JSONException {
|
||||
if (o != null) {
|
||||
if (o instanceof Double) {
|
||||
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
|
||||
@ -507,7 +507,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the value is or contains an invalid number.
|
||||
*/
|
||||
public static String valueToString(final Object value) throws JSONException {
|
||||
public static String valueToString(Object value) throws JSONException {
|
||||
if ((value == null) || value.equals(null)) {
|
||||
return "null";
|
||||
}
|
||||
@ -515,7 +515,7 @@ public class JSONObject {
|
||||
Object object;
|
||||
try {
|
||||
object = ((JSONString) value).toJSONString();
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
if (object != null) {
|
||||
@ -551,7 +551,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return The wrapped value
|
||||
*/
|
||||
public static Object wrap(final Object object) {
|
||||
public static Object wrap(Object object) {
|
||||
try {
|
||||
if (object == null) {
|
||||
return NULL;
|
||||
@ -580,8 +580,8 @@ public class JSONObject {
|
||||
if (object instanceof Map) {
|
||||
return new JSONObject((Map<String, Object>) object);
|
||||
}
|
||||
final Package objectPackage = object.getClass().getPackage();
|
||||
final String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
|
||||
Package objectPackage = object.getClass().getPackage();
|
||||
String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
|
||||
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || (object.getClass().getClassLoader() == null)) {
|
||||
return object.toString();
|
||||
}
|
||||
@ -590,8 +590,8 @@ public class JSONObject {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static final Writer writeValue(final Writer writer, final Object value, final int indentFactor, final int indent) throws JSONException, IOException {
|
||||
|
||||
static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException {
|
||||
if ((value == null) || value.equals(null)) {
|
||||
writer.write("null");
|
||||
} else if (value instanceof JSONObject) {
|
||||
@ -612,7 +612,7 @@ public class JSONObject {
|
||||
Object o;
|
||||
try {
|
||||
o = ((JSONString) value).toJSONString();
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
writer.write(o != null ? o.toString() : quote(value.toString()));
|
||||
@ -621,8 +621,8 @@ public class JSONObject {
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
static final void indent(final Writer writer, final int indent) throws IOException {
|
||||
|
||||
static final void indent(Writer writer, int indent) throws IOException {
|
||||
for (int i = 0; i < indent; i += 1) {
|
||||
writer.write(' ');
|
||||
}
|
||||
@ -643,9 +643,9 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the value is an invalid number or if the key is null.
|
||||
*/
|
||||
public JSONObject accumulate(final String key, final Object value) throws JSONException {
|
||||
public JSONObject accumulate(String key, Object value) throws JSONException {
|
||||
testValidity(value);
|
||||
final Object object = opt(key);
|
||||
Object object = opt(key);
|
||||
if (object == null) {
|
||||
this.put(key, value instanceof JSONArray ? new JSONArray().put(value) : value);
|
||||
} else if (object instanceof JSONArray) {
|
||||
@ -668,9 +668,9 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the key is null or if the current value associated with the key is not a JSONArray.
|
||||
*/
|
||||
public JSONObject append(final String key, final Object value) throws JSONException {
|
||||
public JSONObject append(String key, Object value) throws JSONException {
|
||||
testValidity(value);
|
||||
final Object object = opt(key);
|
||||
Object object = opt(key);
|
||||
if (object == null) {
|
||||
this.put(key, new JSONArray().put(value));
|
||||
} else if (object instanceof JSONArray) {
|
||||
@ -690,11 +690,11 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if the key is not found.
|
||||
*/
|
||||
public Object get(final String key) throws JSONException {
|
||||
public Object get(String key) throws JSONException {
|
||||
if (key == null) {
|
||||
throw new JSONException("Null key.");
|
||||
}
|
||||
final Object object = opt(key);
|
||||
Object object = opt(key);
|
||||
if (object == null) {
|
||||
throw new JSONException("JSONObject[" + quote(key) + "] not found.");
|
||||
}
|
||||
@ -710,8 +710,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if the value is not a Boolean or the String "true" or "false".
|
||||
*/
|
||||
public boolean getBoolean(final String key) throws JSONException {
|
||||
final Object object = get(key);
|
||||
public boolean getBoolean(String key) throws JSONException {
|
||||
Object object = get(key);
|
||||
if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
|
||||
return false;
|
||||
} else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
|
||||
@ -730,8 +730,8 @@ public class JSONObject {
|
||||
* @throws JSONException if the key is not found or if the value is not a Number object and cannot be converted to a
|
||||
* number.
|
||||
*/
|
||||
public double getDouble(final String key) throws JSONException {
|
||||
final Object object = get(key);
|
||||
public double getDouble(String key) throws JSONException {
|
||||
Object object = get(key);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
|
||||
} catch (NumberFormatException e) {
|
||||
@ -748,8 +748,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if the key is not found or if the value cannot be converted to an integer.
|
||||
*/
|
||||
public int getInt(final String key) throws JSONException {
|
||||
final Object object = get(key);
|
||||
public int getInt(String key) throws JSONException {
|
||||
Object object = get(key);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
|
||||
} catch (NumberFormatException e) {
|
||||
@ -766,8 +766,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if the key is not found or if the value is not a JSONArray.
|
||||
*/
|
||||
public JSONArray getJSONArray(final String key) throws JSONException {
|
||||
final Object object = get(key);
|
||||
public JSONArray getJSONArray(String key) throws JSONException {
|
||||
Object object = get(key);
|
||||
if (object instanceof JSONArray) {
|
||||
return (JSONArray) object;
|
||||
}
|
||||
@ -783,8 +783,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if the key is not found or if the value is not a JSONObject.
|
||||
*/
|
||||
public JSONObject getJSONObject(final String key) throws JSONException {
|
||||
final Object object = get(key);
|
||||
public JSONObject getJSONObject(String key) throws JSONException {
|
||||
Object object = get(key);
|
||||
if (object instanceof JSONObject) {
|
||||
return (JSONObject) object;
|
||||
}
|
||||
@ -800,8 +800,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if the key is not found or if the value cannot be converted to a long.
|
||||
*/
|
||||
public long getLong(final String key) throws JSONException {
|
||||
final Object object = get(key);
|
||||
public long getLong(String key) throws JSONException {
|
||||
Object object = get(key);
|
||||
try {
|
||||
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
|
||||
} catch (NumberFormatException e) {
|
||||
@ -818,8 +818,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if there is no string value for the key.
|
||||
*/
|
||||
public String getString(final String key) throws JSONException {
|
||||
final Object object = get(key);
|
||||
public String getString(String key) throws JSONException {
|
||||
Object object = get(key);
|
||||
if (object instanceof String) {
|
||||
return (String) object;
|
||||
}
|
||||
@ -833,8 +833,8 @@ public class JSONObject {
|
||||
*
|
||||
* @return true if the key exists in the JSONObject.
|
||||
*/
|
||||
public boolean has(final String key) {
|
||||
return map.containsKey(key);
|
||||
public boolean has(String key) {
|
||||
return this.map.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -848,8 +848,8 @@ public class JSONObject {
|
||||
* @throws JSONException If there is already a property with this name that is not an Integer, Long, Double, or
|
||||
* Float.
|
||||
*/
|
||||
public JSONObject increment(final String key) throws JSONException {
|
||||
final Object value = opt(key);
|
||||
public JSONObject increment(String key) throws JSONException {
|
||||
Object value = opt(key);
|
||||
if (value == null) {
|
||||
this.put(key, 1);
|
||||
} else if (value instanceof Integer) {
|
||||
@ -873,7 +873,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return true if there is no value associated with the key or if the value is the JSONObject.NULL object.
|
||||
*/
|
||||
public boolean isNull(final String key) {
|
||||
public boolean isNull(String key) {
|
||||
return JSONObject.NULL.equals(opt(key));
|
||||
}
|
||||
|
||||
@ -892,7 +892,7 @@ public class JSONObject {
|
||||
* @return A keySet.
|
||||
*/
|
||||
public Set<String> keySet() {
|
||||
return map.keySet();
|
||||
return this.map.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -901,7 +901,7 @@ public class JSONObject {
|
||||
* @return The number of keys in the JSONObject.
|
||||
*/
|
||||
public int length() {
|
||||
return map.size();
|
||||
return this.map.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -910,8 +910,8 @@ public class JSONObject {
|
||||
* @return A JSONArray containing the key strings, or null if the JSONObject is empty.
|
||||
*/
|
||||
public JSONArray names() {
|
||||
final JSONArray ja = new JSONArray();
|
||||
final Iterator<String> keys = keys();
|
||||
JSONArray ja = new JSONArray();
|
||||
Iterator<String> keys = keys();
|
||||
while (keys.hasNext()) {
|
||||
ja.put(keys.next());
|
||||
}
|
||||
@ -925,8 +925,8 @@ public class JSONObject {
|
||||
*
|
||||
* @return An object which is the value, or null if there is no value.
|
||||
*/
|
||||
public Object opt(final String key) {
|
||||
return key == null ? null : map.get(key);
|
||||
public Object opt(String key) {
|
||||
return key == null ? null : this.map.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -937,7 +937,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(final String key) {
|
||||
public boolean optBoolean(String key) {
|
||||
return this.optBoolean(key, false);
|
||||
}
|
||||
|
||||
@ -950,7 +950,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(final String key, final boolean defaultValue) {
|
||||
public boolean optBoolean(String key, boolean defaultValue) {
|
||||
try {
|
||||
return getBoolean(key);
|
||||
} catch (JSONException e) {
|
||||
@ -966,7 +966,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return An object which is the value.
|
||||
*/
|
||||
public double optDouble(final String key) {
|
||||
public double optDouble(String key) {
|
||||
return this.optDouble(key, Double.NaN);
|
||||
}
|
||||
|
||||
@ -979,7 +979,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return An object which is the value.
|
||||
*/
|
||||
public double optDouble(final String key, final double defaultValue) {
|
||||
public double optDouble(String key, double defaultValue) {
|
||||
try {
|
||||
return getDouble(key);
|
||||
} catch (JSONException e) {
|
||||
@ -995,7 +995,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return An object which is the value.
|
||||
*/
|
||||
public int optInt(final String key) {
|
||||
public int optInt(String key) {
|
||||
return this.optInt(key, 0);
|
||||
}
|
||||
|
||||
@ -1008,7 +1008,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return An object which is the value.
|
||||
*/
|
||||
public int optInt(final String key, final int defaultValue) {
|
||||
public int optInt(String key, int defaultValue) {
|
||||
try {
|
||||
return getInt(key);
|
||||
} catch (JSONException e) {
|
||||
@ -1024,8 +1024,8 @@ public class JSONObject {
|
||||
*
|
||||
* @return A JSONArray which is the value.
|
||||
*/
|
||||
public JSONArray optJSONArray(final String key) {
|
||||
final Object o = opt(key);
|
||||
public JSONArray optJSONArray(String key) {
|
||||
Object o = opt(key);
|
||||
return o instanceof JSONArray ? (JSONArray) o : null;
|
||||
}
|
||||
|
||||
@ -1037,8 +1037,8 @@ public class JSONObject {
|
||||
*
|
||||
* @return A JSONObject which is the value.
|
||||
*/
|
||||
public JSONObject optJSONObject(final String key) {
|
||||
final Object object = opt(key);
|
||||
public JSONObject optJSONObject(String key) {
|
||||
Object object = opt(key);
|
||||
return object instanceof JSONObject ? (JSONObject) object : null;
|
||||
}
|
||||
|
||||
@ -1050,7 +1050,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return An object which is the value.
|
||||
*/
|
||||
public long optLong(final String key) {
|
||||
public long optLong(String key) {
|
||||
return this.optLong(key, 0);
|
||||
}
|
||||
|
||||
@ -1063,7 +1063,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return An object which is the value.
|
||||
*/
|
||||
public long optLong(final String key, final long defaultValue) {
|
||||
public long optLong(String key, long defaultValue) {
|
||||
try {
|
||||
return getLong(key);
|
||||
} catch (JSONException e) {
|
||||
@ -1079,7 +1079,7 @@ public class JSONObject {
|
||||
*
|
||||
* @return A string which is the value.
|
||||
*/
|
||||
public String optString(final String key) {
|
||||
public String optString(String key) {
|
||||
return this.optString(key, "");
|
||||
}
|
||||
|
||||
@ -1091,20 +1091,20 @@ public class JSONObject {
|
||||
*
|
||||
* @return A string which is the value.
|
||||
*/
|
||||
public String optString(final String key, final String defaultValue) {
|
||||
final Object object = opt(key);
|
||||
public String optString(String key, String defaultValue) {
|
||||
Object object = opt(key);
|
||||
return NULL.equals(object) ? defaultValue : object.toString();
|
||||
}
|
||||
|
||||
private void populateMap(final Object bean) {
|
||||
final Class klass = bean.getClass();
|
||||
|
||||
private void populateMap(Object bean) {
|
||||
Class klass = bean.getClass();
|
||||
// If klass is a System class then set includeSuperClass to false.
|
||||
final boolean includeSuperClass = klass.getClassLoader() != null;
|
||||
final Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
|
||||
for (final Method method : methods) {
|
||||
boolean includeSuperClass = klass.getClassLoader() != null;
|
||||
Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
try {
|
||||
if (Modifier.isPublic(method.getModifiers())) {
|
||||
final String name = method.getName();
|
||||
String name = method.getName();
|
||||
String key = "";
|
||||
if (name.startsWith("get")) {
|
||||
if ("getClass".equals(name) || "getDeclaringClass".equals(name)) {
|
||||
@ -1121,9 +1121,9 @@ public class JSONObject {
|
||||
} else if (!Character.isUpperCase(key.charAt(1))) {
|
||||
key = key.substring(0, 1).toLowerCase() + key.substring(1);
|
||||
}
|
||||
final Object result = method.invoke(bean, (Object[]) null);
|
||||
Object result = method.invoke(bean, (Object[]) null);
|
||||
if (result != null) {
|
||||
map.put(key, wrap(result));
|
||||
this.map.put(key, wrap(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1142,7 +1142,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the key is null.
|
||||
*/
|
||||
public JSONObject put(final String key, final boolean value) throws JSONException {
|
||||
public JSONObject put(String key, boolean value) throws JSONException {
|
||||
this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
@ -1157,7 +1157,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public JSONObject put(final String key, final Collection<Object> value) throws JSONException {
|
||||
public JSONObject put(String key, Collection<Object> value) throws JSONException {
|
||||
this.put(key, new JSONArray(value));
|
||||
return this;
|
||||
}
|
||||
@ -1172,7 +1172,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the key is null or if the number is invalid.
|
||||
*/
|
||||
public JSONObject put(final String key, final double value) throws JSONException {
|
||||
public JSONObject put(String key, double value) throws JSONException {
|
||||
this.put(key, new Double(value));
|
||||
return this;
|
||||
}
|
||||
@ -1187,8 +1187,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the key is null.
|
||||
*/
|
||||
public JSONObject put(final String key, final int value) throws JSONException {
|
||||
this.put(key, new Integer(value));
|
||||
public JSONObject put(String key, int value) throws JSONException {
|
||||
this.put(key, Integer.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -1202,8 +1202,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the key is null.
|
||||
*/
|
||||
public JSONObject put(final String key, final long value) throws JSONException {
|
||||
this.put(key, new Long(value));
|
||||
public JSONObject put(String key, long value) throws JSONException {
|
||||
this.put(key, Long.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -1217,7 +1217,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public JSONObject put(final String key, final Map<String, Object> value) throws JSONException {
|
||||
public JSONObject put(String key, Map<String, Object> value) throws JSONException {
|
||||
this.put(key, new JSONObject(value));
|
||||
return this;
|
||||
}
|
||||
@ -1234,13 +1234,13 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the value is non-finite number or if the key is null.
|
||||
*/
|
||||
public JSONObject put(final String key, final Object value) throws JSONException {
|
||||
public JSONObject put(String key, Object value) throws JSONException {
|
||||
if (key == null) {
|
||||
throw new NullPointerException("Null key.");
|
||||
}
|
||||
if (value != null) {
|
||||
testValidity(value);
|
||||
map.put(key, value);
|
||||
this.map.put(key, value);
|
||||
} else {
|
||||
remove(key);
|
||||
}
|
||||
@ -1258,7 +1258,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException if the key is a duplicate
|
||||
*/
|
||||
public JSONObject putOnce(final String key, final Object value) throws JSONException {
|
||||
public JSONObject putOnce(String key, Object value) throws JSONException {
|
||||
if ((key != null) && (value != null)) {
|
||||
if (opt(key) != null) {
|
||||
throw new JSONException("Duplicate key \"" + key + "\"");
|
||||
@ -1279,7 +1279,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the value is a non-finite number.
|
||||
*/
|
||||
public JSONObject putOpt(final String key, final Object value) throws JSONException {
|
||||
public JSONObject putOpt(String key, Object value) throws JSONException {
|
||||
if ((key != null) && (value != null)) {
|
||||
this.put(key, value);
|
||||
}
|
||||
@ -1293,8 +1293,8 @@ public class JSONObject {
|
||||
*
|
||||
* @return The value that was associated with the name, or null if there was no value.
|
||||
*/
|
||||
public Object remove(final String key) {
|
||||
return map.remove(key);
|
||||
public Object remove(String key) {
|
||||
return this.map.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1305,18 +1305,18 @@ public class JSONObject {
|
||||
*
|
||||
* @return true if they are equal
|
||||
*/
|
||||
public boolean similar(final Object other) {
|
||||
public boolean similar(Object other) {
|
||||
try {
|
||||
if (!(other instanceof JSONObject)) {
|
||||
return false;
|
||||
}
|
||||
final Set<String> set = keySet();
|
||||
Set<String> set = keySet();
|
||||
if (!set.equals(((JSONObject) other).keySet())) {
|
||||
return false;
|
||||
}
|
||||
for (final String name : set) {
|
||||
final Object valueThis = get(name);
|
||||
final Object valueOther = ((JSONObject) other).get(name);
|
||||
for (String name : set) {
|
||||
Object valueThis = get(name);
|
||||
Object valueOther = ((JSONObject) other).get(name);
|
||||
if (valueThis instanceof JSONObject) {
|
||||
if (!((JSONObject) valueThis).similar(valueOther)) {
|
||||
return false;
|
||||
@ -1330,7 +1330,7 @@ public class JSONObject {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (final Throwable exception) {
|
||||
} catch (Throwable exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1345,11 +1345,11 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If any of the values are non-finite numbers.
|
||||
*/
|
||||
public JSONArray toJSONArray(final JSONArray names) throws JSONException {
|
||||
public JSONArray toJSONArray(JSONArray names) throws JSONException {
|
||||
if ((names == null) || (names.length() == 0)) {
|
||||
return null;
|
||||
}
|
||||
final JSONArray ja = new JSONArray();
|
||||
JSONArray ja = new JSONArray();
|
||||
for (int i = 0; i < names.length(); i += 1) {
|
||||
ja.put(opt(names.getString(i)));
|
||||
}
|
||||
@ -1388,8 +1388,8 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException If the object contains an invalid number.
|
||||
*/
|
||||
public String toString(final int indentFactor) throws JSONException {
|
||||
final StringWriter w = new StringWriter();
|
||||
public String toString(int indentFactor) throws JSONException {
|
||||
StringWriter w = new StringWriter();
|
||||
synchronized (w.getBuffer()) {
|
||||
return this.write(w, indentFactor, 0).toString();
|
||||
}
|
||||
@ -1404,7 +1404,7 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public Writer write(final Writer writer) throws JSONException {
|
||||
public Writer write(Writer writer) throws JSONException {
|
||||
return this.write(writer, 0, 0);
|
||||
}
|
||||
|
||||
@ -1417,24 +1417,24 @@ public class JSONObject {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException {
|
||||
Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
|
||||
try {
|
||||
boolean commanate = false;
|
||||
final int length = length();
|
||||
final Iterator<String> keys = keys();
|
||||
int length = length();
|
||||
Iterator<String> keys = keys();
|
||||
writer.write('{');
|
||||
if (length == 1) {
|
||||
final Object key = keys.next();
|
||||
Object key = keys.next();
|
||||
writer.write(quote(key.toString()));
|
||||
writer.write(':');
|
||||
if (indentFactor > 0) {
|
||||
writer.write(' ');
|
||||
}
|
||||
writeValue(writer, map.get(key), indentFactor, indent);
|
||||
writeValue(writer, this.map.get(key), indentFactor, indent);
|
||||
} else if (length != 0) {
|
||||
final int newindent = indent + indentFactor;
|
||||
int newindent = indent + indentFactor;
|
||||
while (keys.hasNext()) {
|
||||
final Object key = keys.next();
|
||||
Object key = keys.next();
|
||||
if (commanate) {
|
||||
writer.write(',');
|
||||
}
|
||||
@ -1447,7 +1447,7 @@ public class JSONObject {
|
||||
if (indentFactor > 0) {
|
||||
writer.write(' ');
|
||||
}
|
||||
writeValue(writer, map.get(key), indentFactor, newindent);
|
||||
writeValue(writer, this.map.get(key), indentFactor, newindent);
|
||||
commanate = true;
|
||||
}
|
||||
if (indentFactor > 0) {
|
||||
@ -1457,7 +1457,7 @@ public class JSONObject {
|
||||
}
|
||||
writer.write('}');
|
||||
return writer;
|
||||
} catch (final IOException exception) {
|
||||
} catch (IOException exception) {
|
||||
throw new JSONException(exception);
|
||||
}
|
||||
}
|
||||
@ -1489,7 +1489,7 @@ public class JSONObject {
|
||||
* @return true if the object parameter is the JSONObject.NULL object or null.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
public boolean equals(Object object) {
|
||||
return (object == null) || (object == this);
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,10 @@ class XML {
|
||||
static final Character QUOT = '"';
|
||||
static final Character SLASH = '/';
|
||||
|
||||
static String escape(final String string) {
|
||||
final StringBuilder sb = new StringBuilder(string.length());
|
||||
static String escape(String string) {
|
||||
StringBuilder sb = new StringBuilder(string.length());
|
||||
for (int i = 0, length = string.length(); i < length; i++) {
|
||||
final char c = string.charAt(i);
|
||||
char c = string.charAt(i);
|
||||
switch (c) {
|
||||
case '&':
|
||||
sb.append("&");
|
||||
@ -54,8 +54,8 @@ class XML {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
static void noSpace(final String string) throws JSONException {
|
||||
final int length = string.length();
|
||||
static void noSpace(String string) throws JSONException {
|
||||
int length = string.length();
|
||||
if (length == 0) {
|
||||
throw new JSONException("Empty string.");
|
||||
}
|
||||
@ -77,7 +77,7 @@ class XML {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
private static boolean parse(final XMLTokener x, final JSONObject context, final String name) throws JSONException {
|
||||
private static boolean parse(XMLTokener x, JSONObject context, String name) throws JSONException {
|
||||
// Test for and skip past these forms:
|
||||
// <!-- ... -->
|
||||
// <! ... >
|
||||
@ -220,7 +220,7 @@ class XML {
|
||||
*
|
||||
* @return A simple JSON value.
|
||||
*/
|
||||
static Object stringToValue(final String string) {
|
||||
static Object stringToValue(String string) {
|
||||
if ("true".equalsIgnoreCase(string)) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
@ -232,16 +232,16 @@ class XML {
|
||||
}
|
||||
//If it might be a number, try converting it, first as a Long, and then as a Double. If that doesn't work, return the string.
|
||||
try {
|
||||
final char initial = string.charAt(0);
|
||||
char initial = string.charAt(0);
|
||||
if ((initial == '-') || ((initial >= '0') && (initial <= '9'))) {
|
||||
final Long value = new Long(string);
|
||||
Long value = Long.valueOf(string);
|
||||
if (value.toString().equals(string)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException ignore) {
|
||||
try {
|
||||
final Double value = new Double(string);
|
||||
Double value = Double.valueOf(string);
|
||||
if (value.toString().equals(string)) {
|
||||
return value;
|
||||
}
|
||||
@ -250,10 +250,10 @@ class XML {
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
final JSONObject jo = new JSONObject();
|
||||
final XMLTokener x = new XMLTokener(string);
|
||||
|
||||
public static JSONObject toJSONObject(String string) throws JSONException {
|
||||
JSONObject jo = new JSONObject();
|
||||
XMLTokener x = new XMLTokener(string);
|
||||
while (x.more() && x.skipPast("<")) {
|
||||
parse(x, jo, null);
|
||||
}
|
||||
@ -269,7 +269,7 @@ class XML {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(final Object object) throws JSONException {
|
||||
public static String toString(Object object) throws JSONException {
|
||||
return toString(object, null);
|
||||
}
|
||||
|
||||
@ -283,8 +283,8 @@ class XML {
|
||||
*
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(Object object, final String tagName) throws JSONException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
public static String toString(Object object, String tagName) throws JSONException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i;
|
||||
JSONArray ja;
|
||||
int length;
|
||||
@ -371,7 +371,7 @@ class XML {
|
||||
} else {
|
||||
string = escape(object.toString());
|
||||
return (tagName == null) ? "\"" + string + "\"" :
|
||||
(string.isEmpty()) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
|
||||
string.isEmpty() ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,8 @@ public class PS {
|
||||
log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!");
|
||||
log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!");
|
||||
log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!");
|
||||
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
|
||||
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the "
|
||||
+ "'settings.yml'");
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
@ -304,7 +305,9 @@ public class PS {
|
||||
}
|
||||
if (!WorldUtil.IMP.isWorld(world)) {
|
||||
PS.debug("&c`" + world + "` was not properly loaded - PlotSquared will now try to load it properly: ");
|
||||
PS.debug("&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and multiverse worlds.yml");
|
||||
PS.debug(
|
||||
"&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and "
|
||||
+ "multiverse worlds.yml");
|
||||
PS.debug("&8 - &7Your world management plugin may be faulty (or non existant)");
|
||||
PS.this.IMP.setGenerator(world);
|
||||
}
|
||||
@ -367,7 +370,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `version` is >= `version2`
|
||||
* Check if `version` is >= `version2`.
|
||||
* @param version
|
||||
* @param version2
|
||||
* @return true if `version` is >= `version2`
|
||||
@ -378,7 +381,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last PlotSquared version
|
||||
* Get the last PlotSquared version.
|
||||
* @return last version in config or null
|
||||
*/
|
||||
public int[] getLastVersion() {
|
||||
@ -386,7 +389,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current PlotSquared version
|
||||
* Get the current PlotSquared version.
|
||||
* @return current version in config or null
|
||||
*/
|
||||
public int[] getVersion() {
|
||||
@ -403,7 +406,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database object
|
||||
* Get the database object.
|
||||
*
|
||||
* @return Database object
|
||||
* @see Database#getConnection() To get the database connection
|
||||
@ -1112,7 +1115,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots by a PlotPlayer
|
||||
* Get all plots by a PlotPlayer.
|
||||
* @param world
|
||||
* @param player
|
||||
* @return Set of plot
|
||||
@ -1123,7 +1126,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots by a PlotPlayer
|
||||
* Get all plots by a PlotPlayer.
|
||||
* @param area
|
||||
* @param player
|
||||
* @return Set of plot
|
||||
@ -1134,7 +1137,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots by a UUID in a world
|
||||
* Get all plots by a UUID in a world.
|
||||
* @param world
|
||||
* @param uuid
|
||||
* @return Set of plot
|
||||
@ -1152,7 +1155,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots by a UUID in an area
|
||||
* Get all plots by a UUID in an area.
|
||||
* @param area
|
||||
* @param uuid
|
||||
* @return Set of plot
|
||||
@ -1170,7 +1173,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #hasPlotArea(String)}<br>
|
||||
* Use {@link #hasPlotArea(String)}.
|
||||
* Note: Worlds may have more than one plot area
|
||||
* @deprecated
|
||||
* @param world
|
||||
@ -1182,7 +1185,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a plot world
|
||||
* Check if a plot world.
|
||||
* @param world
|
||||
* @see #getPlotAreaByString(String) to get the PlotArea object
|
||||
* @return if a plot world is registered
|
||||
@ -1233,7 +1236,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots for a PlotPlayer
|
||||
* Get the plots for a PlotPlayer.
|
||||
* @param player
|
||||
* @return Set of Plot
|
||||
*/
|
||||
@ -1246,7 +1249,7 @@ public class PS {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots for a UUID
|
||||
* Get the plots for a UUID.
|
||||
* @param uuid
|
||||
* @return Set of Plot
|
||||
*/
|
||||
@ -1811,7 +1814,7 @@ public class PS {
|
||||
List<String> booleanFlags =
|
||||
Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles",
|
||||
"pve", "pvp",
|
||||
"no-worldedit", "redstone");
|
||||
"no-worldedit", "redstone");
|
||||
List<String> intervalFlags = Arrays.asList("feed", "heal");
|
||||
List<String> stringFlags = Arrays.asList("greeting", "farewell");
|
||||
List<String> intFlags = Arrays.asList("misc-cap", "entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap", "music");
|
||||
@ -1874,6 +1877,7 @@ public class PS {
|
||||
return MainUtil.timeToSec(value) * 1000 + System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueDesc() {
|
||||
return "Flag value must a timestamp or a boolean";
|
||||
|
@ -45,33 +45,25 @@ public class Debug extends SubCommand {
|
||||
MainUtil.sendMessage(plr, msg.toString());
|
||||
return true;
|
||||
}
|
||||
StringBuilder information;
|
||||
String header, line, section;
|
||||
{
|
||||
information = new StringBuilder();
|
||||
header = C.DEBUG_HEADER.s();
|
||||
line = C.DEBUG_LINE.s();
|
||||
section = C.DEBUG_SECTION.s();
|
||||
}
|
||||
{
|
||||
final StringBuilder worlds = new StringBuilder("");
|
||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||
@Override
|
||||
public void run(PlotArea value) {
|
||||
worlds.append(value.toString()).append(" ");
|
||||
}
|
||||
});
|
||||
information.append(header);
|
||||
information.append(getSection(section, "PlotArea"));
|
||||
information.append(getLine(line, "Plot Worlds", worlds));
|
||||
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
|
||||
information.append(getSection(section, "Messages"));
|
||||
information.append(getLine(line, "Total Messages", C.values().length));
|
||||
information.append(getLine(line, "View all captions", "/plot debug msg"));
|
||||
}
|
||||
{
|
||||
MainUtil.sendMessage(plr, information.toString());
|
||||
}
|
||||
StringBuilder information = new StringBuilder();
|
||||
String header = C.DEBUG_HEADER.s();
|
||||
String line = C.DEBUG_LINE.s();
|
||||
String section = C.DEBUG_SECTION.s();
|
||||
final StringBuilder worlds = new StringBuilder("");
|
||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||
@Override
|
||||
public void run(PlotArea value) {
|
||||
worlds.append(value.toString()).append(" ");
|
||||
}
|
||||
});
|
||||
information.append(header);
|
||||
information.append(getSection(section, "PlotArea"));
|
||||
information.append(getLine(line, "Plot Worlds", worlds));
|
||||
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
|
||||
information.append(getSection(section, "Messages"));
|
||||
information.append(getLine(line, "Total Messages", C.values().length));
|
||||
information.append(getLine(line, "View all captions", "/plot debug msg"));
|
||||
MainUtil.sendMessage(plr, information.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -29,19 +29,17 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SubCommand class
|
||||
*
|
||||
|
||||
* SubCommand class.
|
||||
*/
|
||||
public abstract class SubCommand extends com.plotsquared.general.commands.Command<PlotPlayer> {
|
||||
|
||||
/**
|
||||
* The category
|
||||
* The category.
|
||||
*/
|
||||
public CommandCategory category;
|
||||
|
||||
/**
|
||||
* Send a message
|
||||
* Send a message.
|
||||
*
|
||||
* @param plr Player who will receive the message
|
||||
* @param c Caption
|
||||
|
@ -37,8 +37,6 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* Captions class.
|
||||
*
|
||||
|
||||
*/
|
||||
public enum C {
|
||||
|
||||
@ -629,52 +627,46 @@ public enum C {
|
||||
*/
|
||||
CUSTOM_STRING("-", "-");
|
||||
public static final HashMap<String, String> replacements = new HashMap<>();
|
||||
/**
|
||||
* Translated.
|
||||
*/
|
||||
private String s;
|
||||
|
||||
/**
|
||||
* Default.
|
||||
*/
|
||||
private String d;
|
||||
/**
|
||||
* What locale category should this translation fall under.
|
||||
*/
|
||||
private String cat;
|
||||
private final String def;
|
||||
/**
|
||||
* Should the string be prefixed.
|
||||
*/
|
||||
private boolean prefix;
|
||||
|
||||
/**
|
||||
* Constructor for custom strings.
|
||||
private final boolean prefix; /**
|
||||
* What locale category should this translation fall under.
|
||||
*/
|
||||
C() {
|
||||
/*
|
||||
* use setCustomString();
|
||||
*/
|
||||
}
|
||||
private final String category;
|
||||
/**
|
||||
* Translated.
|
||||
*/
|
||||
private String s; /**
|
||||
* Should the string be prefixed.
|
||||
*/
|
||||
private final boolean prefix;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param d default
|
||||
* @param def default
|
||||
* @param prefix use prefix
|
||||
*/
|
||||
C(String d, boolean prefix, String cat) {
|
||||
this.d = d;
|
||||
this.s = d;
|
||||
C(String def, boolean prefix, String category) {
|
||||
this.def = def;
|
||||
this.s = def;
|
||||
this.prefix = prefix;
|
||||
this.cat = cat.toLowerCase();
|
||||
this.category = category.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param d default
|
||||
* @param def default
|
||||
*/
|
||||
C(String d, String cat) {
|
||||
this(d, true, cat.toLowerCase());
|
||||
C(String def, String category) {
|
||||
this(def, true, category.toLowerCase());
|
||||
}
|
||||
|
||||
public static String format(String m, Object... args) {
|
||||
@ -720,35 +712,40 @@ public enum C {
|
||||
}
|
||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
Set<String> keys = yml.getKeys(true);
|
||||
EnumSet<C> all = EnumSet.allOf(C.class);
|
||||
EnumSet<C> allEnums = EnumSet.allOf(C.class);
|
||||
HashSet<String> allNames = new HashSet<>();
|
||||
HashSet<String> allCats = new HashSet<>();
|
||||
HashSet<String> categories = new HashSet<>();
|
||||
HashSet<String> toRemove = new HashSet<>();
|
||||
for (C c : all) {
|
||||
for (C c : allEnums) {
|
||||
allNames.add(c.name());
|
||||
allCats.add(c.cat.toLowerCase());
|
||||
categories.add(c.category.toLowerCase());
|
||||
}
|
||||
HashSet<C> captions = new HashSet<>();
|
||||
boolean changed = false;
|
||||
for (String key : keys) {
|
||||
if (!yml.isString(key)) {
|
||||
if (!allCats.contains(key)) {
|
||||
if (!categories.contains(key)) {
|
||||
toRemove.add(key);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
String[] split = key.split("\\.");
|
||||
String node = split[split.length - 1].toUpperCase();
|
||||
C caption = allNames.contains(node) ? valueOf(node) : null;
|
||||
C caption;
|
||||
if (allNames.contains(node)) {
|
||||
caption = valueOf(node);
|
||||
} else {
|
||||
caption = null;
|
||||
}
|
||||
if (caption != null) {
|
||||
if (caption.cat.startsWith("static")) {
|
||||
if (caption.category.startsWith("static")) {
|
||||
continue;
|
||||
}
|
||||
String value = yml.getString(key);
|
||||
if (!split[0].equalsIgnoreCase(caption.cat)) {
|
||||
if (!split[0].equalsIgnoreCase(caption.category)) {
|
||||
changed = true;
|
||||
yml.set(key, null);
|
||||
yml.set(caption.cat + "." + caption.name().toLowerCase(), value);
|
||||
yml.set(caption.category + "." + caption.name().toLowerCase(), value);
|
||||
}
|
||||
captions.add(caption);
|
||||
caption.s = value;
|
||||
@ -773,13 +770,13 @@ public enum C {
|
||||
replacements.put("\\\\n", "\n");
|
||||
replacements.put("\\n", "\n");
|
||||
replacements.put("&-", "\n");
|
||||
for (C caption : all) {
|
||||
for (C caption : allEnums) {
|
||||
if (!captions.contains(caption)) {
|
||||
if (caption.cat.startsWith("static")) {
|
||||
if (caption.getCategory().startsWith("static")) {
|
||||
continue;
|
||||
}
|
||||
changed = true;
|
||||
yml.set(caption.cat + "." + caption.name().toLowerCase(), caption.d);
|
||||
yml.set(caption.category + "." + caption.name().toLowerCase(), caption.def);
|
||||
}
|
||||
caption.s = StringMan.replaceFromMap(caption.s, replacements);
|
||||
}
|
||||
@ -808,8 +805,8 @@ public enum C {
|
||||
return StringMan.replaceFromMap(s(), replacements);
|
||||
}
|
||||
|
||||
public String getCat() {
|
||||
return this.cat;
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void send(CommandCaller plr, String... args) {
|
||||
|
@ -64,7 +64,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a {@link ResultSet} contains a column
|
||||
* Check if a {@link ResultSet} contains a column.
|
||||
* @param resultSet
|
||||
* @param name
|
||||
* @return
|
||||
@ -119,7 +119,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
* Create a plot.
|
||||
*
|
||||
* @param plot Plot to create
|
||||
*/
|
||||
@ -131,7 +131,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create tables
|
||||
* Create tables.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@ -140,7 +140,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a plot
|
||||
* Delete a plot.
|
||||
*
|
||||
* @param plot Plot to delete
|
||||
*/
|
||||
@ -153,7 +153,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the ratings for a plot
|
||||
* Delete the ratings for a plot.
|
||||
* @param plot
|
||||
*/
|
||||
public static void deleteRatings(Plot plot) {
|
||||
@ -164,7 +164,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the trusted list for a plot
|
||||
* Delete the trusted list for a plot.
|
||||
* @param plot
|
||||
*/
|
||||
public static void deleteTrusted(Plot plot) {
|
||||
@ -175,7 +175,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the members list for a plot
|
||||
* Delete the members list for a plot.
|
||||
* @param plot
|
||||
*/
|
||||
public static void deleteMembers(Plot plot) {
|
||||
@ -186,7 +186,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the denied list for a plot
|
||||
* Delete the denied list for a plot.
|
||||
* @param plot
|
||||
*/
|
||||
public static void deleteDenied(Plot plot) {
|
||||
@ -197,7 +197,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the comments in a plot
|
||||
* Delete the comments in a plot.
|
||||
* @param plot
|
||||
*/
|
||||
public static void deleteComments(Plot plot) {
|
||||
@ -227,7 +227,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
* Create plot settings.
|
||||
*
|
||||
* @param id Plot ID
|
||||
* @param plot Plot Object
|
||||
@ -240,7 +240,7 @@ public class DBFunc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot id
|
||||
* Get a plot id.
|
||||
*
|
||||
* @param plot Plot Object
|
||||
*
|
||||
|
@ -35,17 +35,17 @@ public abstract class Database {
|
||||
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Opens a connection with the database
|
||||
* Opens a connection with the database.
|
||||
*
|
||||
* @return Opened connection
|
||||
*
|
||||
* @throws SQLException if the connection can not be opened
|
||||
* @throws SQLException if the connection can not be opened
|
||||
* @throws ClassNotFoundException if the driver cannot be found
|
||||
*/
|
||||
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Checks if a connection is open with the database
|
||||
* Checks if a connection is open with the database.
|
||||
*
|
||||
* @return true if the connection is open
|
||||
*
|
||||
@ -54,7 +54,7 @@ public abstract class Database {
|
||||
public abstract boolean checkConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* Gets the connection with the database
|
||||
* Gets the connection with the database.
|
||||
*
|
||||
* @return Connection with the database, null if none
|
||||
*/
|
||||
@ -83,8 +83,9 @@ public abstract class Database {
|
||||
public abstract ResultSet querySQL(String query) throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Executes an Update SQL Query<br> See {@link java.sql.Statement#executeUpdate(String)}<br> If the connection is
|
||||
* closed, it will be opened
|
||||
* Executes an Update SQL Query.
|
||||
* See {@link java.sql.Statement#executeUpdate(String)}.
|
||||
* If the connection is closed, it will be opened.
|
||||
*
|
||||
* @param query Query to be run
|
||||
*
|
||||
|
@ -35,15 +35,16 @@ import java.sql.Statement;
|
||||
* @author tips48
|
||||
*/
|
||||
public class MySQL extends Database {
|
||||
|
||||
private final String user;
|
||||
private final String database;
|
||||
private final String password;
|
||||
private final String port;
|
||||
private final String hostname;
|
||||
private Connection connection;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new MySQL instance
|
||||
* Creates a new MySQL instance.
|
||||
*
|
||||
* @param hostname Name of the host
|
||||
* @param port Port number
|
||||
@ -51,69 +52,71 @@ public class MySQL extends Database {
|
||||
* @param username Username
|
||||
* @param password Password
|
||||
*/
|
||||
public MySQL(final String hostname, final String port, final String database, final String username, final String password) {
|
||||
public MySQL(String hostname, String port, String database, String username, String password) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
user = username;
|
||||
this.user = username;
|
||||
this.password = password;
|
||||
connection = null;
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Connection forceConnection() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database, user, password);
|
||||
return connection;
|
||||
this.connection =
|
||||
DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
return connection;
|
||||
return this.connection;
|
||||
}
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
PS.debug("jdbc:mysql://" + hostname + ":" + port + "/" + database);
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database, user, password);
|
||||
return connection;
|
||||
PS.debug("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database);
|
||||
this.connection =
|
||||
DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (connection != null) && !connection.isClosed();
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (connection == null) {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
connection.close();
|
||||
connection = null;
|
||||
this.connection.close();
|
||||
this.connection = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = this.connection.createStatement()) {
|
||||
return statement.executeQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = this.connection.createStatement()) {
|
||||
return statement.executeUpdate(query);
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,10 @@ import java.sql.Statement;
|
||||
* Connects to and uses a SQLite database.
|
||||
*/
|
||||
public class SQLite extends Database {
|
||||
|
||||
private final String dbLocation;
|
||||
private Connection connection;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new SQLite instance
|
||||
*
|
||||
@ -45,7 +46,7 @@ public class SQLite extends Database {
|
||||
public SQLite(String dbLocation) {
|
||||
this.dbLocation = dbLocation;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
@ -66,17 +67,17 @@ public class SQLite extends Database {
|
||||
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (this.connection == null) {
|
||||
@ -86,7 +87,7 @@ public class SQLite extends Database {
|
||||
this.connection = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
@ -96,7 +97,7 @@ public class SQLite extends Database {
|
||||
return statement.executeQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
@ -106,7 +107,7 @@ public class SQLite extends Database {
|
||||
return statement.executeUpdate(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Connection forceConnection() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
|
@ -1,38 +1,39 @@
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
|
||||
public abstract class StmtMod<T> {
|
||||
public abstract String getCreateMySQL(final int size);
|
||||
|
||||
public String getCreateMySQL(final int size, final String query, final int params) {
|
||||
final StringBuilder statement = new StringBuilder(query);
|
||||
|
||||
public abstract String getCreateMySQL(int size);
|
||||
|
||||
public String getCreateMySQL(int size, String query, int params) {
|
||||
StringBuilder statement = new StringBuilder(query);
|
||||
for (int i = 0; i < (size - 1); i++) {
|
||||
statement.append("(" + StringMan.repeat(",?", params).substring(1) + "),");
|
||||
}
|
||||
statement.append("(" + StringMan.repeat(",?", params).substring(1) + ")");
|
||||
return statement.toString();
|
||||
}
|
||||
|
||||
public String getCreateSQLite(final int size, final String query, final int params) {
|
||||
final StringBuilder statement = new StringBuilder(query);
|
||||
final String modParams = StringMan.repeat(",?", params).substring(1);
|
||||
|
||||
public String getCreateSQLite(int size, String query, int params) {
|
||||
StringBuilder statement = new StringBuilder(query);
|
||||
String modParams = StringMan.repeat(",?", params).substring(1);
|
||||
for (int i = 0; i < (size - 1); i++) {
|
||||
statement.append("UNION SELECT " + modParams + " ");
|
||||
}
|
||||
return statement.toString();
|
||||
}
|
||||
|
||||
public abstract String getCreateSQLite(final int size);
|
||||
|
||||
|
||||
public abstract String getCreateSQLite(int size);
|
||||
|
||||
public abstract String getCreateSQL();
|
||||
|
||||
public abstract void setMySQL(final PreparedStatement stmt, final int i, final T obj) throws SQLException;
|
||||
|
||||
public abstract void setSQLite(final PreparedStatement stmt, final int i, final T obj) throws SQLException;
|
||||
|
||||
public abstract void setSQL(final PreparedStatement stmt, final T obj) throws SQLException;
|
||||
|
||||
public abstract void setMySQL(PreparedStatement stmt, int i, T obj) throws SQLException;
|
||||
|
||||
public abstract void setSQLite(PreparedStatement stmt, int i, T obj) throws SQLException;
|
||||
|
||||
public abstract void setSQL(PreparedStatement stmt, T obj) throws SQLException;
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
* - Use the methods from the PlotArea/PS/Location etc to get existing plots
|
||||
*/
|
||||
public class Plot {
|
||||
|
||||
/**
|
||||
* @deprecated raw access is deprecated
|
||||
*/
|
||||
|
@ -31,58 +31,59 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Generic settings class
|
||||
* Generic settings class.
|
||||
* - Does not keep a reference to a parent class
|
||||
* - Direct changes here will not occur in the db (Use the parent plot object for that)
|
||||
*/
|
||||
public class PlotSettings {
|
||||
|
||||
/**
|
||||
* merged plots
|
||||
* Merged plots.
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean[] merged = new boolean[] { false, false, false, false };
|
||||
public boolean[] merged = new boolean[]{false, false, false, false};
|
||||
/**
|
||||
* plot alias
|
||||
* Plot alias.
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated
|
||||
public String alias = "";
|
||||
/**
|
||||
* Comments
|
||||
* Comments.
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated
|
||||
public List<PlotComment> comments = null;
|
||||
|
||||
|
||||
/**
|
||||
* The ratings for a plot
|
||||
* The ratings for a plot.
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<UUID, Integer> ratings;
|
||||
|
||||
|
||||
/**
|
||||
* Flags
|
||||
* Flags.
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<String, Flag> flags;
|
||||
/**
|
||||
* Home Position
|
||||
* Home Position.
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated
|
||||
private BlockLoc position;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
public PlotSettings() {
|
||||
flags = new HashMap<>();
|
||||
this.flags = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <b>Check if the plot is merged in a direction</b><br> 0 = North<br> 1 = East<br> 2 = South<br> 3 = West<br>
|
||||
*
|
||||
@ -90,118 +91,118 @@ public class PlotSettings {
|
||||
*
|
||||
* @return boolean merged
|
||||
*/
|
||||
public boolean getMerged(final int direction) {
|
||||
return merged[direction];
|
||||
public boolean getMerged(int direction) {
|
||||
return this.merged[direction];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the plot is merged (i.e. if it's a mega plot)
|
||||
*/
|
||||
public boolean isMerged() {
|
||||
return merged[0] || merged[1] || merged[2] || merged[3];
|
||||
}
|
||||
|
||||
public boolean[] getMerged() {
|
||||
return merged;
|
||||
}
|
||||
|
||||
public void setMerged(final boolean[] merged) {
|
||||
this.merged = merged;
|
||||
}
|
||||
|
||||
public Map<UUID, Integer> getRatings() {
|
||||
return ratings == null ? new HashMap<UUID, Integer>() : ratings;
|
||||
return this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3];
|
||||
}
|
||||
|
||||
public boolean setMerged(final int direction, final boolean merged) {
|
||||
public boolean[] getMerged() {
|
||||
return this.merged;
|
||||
}
|
||||
|
||||
public void setMerged(boolean[] merged) {
|
||||
this.merged = merged;
|
||||
}
|
||||
|
||||
public Map<UUID, Integer> getRatings() {
|
||||
return this.ratings == null ? new HashMap<UUID, Integer>() : this.ratings;
|
||||
}
|
||||
|
||||
public boolean setMerged(int direction, boolean merged) {
|
||||
if (this.merged[direction] != merged) {
|
||||
this.merged[direction] = merged;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public BlockLoc getPosition() {
|
||||
if (position == null) {
|
||||
if (this.position == null) {
|
||||
return new BlockLoc(0, 0, 0);
|
||||
}
|
||||
return position;
|
||||
return this.position;
|
||||
}
|
||||
|
||||
|
||||
public void setPosition(BlockLoc position) {
|
||||
if (position != null && position.x == 0 && position.y == 0 && position.z == 0) {
|
||||
position = null;
|
||||
}
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the plot alias
|
||||
* Set the plot alias.
|
||||
*
|
||||
* @param alias alias to be used
|
||||
*/
|
||||
public void setAlias(final String alias) {
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
|
||||
public String getJoinMessage(PlotArea area) {
|
||||
final Flag greeting = FlagManager.getSettingFlag(area, this, "greeting");
|
||||
Flag greeting = FlagManager.getSettingFlag(area, this, "greeting");
|
||||
if (greeting != null) {
|
||||
return greeting.getValueString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the "farewell" flag value
|
||||
*
|
||||
* @return Farewell flag
|
||||
*/
|
||||
public String getLeaveMessage(PlotArea area) {
|
||||
final Flag farewell = FlagManager.getSettingFlag(area, this, "farewell");
|
||||
Flag farewell = FlagManager.getSettingFlag(area, this, "farewell");
|
||||
if (farewell != null) {
|
||||
return farewell.getValueString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public ArrayList<PlotComment> getComments(final String inbox) {
|
||||
final ArrayList<PlotComment> c = new ArrayList<>();
|
||||
if (comments == null) {
|
||||
|
||||
public ArrayList<PlotComment> getComments(String inbox) {
|
||||
ArrayList<PlotComment> c = new ArrayList<>();
|
||||
if (this.comments == null) {
|
||||
return null;
|
||||
}
|
||||
for (final PlotComment comment : comments) {
|
||||
for (PlotComment comment : this.comments) {
|
||||
if (comment.inbox.equals(inbox)) {
|
||||
c.add(comment);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public void setComments(final List<PlotComment> comments) {
|
||||
|
||||
public void setComments(List<PlotComment> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public void removeComment(final PlotComment comment) {
|
||||
if (comments.contains(comment)) {
|
||||
comments.remove(comment);
|
||||
|
||||
public void removeComment(PlotComment comment) {
|
||||
if (this.comments.contains(comment)) {
|
||||
this.comments.remove(comment);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeComments(final List<PlotComment> comments) {
|
||||
for (final PlotComment comment : comments) {
|
||||
|
||||
public void removeComments(List<PlotComment> comments) {
|
||||
for (PlotComment comment : comments) {
|
||||
removeComment(comment);
|
||||
}
|
||||
}
|
||||
|
||||
public void addComment(final PlotComment comment) {
|
||||
if (comments == null) {
|
||||
comments = new ArrayList<>();
|
||||
|
||||
public void addComment(PlotComment comment) {
|
||||
if (this.comments == null) {
|
||||
this.comments = new ArrayList<>();
|
||||
}
|
||||
comments.add(comment);
|
||||
this.comments.add(comment);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -10,70 +11,69 @@ public class Rating {
|
||||
/**
|
||||
* This is a map of the rating category to the rating value
|
||||
*/
|
||||
private HashMap<String, Integer> ratingMap;
|
||||
|
||||
private final HashMap<String, Integer> ratingMap;
|
||||
private final int initial;
|
||||
private boolean changed;
|
||||
private int initial;
|
||||
|
||||
public Rating(int value) {
|
||||
initial = value;
|
||||
ratingMap = new HashMap<>();
|
||||
this.initial = value;
|
||||
this.ratingMap = new HashMap<>();
|
||||
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1)) {
|
||||
if (value < 10) {
|
||||
for (String ratingCategory : Settings.RATING_CATEGORIES) {
|
||||
ratingMap.put(ratingCategory, value);
|
||||
this.ratingMap.put(ratingCategory, value);
|
||||
}
|
||||
changed = true;
|
||||
this.changed = true;
|
||||
return;
|
||||
}
|
||||
for (String ratingCategory : Settings.RATING_CATEGORIES) {
|
||||
ratingMap.put(ratingCategory, (value % 10) - 1);
|
||||
this.ratingMap.put(ratingCategory, (value % 10) - 1);
|
||||
value = value / 10;
|
||||
}
|
||||
} else {
|
||||
ratingMap.put(null, value);
|
||||
this.ratingMap.put(null, value);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getCategories() {
|
||||
if (ratingMap.size() == 1) {
|
||||
if (this.ratingMap.size() == 1) {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
return new ArrayList<>(ratingMap.keySet());
|
||||
return new ArrayList<>(this.ratingMap.keySet());
|
||||
}
|
||||
|
||||
public double getAverageRating() {
|
||||
double total = 0;
|
||||
for (final Entry<String, Integer> entry : ratingMap.entrySet()) {
|
||||
for (Entry<String, Integer> entry : this.ratingMap.entrySet()) {
|
||||
total += entry.getValue();
|
||||
}
|
||||
return total / ratingMap.size();
|
||||
return total / this.ratingMap.size();
|
||||
}
|
||||
|
||||
public Integer getRating(final String category) {
|
||||
return ratingMap.get(category);
|
||||
public Integer getRating(String category) {
|
||||
return this.ratingMap.get(category);
|
||||
}
|
||||
|
||||
public boolean setRating(final String category, final int value) {
|
||||
changed = true;
|
||||
if (!ratingMap.containsKey(category)) {
|
||||
public boolean setRating(String category, int value) {
|
||||
this.changed = true;
|
||||
if (!this.ratingMap.containsKey(category)) {
|
||||
return false;
|
||||
}
|
||||
return ratingMap.put(category, value) != null;
|
||||
return this.ratingMap.put(category, value) != null;
|
||||
}
|
||||
|
||||
public int getAggregate() {
|
||||
if (!changed) {
|
||||
return initial;
|
||||
if (!this.changed) {
|
||||
return this.initial;
|
||||
}
|
||||
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1)) {
|
||||
int val = 0;
|
||||
for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++) {
|
||||
val += (i + 1) * Math.pow(10, ratingMap.get(Settings.RATING_CATEGORIES.get(i)));
|
||||
val += (i + 1) * Math.pow(10, this.ratingMap.get(Settings.RATING_CATEGORIES.get(i)));
|
||||
}
|
||||
return val;
|
||||
} else {
|
||||
return ratingMap.get(null);
|
||||
return this.ratingMap.get(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,19 +9,20 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class StringMan {
|
||||
public static String replaceFromMap(final String string, final Map<String, String> replacements) {
|
||||
final StringBuilder sb = new StringBuilder(string);
|
||||
|
||||
public static String replaceFromMap(String string, Map<String, String> replacements) {
|
||||
StringBuilder sb = new StringBuilder(string);
|
||||
int size = string.length();
|
||||
for (final Entry<String, String> entry : replacements.entrySet()) {
|
||||
for (Entry<String, String> entry : replacements.entrySet()) {
|
||||
if (size == 0) {
|
||||
break;
|
||||
}
|
||||
final String key = entry.getKey();
|
||||
final String value = entry.getValue();
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
int start = sb.indexOf(key, 0);
|
||||
while (start > -1) {
|
||||
final int end = start + key.length();
|
||||
final int nextSearchStart = start + value.length();
|
||||
int end = start + key.length();
|
||||
int nextSearchStart = start + value.length();
|
||||
sb.replace(start, end, value);
|
||||
size -= end - start;
|
||||
start = sb.indexOf(key, nextSearchStart);
|
||||
@ -29,7 +30,7 @@ public class StringMan {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static int intersection(Set<String> options, String[] toCheck) {
|
||||
int count = 0;
|
||||
for (String check : toCheck) {
|
||||
@ -40,7 +41,7 @@ public class StringMan {
|
||||
return count;
|
||||
}
|
||||
|
||||
public static String getString(final Object obj) {
|
||||
public static String getString(Object obj) {
|
||||
if (obj == null) {
|
||||
return "null";
|
||||
}
|
||||
@ -50,7 +51,7 @@ public class StringMan {
|
||||
if (obj.getClass().isArray()) {
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
|
||||
|
||||
for (int i = 0; i < Array.getLength(obj); i++) {
|
||||
result += prefix + getString(Array.get(obj, i));
|
||||
prefix = ",";
|
||||
@ -59,7 +60,7 @@ public class StringMan {
|
||||
} else if (obj instanceof Collection<?>) {
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
for (final Object element : (Collection<?>) obj) {
|
||||
for (Object element : (Collection<?>) obj) {
|
||||
result += prefix + getString(element);
|
||||
prefix = ",";
|
||||
}
|
||||
@ -68,8 +69,8 @@ public class StringMan {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static String replaceFirst(final char c, final String s) {
|
||||
|
||||
public static String replaceFirst(char c, String s) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
}
|
||||
@ -77,10 +78,10 @@ public class StringMan {
|
||||
return s;
|
||||
}
|
||||
char[] chars = s.toCharArray();
|
||||
final char[] newChars = new char[chars.length];
|
||||
char[] newChars = new char[chars.length];
|
||||
int used = 0;
|
||||
boolean found = false;
|
||||
for (final char cc : chars) {
|
||||
for (char cc : chars) {
|
||||
if (!found && (c == cc)) {
|
||||
found = true;
|
||||
} else {
|
||||
@ -94,86 +95,86 @@ public class StringMan {
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String replaceAll(final String string, final Object... pairs) {
|
||||
final StringBuilder sb = new StringBuilder(string);
|
||||
|
||||
public static String replaceAll(String string, Object... pairs) {
|
||||
StringBuilder sb = new StringBuilder(string);
|
||||
for (int i = 0; i < pairs.length; i += 2) {
|
||||
final String key = pairs[i] + "";
|
||||
final String value = pairs[i + 1] + "";
|
||||
String key = pairs[i] + "";
|
||||
String value = pairs[i + 1] + "";
|
||||
int start = sb.indexOf(key, 0);
|
||||
while (start > -1) {
|
||||
final int end = start + key.length();
|
||||
final int nextSearchStart = start + value.length();
|
||||
int end = start + key.length();
|
||||
int nextSearchStart = start + value.length();
|
||||
sb.replace(start, end, value);
|
||||
start = sb.indexOf(key, nextSearchStart);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static boolean isAlphanumeric(final String str) {
|
||||
|
||||
public static boolean isAlphanumeric(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
final char c = str.charAt(i);
|
||||
char c = str.charAt(i);
|
||||
if ((c < 0x30) || ((c >= 0x3a) && (c <= 0x40)) || ((c > 0x5a) && (c <= 0x60)) || (c > 0x7a)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAlphanumericUnd(final String str) {
|
||||
|
||||
public static boolean isAlphanumericUnd(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
final char c = str.charAt(i);
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x30 || (c >= 0x3a) && (c <= 0x40) || (c > 0x5a) && (c <= 0x60) || (c > 0x7a)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAlpha(final String str) {
|
||||
|
||||
public static boolean isAlpha(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
final char c = str.charAt(i);
|
||||
char c = str.charAt(i);
|
||||
if ((c <= 0x40) || ((c > 0x5a) && (c <= 0x60)) || (c > 0x7a)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String join(final Collection<?> collection, final String delimiter) {
|
||||
|
||||
public static String join(Collection<?> collection, String delimiter) {
|
||||
return join(collection.toArray(), delimiter);
|
||||
}
|
||||
|
||||
public static String joinOrdered(final Collection<?> collection, final String delimiter) {
|
||||
final Object[] array = collection.toArray();
|
||||
|
||||
public static String joinOrdered(Collection<?> collection, String delimiter) {
|
||||
Object[] array = collection.toArray();
|
||||
Arrays.sort(array, new Comparator<Object>() {
|
||||
@Override
|
||||
public int compare(final Object a, final Object b) {
|
||||
public int compare(Object a, Object b) {
|
||||
return a.hashCode() - b.hashCode();
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
return join(array, delimiter);
|
||||
}
|
||||
|
||||
public static String join(final Collection<?> collection, final char delimiter) {
|
||||
|
||||
public static String join(Collection<?> collection, char delimiter) {
|
||||
return join(collection.toArray(), delimiter + "");
|
||||
}
|
||||
|
||||
public static boolean isAsciiPrintable(final char c) {
|
||||
|
||||
public static boolean isAsciiPrintable(char c) {
|
||||
return (c >= ' ') && (c < '');
|
||||
}
|
||||
|
||||
public static boolean isAsciiPrintable(final String s) {
|
||||
for (final char c : s.toCharArray()) {
|
||||
|
||||
public static boolean isAsciiPrintable(String s) {
|
||||
for (char c : s.toCharArray()) {
|
||||
if (!isAsciiPrintable(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static int getLevenshteinDistance(String s, String t) {
|
||||
int n = s.length();
|
||||
int m = t.length();
|
||||
@ -183,7 +184,7 @@ public class StringMan {
|
||||
return n;
|
||||
}
|
||||
if (n > m) {
|
||||
final String tmp = s;
|
||||
String tmp = s;
|
||||
s = t;
|
||||
t = tmp;
|
||||
n = m;
|
||||
@ -198,7 +199,7 @@ public class StringMan {
|
||||
for (int j = 1; j <= m; j++) {
|
||||
char t_j = t.charAt(j - 1);
|
||||
d[0] = j;
|
||||
|
||||
|
||||
for (i = 1; i <= n; i++) {
|
||||
int cost = s.charAt(i - 1) == t_j ? 0 : 1;
|
||||
d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost);
|
||||
@ -209,9 +210,9 @@ public class StringMan {
|
||||
}
|
||||
return p[n];
|
||||
}
|
||||
|
||||
public static String join(final Object[] array, final String delimiter) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
public static String join(Object[] array, String delimiter) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0, j = array.length; i < j; i++) {
|
||||
if (i > 0) {
|
||||
result.append(delimiter);
|
||||
@ -220,43 +221,43 @@ public class StringMan {
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String join(final int[] array, final String delimiter) {
|
||||
final Integer[] wrapped = new Integer[array.length];
|
||||
|
||||
public static String join(int[] array, String delimiter) {
|
||||
Integer[] wrapped = new Integer[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
wrapped[i] = array[i];
|
||||
}
|
||||
return join(wrapped, delimiter);
|
||||
}
|
||||
|
||||
public static boolean isEqualToAny(final String a, final String... args) {
|
||||
for (final String arg : args) {
|
||||
|
||||
public static boolean isEqualToAny(String a, String... args) {
|
||||
for (String arg : args) {
|
||||
if (StringMan.isEqual(a, arg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isEqualIgnoreCaseToAny(final String a, final String... args) {
|
||||
for (final String arg : args) {
|
||||
|
||||
public static boolean isEqualIgnoreCaseToAny(String a, String... args) {
|
||||
for (String arg : args) {
|
||||
if (StringMan.isEqualIgnoreCase(a, arg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isEqual(final String a, final String b) {
|
||||
return ((a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && (a.hashCode() == b.hashCode()) && a.equals(b)));
|
||||
|
||||
public static boolean isEqual(String a, String b) {
|
||||
return (a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && (a.hashCode() == b.hashCode()) && a.equals(b));
|
||||
}
|
||||
|
||||
public static boolean isEqualIgnoreCase(final String a, final String b) {
|
||||
return ((a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && a.equalsIgnoreCase(b)));
|
||||
|
||||
public static boolean isEqualIgnoreCase(String a, String b) {
|
||||
return (a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && a.equalsIgnoreCase(b));
|
||||
}
|
||||
|
||||
public static String repeat(final String s, final int n) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
public static String repeat(String s, int n) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < n; i++) {
|
||||
sb.append(s);
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public abstract class UUIDHandlerImplementation {
|
||||
|
||||
public final ConcurrentHashMap<String, PlotPlayer> players;
|
||||
public boolean CACHED = false;
|
||||
public UUIDWrapper uuidWrapper = null;
|
||||
public HashSet<UUID> unknown = new HashSet<>();
|
||||
private boolean cached = false;
|
||||
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||
|
||||
public UUIDHandlerImplementation(UUIDWrapper wrapper) {
|
||||
@ -36,7 +36,7 @@ public abstract class UUIDHandlerImplementation {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the UUID is not found, some commands can request to fetch the UUID when possible
|
||||
* If the UUID is not found, some commands can request to fetch the UUID when possible.
|
||||
* @param name
|
||||
* @param ifFetch
|
||||
*/
|
||||
@ -47,10 +47,10 @@ public abstract class UUIDHandlerImplementation {
|
||||
* Recommended to override this is you want to cache offline players
|
||||
*/
|
||||
public boolean startCaching(Runnable whenDone) {
|
||||
if (this.CACHED) {
|
||||
if (this.cached) {
|
||||
return false;
|
||||
}
|
||||
return this.CACHED = true;
|
||||
return this.cached = true;
|
||||
}
|
||||
|
||||
public UUIDWrapper getUUIDWrapper() {
|
||||
@ -73,7 +73,7 @@ public abstract class UUIDHandlerImplementation {
|
||||
for (Map.Entry<StringWrapper, UUID> entry : toAdd.entrySet()) {
|
||||
UUID uuid = entry.getValue();
|
||||
StringWrapper name = entry.getKey();
|
||||
if ((uuid == null) || (name == null)) {
|
||||
if (uuid == null || name == null) {
|
||||
continue;
|
||||
}
|
||||
BiMap<UUID, StringWrapper> inverse = this.uuidMap.inverse();
|
||||
@ -105,7 +105,8 @@ public abstract class UUIDHandlerImplementation {
|
||||
|
||||
/*
|
||||
* lazy UUID conversion:
|
||||
* - Useful if the person misconfigured the database, or settings before PlotMe conversion
|
||||
* - Useful if the person misconfigured the database, or settings before
|
||||
* PlotMe conversion
|
||||
*/
|
||||
if (!Settings.OFFLINE_MODE && !this.unknown.isEmpty()) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
|
@ -6,6 +6,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class QuadMap<T> {
|
||||
|
||||
public final int size;
|
||||
public final int x;
|
||||
public final int z;
|
||||
@ -23,9 +24,9 @@ public class QuadMap<T> {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.newsize = size >> 1;
|
||||
min = 512;
|
||||
this.min = 512;
|
||||
}
|
||||
|
||||
|
||||
public QuadMap(int size, int x, int z, int min) {
|
||||
this.size = size;
|
||||
this.x = x;
|
||||
@ -33,112 +34,112 @@ public class QuadMap<T> {
|
||||
this.newsize = size >> 1;
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
|
||||
public int count() {
|
||||
int size = countBelow();
|
||||
if (objects != null) {
|
||||
size += objects.size();
|
||||
if (this.objects != null) {
|
||||
size += this.objects.size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
public Set<T> getAll() {
|
||||
HashSet<T> all = new HashSet<>();
|
||||
if (objects != null) {
|
||||
all.addAll(objects);
|
||||
if (this.objects != null) {
|
||||
all.addAll(this.objects);
|
||||
}
|
||||
if (skip != null) {
|
||||
all.addAll(skip.getAll());
|
||||
if (this.skip != null) {
|
||||
all.addAll(this.skip.getAll());
|
||||
return all;
|
||||
}
|
||||
if (one != null) {
|
||||
all.addAll(one.getAll());
|
||||
if (this.one != null) {
|
||||
all.addAll(this.one.getAll());
|
||||
}
|
||||
if (two != null) {
|
||||
all.addAll(two.getAll());
|
||||
if (this.two != null) {
|
||||
all.addAll(this.two.getAll());
|
||||
}
|
||||
if (three != null) {
|
||||
all.addAll(three.getAll());
|
||||
if (this.three != null) {
|
||||
all.addAll(this.three.getAll());
|
||||
}
|
||||
if (four != null) {
|
||||
all.addAll(four.getAll());
|
||||
if (this.four != null) {
|
||||
all.addAll(this.four.getAll());
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
public int countCurrent() {
|
||||
return objects == null ? 0 : objects.size();
|
||||
return this.objects == null ? 0 : this.objects.size();
|
||||
}
|
||||
|
||||
public int countBelow() {
|
||||
int size = 0;
|
||||
if (one != null) {
|
||||
size += one.count();
|
||||
if (this.one != null) {
|
||||
size += this.one.count();
|
||||
}
|
||||
if (two != null) {
|
||||
size += two.count();
|
||||
if (this.two != null) {
|
||||
size += this.two.count();
|
||||
}
|
||||
if (three != null) {
|
||||
size += three.count();
|
||||
if (this.three != null) {
|
||||
size += this.three.count();
|
||||
}
|
||||
if (four != null) {
|
||||
size += four.count();
|
||||
if (this.four != null) {
|
||||
size += this.four.count();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public void add(T area) {
|
||||
if (size <= min) {
|
||||
if (this.size <= this.min) {
|
||||
if (this.objects == null) {
|
||||
objects = new HashSet<>();
|
||||
this.objects = new HashSet<>();
|
||||
}
|
||||
this.objects.add(area);
|
||||
return;
|
||||
}
|
||||
RegionWrapper region = getRegion(area);
|
||||
if (region.minX >= x) {
|
||||
if (region.minZ >= z) {
|
||||
if (one == null) {
|
||||
one = newInstance(newsize, x + newsize, z + newsize, min);
|
||||
if (region.minX >= this.x) {
|
||||
if (region.minZ >= this.z) {
|
||||
if (this.one == null) {
|
||||
this.one = newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize, this.min);
|
||||
}
|
||||
one.add(area);
|
||||
this.one.add(area);
|
||||
recalculateSkip();
|
||||
return;
|
||||
} else if (region.maxZ < z) {
|
||||
if (two == null) {
|
||||
two = newInstance(newsize, x + newsize, z - newsize, min);
|
||||
} else if (region.maxZ < this.z) {
|
||||
if (this.two == null) {
|
||||
this.two = newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize, this.min);
|
||||
}
|
||||
two.add(area);
|
||||
this.two.add(area);
|
||||
recalculateSkip();
|
||||
return;
|
||||
}
|
||||
} else if (region.maxX < x) {
|
||||
if (region.minZ >= z) {
|
||||
if (four == null) {
|
||||
four = newInstance(newsize, x - newsize, z + newsize, min);
|
||||
} else if (region.maxX < this.x) {
|
||||
if (region.minZ >= this.z) {
|
||||
if (this.four == null) {
|
||||
this.four = newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize, this.min);
|
||||
}
|
||||
four.add(area);
|
||||
this.four.add(area);
|
||||
recalculateSkip();
|
||||
return;
|
||||
} else if (region.maxZ < z) {
|
||||
if (three == null) {
|
||||
three = newInstance(newsize, x - newsize, z - newsize, min);
|
||||
} else if (region.maxZ < this.z) {
|
||||
if (this.three == null) {
|
||||
this.three = newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize, this.min);
|
||||
}
|
||||
three.add(area);
|
||||
this.three.add(area);
|
||||
recalculateSkip();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.objects == null) {
|
||||
objects = new HashSet<>();
|
||||
this.objects = new HashSet<>();
|
||||
}
|
||||
this.objects.add(area);
|
||||
}
|
||||
|
||||
|
||||
public RegionWrapper getRegion(T value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public QuadMap<T> newInstance(int newsize, int x, int z, int min) {
|
||||
try {
|
||||
return new QuadMap<T>(newsize, x, z, min) {
|
||||
@ -152,47 +153,47 @@ public class QuadMap<T> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean remove(T area) {
|
||||
if (objects != null) {
|
||||
if (objects.remove(area)) {
|
||||
return objects.isEmpty();
|
||||
if (this.objects != null) {
|
||||
if (this.objects.remove(area)) {
|
||||
return this.objects.isEmpty();
|
||||
}
|
||||
}
|
||||
if (skip != null) {
|
||||
if (skip.remove(area)) {
|
||||
skip = null;
|
||||
if (this.skip != null) {
|
||||
if (this.skip.remove(area)) {
|
||||
this.skip = null;
|
||||
}
|
||||
} else {
|
||||
RegionWrapper region = getRegion(area);
|
||||
if (region.minX >= this.x) {
|
||||
if (region.minZ >= this.z) {
|
||||
if (one != null) {
|
||||
if (one.remove(area)) {
|
||||
one = null;
|
||||
if (this.one != null) {
|
||||
if (this.one.remove(area)) {
|
||||
this.one = null;
|
||||
}
|
||||
return countCurrent() == 0;
|
||||
}
|
||||
} else {
|
||||
if (two != null) {
|
||||
if (two.remove(area)) {
|
||||
two = null;
|
||||
if (this.two != null) {
|
||||
if (this.two.remove(area)) {
|
||||
this.two = null;
|
||||
}
|
||||
return countCurrent() == 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (region.minZ >= this.z) {
|
||||
if (four != null) {
|
||||
if (four.remove(area)) {
|
||||
four = null;
|
||||
if (this.four != null) {
|
||||
if (this.four.remove(area)) {
|
||||
this.four = null;
|
||||
}
|
||||
return countCurrent() == 0;
|
||||
}
|
||||
} else {
|
||||
if (three != null) {
|
||||
if (three.remove(area)) {
|
||||
three = null;
|
||||
if (this.three != null) {
|
||||
if (this.three.remove(area)) {
|
||||
this.three = null;
|
||||
}
|
||||
return countCurrent() == 0;
|
||||
}
|
||||
@ -204,7 +205,7 @@ public class QuadMap<T> {
|
||||
|
||||
public void recalculateSkip() {
|
||||
QuadMap<T> map = null;
|
||||
for (QuadMap<T> current : new QuadMap[] { one, two, three, four }) {
|
||||
for (QuadMap<T> current : new QuadMap[]{this.one, this.two, this.three, this.four}) {
|
||||
if (current != null) {
|
||||
if (map != null) {
|
||||
this.skip = null;
|
||||
@ -215,70 +216,71 @@ public class QuadMap<T> {
|
||||
}
|
||||
this.skip = map.skip == null ? map : map.skip;
|
||||
}
|
||||
|
||||
|
||||
public Set<T> get(RegionWrapper region) {
|
||||
HashSet<T> set = new HashSet<>();
|
||||
if (objects != null) {
|
||||
for (T obj : objects) {
|
||||
if (this.objects != null) {
|
||||
for (T obj : this.objects) {
|
||||
if (getRegion(obj).intersects(region)) {
|
||||
set.add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (skip != null) {
|
||||
if (skip.intersects(region)) {
|
||||
set.addAll(skip.get(region));
|
||||
if (this.skip != null) {
|
||||
if (this.skip.intersects(region)) {
|
||||
set.addAll(this.skip.get(region));
|
||||
}
|
||||
} else {
|
||||
if (one != null && one.intersects(region)) {
|
||||
set.addAll(one.get(region));
|
||||
if (this.one != null && this.one.intersects(region)) {
|
||||
set.addAll(this.one.get(region));
|
||||
}
|
||||
if (two != null && two.intersects(region)) {
|
||||
set.addAll(two.get(region));
|
||||
if (this.two != null && this.two.intersects(region)) {
|
||||
set.addAll(this.two.get(region));
|
||||
}
|
||||
if (three != null && three.intersects(region)) {
|
||||
set.addAll(three.get(region));
|
||||
if (this.three != null && this.three.intersects(region)) {
|
||||
set.addAll(this.three.get(region));
|
||||
}
|
||||
if (four != null && four.intersects(region)) {
|
||||
set.addAll(four.get(region));
|
||||
if (this.four != null && this.four.intersects(region)) {
|
||||
set.addAll(this.four.get(region));
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
public boolean intersects(RegionWrapper other) {
|
||||
return (other.minX <= this.x + size) && (other.maxX >= this.x - size) && (other.minZ <= this.z + size) && (other.maxZ >= this.z - size);
|
||||
return (other.minX <= this.x + this.size) && (other.maxX >= this.x - this.size) && (other.minZ <= this.z + this.size) && (other.maxZ
|
||||
>= this.z - this.size);
|
||||
}
|
||||
|
||||
public T get(int x, int z) {
|
||||
if (objects != null) {
|
||||
for (T obj : objects) {
|
||||
if (this.objects != null) {
|
||||
for (T obj : this.objects) {
|
||||
if (getRegion(obj).isIn(x, z)) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (skip != null) {
|
||||
return skip.get(x, z);
|
||||
if (this.skip != null) {
|
||||
return this.skip.get(x, z);
|
||||
} else {
|
||||
if (x >= this.x) {
|
||||
if (z >= this.z) {
|
||||
if (one != null) {
|
||||
return one.get(x, z);
|
||||
if (this.one != null) {
|
||||
return this.one.get(x, z);
|
||||
}
|
||||
} else {
|
||||
if (two != null) {
|
||||
return two.get(x, z);
|
||||
if (this.two != null) {
|
||||
return this.two.get(x, z);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (z >= this.z) {
|
||||
if (four != null) {
|
||||
return four.get(x, z);
|
||||
if (this.four != null) {
|
||||
return this.four.get(x, z);
|
||||
}
|
||||
} else {
|
||||
if (three != null) {
|
||||
return three.get(x, z);
|
||||
if (this.three != null) {
|
||||
return this.three.get(x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
package com.intellectualcrafters.plot.uuid;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class UUIDWrapper {
|
||||
public abstract UUID getUUID(final PlotPlayer player);
|
||||
|
||||
public abstract UUID getUUID(final OfflinePlotPlayer player);
|
||||
|
||||
public abstract UUID getUUID(final String name);
|
||||
|
||||
public abstract OfflinePlotPlayer getOfflinePlayer(final UUID uuid);
|
||||
|
||||
public abstract OfflinePlotPlayer getOfflinePlayer(final String name);
|
||||
|
||||
public abstract UUID getUUID(PlotPlayer player);
|
||||
|
||||
public abstract UUID getUUID(OfflinePlotPlayer player);
|
||||
|
||||
public abstract UUID getUUID(String name);
|
||||
|
||||
public abstract OfflinePlotPlayer getOfflinePlayer(UUID uuid);
|
||||
|
||||
public abstract OfflinePlotPlayer getOfflinePlayer(String name);
|
||||
|
||||
public abstract OfflinePlotPlayer[] getOfflinePlayers();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user