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