Merge remote-tracking branch 'origin/master'

# Conflicts:
#	Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java
#	Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java
#	Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
#	Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java
#	Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java
#	Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java
This commit is contained in:
Matt 2016-03-20 23:03:31 -04:00
commit 09ee7f3048
50 changed files with 532 additions and 956 deletions

View File

@ -45,7 +45,6 @@ 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;
@ -66,21 +65,21 @@ import java.util.UUID;
* @see PS * @see PS
*/ */
public class PlotAPI { public class PlotAPI {
/** /**
* Permission that allows for admin access, this permission node will allow the player to use any part of the * Permission that allows for admin access, this permission node will allow the player to use any part of the
* plugin, without limitations. * plugin, without limitations.
* @deprecated Use C.PERMISSION_ADMIN.s() instead * @deprecated Use C.PERMISSION_ADMIN instead
*/ */
@Deprecated @Deprecated
public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s(); public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s();
/** /**
* @deprecated Use new PlotAPI() instead * @deprecated Use new PlotAPI() instead
*/ */
@Deprecated @Deprecated
public PlotAPI(final JavaPlugin plugin) {} public PlotAPI(final JavaPlugin plugin) {}
/** /**
* @see PS * @see PS
* *
@ -93,7 +92,7 @@ public class PlotAPI {
*/ */
@Deprecated @Deprecated
public PlotAPI() {} public PlotAPI() {}
/** /**
* Get all plots * Get all plots
* *
@ -104,7 +103,7 @@ public class PlotAPI {
public Set<Plot> getAllPlots() { public Set<Plot> getAllPlots() {
return PS.get().getPlots(); return PS.get().getPlots();
} }
/** /**
* Return all plots for a player * Return all plots for a player
* *
@ -115,7 +114,7 @@ public class PlotAPI {
public Set<Plot> getPlayerPlots(final Player player) { public Set<Plot> getPlayerPlots(final Player player) {
return PS.get().getPlots(BukkitUtil.getPlayer(player)); return PS.get().getPlots(BukkitUtil.getPlayer(player));
} }
/** /**
* Add a plot world * Add a plot world
* *
@ -125,7 +124,7 @@ public class PlotAPI {
public void addPlotArea(final PlotArea plotArea) { public void addPlotArea(final PlotArea plotArea) {
PS.get().addPlotArea(plotArea); PS.get().addPlotArea(plotArea);
} }
/** /**
* @return main configuration * @return main configuration
* *
@ -134,7 +133,7 @@ public class PlotAPI {
public YamlConfiguration getConfig() { public YamlConfiguration getConfig() {
return PS.get().config; return PS.get().config;
} }
/** /**
* @return storage configuration * @return storage configuration
* *
@ -143,7 +142,7 @@ public class PlotAPI {
public YamlConfiguration getStorage() { public YamlConfiguration getStorage() {
return PS.get().storage; return PS.get().storage;
} }
/** /**
* Get the main class for this plugin <br> - Contains a lot of fields and methods - not very well organized <br> * Get the main class for this plugin <br> - Contains a lot of fields and methods - not very well organized <br>
* Only use this if you really need it * Only use this if you really need it
@ -155,7 +154,7 @@ public class PlotAPI {
public PS getMain() { public PS getMain() {
return PS.get(); return PS.get();
} }
/** /**
* ChunkManager class contains several useful methods<br> * ChunkManager class contains several useful methods<br>
* - Chunk deletion<br> * - Chunk deletion<br>
@ -179,7 +178,7 @@ public class PlotAPI {
public SetQueue getSetQueue() { public SetQueue getSetQueue() {
return SetQueue.IMP; return SetQueue.IMP;
} }
/** /**
* UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead) * UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead)
* *
@ -190,7 +189,7 @@ public class PlotAPI {
public UUIDWrapper getUUIDWrapper() { public UUIDWrapper getUUIDWrapper() {
return UUIDHandler.getUUIDWrapper(); return UUIDHandler.getUUIDWrapper();
} }
/** /**
* Do not use this. Instead use FlagManager.[method] in your code. * Do not use this. Instead use FlagManager.[method] in your code.
* - Flag related stuff * - Flag related stuff
@ -203,7 +202,7 @@ public class PlotAPI {
public FlagManager getFlagManager() { public FlagManager getFlagManager() {
return new FlagManager(); return new FlagManager();
} }
/** /**
* Do not use this. Instead use MainUtil.[method] in your code. * Do not use this. Instead use MainUtil.[method] in your code.
* - Basic plot management stuff * - Basic plot management stuff
@ -216,7 +215,7 @@ public class PlotAPI {
public MainUtil getMainUtil() { public MainUtil getMainUtil() {
return new MainUtil(); return new MainUtil();
} }
/** /**
* Do not use this. Instead use C.PERMISSION_[method] in your code. * Do not use this. Instead use C.PERMISSION_[method] in your code.
* - Basic permission management stuff * - Basic permission management stuff
@ -235,7 +234,7 @@ public class PlotAPI {
} }
return perms.toArray(new String[perms.size()]); return perms.toArray(new String[perms.size()]);
} }
/** /**
* SchematicHandler class contains methods related to pasting, reading and writing schematics * SchematicHandler class contains methods related to pasting, reading and writing schematics
* *
@ -246,7 +245,7 @@ public class PlotAPI {
public SchematicHandler getSchematicHandler() { public SchematicHandler getSchematicHandler() {
return SchematicHandler.manager; return SchematicHandler.manager;
} }
/** /**
* Use C.[caption] instead * Use C.[caption] instead
* *
@ -258,7 +257,7 @@ public class PlotAPI {
public C[] getCaptions() { public C[] getCaptions() {
return C.values(); return C.values();
} }
/** /**
* Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil * Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil
* *
@ -276,7 +275,7 @@ public class PlotAPI {
} }
return getPlotManager(world.getName()); return getPlotManager(world.getName());
} }
public Set<PlotArea> getPlotAreas(World world) { public Set<PlotArea> getPlotAreas(World world) {
if (world == null) { if (world == null) {
return new HashSet<>(); return new HashSet<>();
@ -308,7 +307,7 @@ public class PlotAPI {
return null; return null;
} }
} }
/** /**
* Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific * Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific
* settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea * settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea
@ -327,7 +326,7 @@ public class PlotAPI {
} }
return getWorldSettings(world.getName()); return getWorldSettings(world.getName());
} }
/** /**
* Get the settings for a world (settings bundled in PlotArea class) * Get the settings for a world (settings bundled in PlotArea class)
* *
@ -354,7 +353,7 @@ public class PlotAPI {
return null; return null;
} }
} }
/** /**
* Send a message to a player. * Send a message to a player.
* *
@ -367,7 +366,7 @@ public class PlotAPI {
public void sendMessage(final Player player, final C c) { public void sendMessage(final Player player, final C c) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c); MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
} }
/** /**
* Send a message to a player. - Supports color codes * Send a message to a player. - Supports color codes
* *
@ -379,7 +378,7 @@ public class PlotAPI {
public void sendMessage(final Player player, final String string) { public void sendMessage(final Player player, final String string) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string); MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
} }
/** /**
* Send a message to the console. - Supports color codes * Send a message to the console. - Supports color codes
* *
@ -390,7 +389,7 @@ public class PlotAPI {
public void sendConsoleMessage(final String msg) { public void sendConsoleMessage(final String msg) {
PS.log(msg); PS.log(msg);
} }
/** /**
* Send a message to the console * Send a message to the console
* *
@ -400,9 +399,9 @@ public class PlotAPI {
* @see com.intellectualcrafters.plot.config.C * @see com.intellectualcrafters.plot.config.C
*/ */
public void sendConsoleMessage(final C c) { public void sendConsoleMessage(final C c) {
sendConsoleMessage(c.s()); sendConsoleMessage(c);
} }
/** /**
* Register a flag for use in plots * Register a flag for use in plots
* *
@ -414,7 +413,7 @@ public class PlotAPI {
public void addFlag(final AbstractFlag flag) { public void addFlag(final AbstractFlag flag) {
FlagManager.addFlag(flag); FlagManager.addFlag(flag);
} }
/** /**
* get all the currently registered flags * get all the currently registered flags
* *
@ -426,7 +425,7 @@ public class PlotAPI {
public AbstractFlag[] getFlags() { public AbstractFlag[] getFlags() {
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]); return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
} }
/** /**
* Get a plot based on the ID * Get a plot based on the ID
* *
@ -449,7 +448,7 @@ public class PlotAPI {
} }
return area.getPlot(new PlotId(x, z)); return area.getPlot(new PlotId(x, z));
} }
/** /**
* Get a plot based on the location * Get a plot based on the location
* *
@ -465,7 +464,7 @@ public class PlotAPI {
} }
return BukkitUtil.getLocation(l).getPlot(); return BukkitUtil.getLocation(l).getPlot();
} }
/** /**
* Get a plot based on the player location * Get a plot based on the player location
* *
@ -479,7 +478,7 @@ public class PlotAPI {
public Plot getPlot(final Player player) { public Plot getPlot(final 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
* *
@ -493,7 +492,7 @@ public class PlotAPI {
public boolean hasPlot(final World world, final Player player) { public boolean hasPlot(final World world, final 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
* *
@ -517,7 +516,7 @@ public class PlotAPI {
} }
return pPlots.toArray(new Plot[pPlots.size()]); return pPlots.toArray(new Plot[pPlots.size()]);
} }
/** /**
* Get all plots for the world * Get all plots for the world
* *
@ -536,7 +535,7 @@ public class PlotAPI {
Collection<Plot> plots = PS.get().getPlots(world.getName()); Collection<Plot> plots = PS.get().getPlots(world.getName());
return plots.toArray(new Plot[plots.size()]); return plots.toArray(new Plot[plots.size()]);
} }
/** /**
* Get all plot worlds * Get all plot worlds
* *
@ -548,7 +547,7 @@ public class PlotAPI {
Set<String> plotWorldStrings = PS.get().getPlotWorldStrings(); Set<String> plotWorldStrings = PS.get().getPlotWorldStrings();
return plotWorldStrings.toArray(new String[plotWorldStrings.size()]); return plotWorldStrings.toArray(new String[plotWorldStrings.size()]);
} }
/** /**
* Get if plot world * Get if plot world
* *
@ -562,7 +561,7 @@ public class PlotAPI {
public boolean isPlotWorld(final World world) { public boolean isPlotWorld(final World world) {
return PS.get().hasPlotArea(world.getName()); return PS.get().hasPlotArea(world.getName());
} }
/** /**
* Get plot locations * Get plot locations
* *
@ -578,7 +577,7 @@ public class PlotAPI {
public Location[] getLocations(final Plot p) { public Location[] getLocations(final 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()) };
} }
/** /**
* Get home location * Get home location
* *
@ -591,7 +590,7 @@ public class PlotAPI {
public Location getHomeLocation(final Plot p) { public Location getHomeLocation(final Plot p) {
return BukkitUtil.getLocation(p.getHome()); return BukkitUtil.getLocation(p.getHome());
} }
/** /**
* Get Bottom Location (min, min, min) * Get Bottom Location (min, min, min)
* *
@ -607,14 +606,14 @@ public class PlotAPI {
public Location getBottomLocation(final Plot p) { public Location getBottomLocation(final Plot p) {
return BukkitUtil.getLocation(p.getBottom()); return BukkitUtil.getLocation(p.getBottom());
} }
/** /**
* Get Top Location (max, max, max) * Get Top Location (max, max, max)
* *
* @param p Plot that you want to get the location for * @param p Plot that you want to get the location for
* *
* @return plot top location * @return plot top location
* *
* @deprecated As merged plots may not have a rectangular shape * @deprecated As merged plots may not have a rectangular shape
* *
* @see Plot * @see Plot
@ -623,7 +622,7 @@ public class PlotAPI {
public Location getTopLocation(final Plot p) { public Location getTopLocation(final Plot p) {
return BukkitUtil.getLocation(p.getTop()); return BukkitUtil.getLocation(p.getTop());
} }
/** /**
* Check whether or not a player is in a plot * Check whether or not a player is in a plot
* *
@ -635,7 +634,7 @@ public class PlotAPI {
public boolean isInPlot(final Player player) { public boolean isInPlot(final Player player) {
return getPlot(player) != null; return getPlot(player) != null;
} }
/** /**
* Register a subcommand * Register a subcommand
* *
@ -650,7 +649,7 @@ public class PlotAPI {
MainCommand.getInstance().createCommand(c); MainCommand.getInstance().createCommand(c);
} }
} }
/** /**
* Get the PlotSquared class * Get the PlotSquared class
* *
@ -661,7 +660,7 @@ public class PlotAPI {
public PS getPlotSquared() { public PS getPlotSquared() {
return PS.get(); return PS.get();
} }
/** /**
* Get the player plot count * Get the player plot count
* *
@ -677,7 +676,7 @@ public class PlotAPI {
} }
return BukkitUtil.getPlayer(player).getPlotCount(world.getName()); return BukkitUtil.getPlayer(player).getPlotCount(world.getName());
} }
/** /**
* Get a collection containing the players plots * Get a collection containing the players plots
* *
@ -696,7 +695,7 @@ public class PlotAPI {
} }
return BukkitUtil.getPlayer(player).getPlots(world.getName()); return BukkitUtil.getPlayer(player).getPlots(world.getName());
} }
/** /**
* Get the numbers of plots, which the player is able to build in * Get the numbers of plots, which the player is able to build in
* *
@ -709,7 +708,7 @@ public class PlotAPI {
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);
return pp.getAllowedPlots(); return pp.getAllowedPlots();
} }
/** /**
* Get the PlotPlayer for a player<br> * Get the PlotPlayer for a player<br>
* - The PlotPlayer is usually cached and will provide useful functions relating to players * - The PlotPlayer is usually cached and will provide useful functions relating to players
@ -722,7 +721,7 @@ public class PlotAPI {
public PlotPlayer wrapPlayer(final Player player) { public PlotPlayer wrapPlayer(final Player player) {
return PlotPlayer.wrap(player); return PlotPlayer.wrap(player);
} }
/** /**
* Get the PlotPlayer for a UUID (Please note that PlotSquared can be configured to provide different UUIDs than bukkit) * Get the PlotPlayer for a UUID (Please note that PlotSquared can be configured to provide different UUIDs than bukkit)
* *
@ -734,7 +733,7 @@ public class PlotAPI {
public PlotPlayer wrapPlayer(final UUID uuid) { public PlotPlayer wrapPlayer(final UUID uuid) {
return PlotPlayer.wrap(uuid); return PlotPlayer.wrap(uuid);
} }
/** /**
* Get the PlotPlayer for a username * Get the PlotPlayer for a username
* *
@ -746,7 +745,7 @@ public class PlotAPI {
public PlotPlayer wrapPlayer(final String player) { public PlotPlayer wrapPlayer(final String player) {
return PlotPlayer.wrap(player); return PlotPlayer.wrap(player);
} }
/** /**
* Get the PlotPlayer for an offline player<br> * Get the PlotPlayer for an offline player<br>
* Note that this will work if the player is offline, however not all functionality will work * Note that this will work if the player is offline, however not all functionality will work

View File

@ -87,7 +87,6 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; 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.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -97,12 +96,12 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public static BukkitMain THIS; public static BukkitMain THIS;
public static WorldEditPlugin worldEdit; public static WorldEditPlugin worldEdit;
private int[] version; private int[] version;
@Override @Override
public int[] getServerVersion() { public int[] getServerVersion() {
if (version == null) { if (version == null) {
@ -123,20 +122,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
return version; return version;
} }
@Override @Override
public void onEnable() { public void onEnable() {
THIS = this; THIS = this;
new PS(this, "Bukkit"); new PS(this, "Bukkit");
} }
@Override @Override
public void onDisable() { public void onDisable() {
PS.get().disable(); PS.get().disable();
Bukkit.getScheduler().cancelTasks(this); Bukkit.getScheduler().cancelTasks(this);
THIS = null; THIS = null;
} }
@Override @Override
public void log(String message) { public void log(String message) {
if (THIS != null && Bukkit.getServer().getConsoleSender() != null) { if (THIS != null && Bukkit.getServer().getConsoleSender() != null) {
@ -151,20 +150,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
System.out.println(ConsoleColors.fromString(message)); System.out.println(ConsoleColors.fromString(message));
} }
@Override @Override
public void disable() { public void disable() {
if (THIS != null) { if (THIS != null) {
onDisable(); onDisable();
} }
} }
@Override @Override
public int[] getPluginVersion() { public int[] getPluginVersion() {
final String[] split = getDescription().getVersion().split("\\."); final String[] split = getDescription().getVersion().split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) }; return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
} }
@Override @Override
public void registerCommands() { public void registerCommands() {
final BukkitCommand bcmd = new BukkitCommand(); final BukkitCommand bcmd = new BukkitCommand();
@ -174,25 +173,25 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
plotCommand.setTabCompleter(bcmd); plotCommand.setTabCompleter(bcmd);
MainCommand.getInstance().addCommand(new DebugUUID()); MainCommand.getInstance().addCommand(new DebugUUID());
} }
@Override @Override
public File getDirectory() { public File getDirectory() {
return getDataFolder(); return getDataFolder();
} }
@Override @Override
public File getWorldContainer() { public File getWorldContainer() {
return Bukkit.getWorldContainer(); return Bukkit.getWorldContainer();
} }
@Override @Override
public TaskManager getTaskManager() { public TaskManager getTaskManager() {
return new BukkitTaskManager(); return new BukkitTaskManager();
} }
@Override @Override
public void runEntityTask() { public void runEntityTask() {
log(C.PREFIX.s() + "KillAllEntities started."); log(C.PREFIX + "KillAllEntities started.");
TaskManager.runTaskRepeat(new Runnable() { TaskManager.runTaskRepeat(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -335,7 +334,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
}, 20); }, 20);
} }
@Override @Override
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
final HybridGen result = new HybridGen(); final HybridGen result = new HybridGen();
@ -344,7 +343,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
return (ChunkGenerator) result.specify(); return (ChunkGenerator) result.specify();
} }
@Override @Override
public void registerPlayerEvents() { public void registerPlayerEvents() {
getServer().getPluginManager().registerEvents(new PlayerEvents(), this); getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
@ -355,23 +354,23 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8_3(), this); getServer().getPluginManager().registerEvents(new PlayerEvents_1_8_3(), this);
} }
} }
@Override @Override
public void registerInventoryEvents() { public void registerInventoryEvents() {
// Part of PlayerEvents - can be moved if necessary // Part of PlayerEvents - can be moved if necessary
} }
@Override @Override
public void registerPlotPlusEvents() { public void registerPlotPlusEvents() {
PlotPlusListener.startRunnable(this); PlotPlusListener.startRunnable(this);
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this); getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
} }
@Override @Override
public void registerForceFieldEvents() { public void registerForceFieldEvents() {
getServer().getPluginManager().registerEvents(new ForceFieldListener(), this); getServer().getPluginManager().registerEvents(new ForceFieldListener(), this);
} }
@Override @Override
public boolean initWorldEdit() { public boolean initWorldEdit() {
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) { if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
@ -388,7 +387,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
return false; return false;
} }
@Override @Override
public EconHandler getEconomyHandler() { public EconHandler getEconomyHandler() {
try { try {
@ -400,7 +399,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
return null; return null;
} }
@Override @Override
public PlotQueue initPlotQueue() { public PlotQueue initPlotQueue() {
try { try {
@ -439,12 +438,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
return new SlowQueue(); return new SlowQueue();
} }
} }
@Override @Override
public WorldUtil initWorldUtil() { public WorldUtil initWorldUtil() {
return new BukkitUtil(); return new BukkitUtil();
} }
@Override @Override
public boolean initPlotMeConverter() { public boolean initPlotMeConverter() {
TaskManager.runTaskLaterAsync(new Runnable() { TaskManager.runTaskLaterAsync(new Runnable() {
@ -463,7 +462,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
}, 20); }, 20);
return Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null; return Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null;
} }
@Override @Override
public GeneratorWrapper<?> getGenerator(final String world, final String name) { public GeneratorWrapper<?> getGenerator(final String world, final String name) {
if (name == null) { if (name == null) {
@ -480,17 +479,17 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
return new BukkitPlotGenerator(new HybridGen()); return new BukkitPlotGenerator(new HybridGen());
} }
} }
@Override @Override
public HybridUtils initHybridUtils() { public HybridUtils initHybridUtils() {
return new BukkitHybridUtils(); return new BukkitHybridUtils();
} }
@Override @Override
public SetupUtils initSetupUtils() { public SetupUtils initSetupUtils() {
return new BukkitSetupUtils(); return new BukkitSetupUtils();
} }
@Override @Override
public UUIDHandlerImplementation initUUIDHandler() { public UUIDHandlerImplementation initUUIDHandler() {
final boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6); final boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6);
@ -514,7 +513,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
Settings.OFFLINE_MODE = true; Settings.OFFLINE_MODE = true;
} }
if (!checkVersion) { if (!checkVersion) {
log(C.PREFIX.s() + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature."); log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
Settings.TITLES = false; Settings.TITLES = false;
FlagManager.removeFlag(FlagManager.getFlag("titles")); FlagManager.removeFlag(FlagManager.getFlag("titles"));
} else { } else {
@ -524,59 +523,59 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
} }
if (Settings.OFFLINE_MODE) { if (Settings.OFFLINE_MODE) {
log(C.PREFIX.s() + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit"); log(C.PREFIX + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit");
} else { } else {
log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs"); log(C.PREFIX + " &6PlotSquared is using online UUIDs");
} }
return Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler(wrapper) : new FileUUIDHandler(wrapper); return Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler(wrapper) : new FileUUIDHandler(wrapper);
} }
@Override @Override
public ChunkManager initChunkManager() { public ChunkManager initChunkManager() {
return new BukkitChunkManager(); return new BukkitChunkManager();
} }
@Override @Override
public EventUtil initEventUtil() { public EventUtil initEventUtil() {
return new BukkitEventUtil(); return new BukkitEventUtil();
} }
@Override @Override
public void unregister(final PlotPlayer player) { public void unregister(final PlotPlayer player) {
BukkitUtil.removePlayer(player.getName()); BukkitUtil.removePlayer(player.getName());
} }
@Override @Override
public void registerChunkProcessor() { public void registerChunkProcessor() {
getServer().getPluginManager().registerEvents(new ChunkListener(), this); getServer().getPluginManager().registerEvents(new ChunkListener(), this);
} }
@Override @Override
public void registerWorldEvents() { public void registerWorldEvents() {
getServer().getPluginManager().registerEvents(new WorldEvents(), this); getServer().getPluginManager().registerEvents(new WorldEvents(), this);
} }
@Override @Override
public InventoryUtil initInventoryUtil() { public InventoryUtil initInventoryUtil() {
return new BukkitInventoryUtil(); return new BukkitInventoryUtil();
} }
@Override @Override
public String getServerName() { public String getServerName() {
return Bukkit.getServerName(); return Bukkit.getServerName();
} }
@Override @Override
public void startMetrics() { public void startMetrics() {
try { try {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.start(); metrics.start();
log(C.PREFIX.s() + "&6Metrics enabled."); log(C.PREFIX + "&6Metrics enabled.");
} catch (IOException e) { } catch (IOException e) {
log(C.PREFIX.s() + "&cFailed to load up metrics."); log(C.PREFIX + "&cFailed to load up metrics.");
} }
} }
@Override @Override
public void setGenerator(final String worldname) { public void setGenerator(final String worldname) {
World world = BukkitUtil.getWorld(worldname); World world = BukkitUtil.getWorld(worldname);
@ -615,18 +614,18 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
PS.get().loadWorld(worldname, null); PS.get().loadWorld(worldname, null);
} }
} }
@Override @Override
public SchematicHandler initSchematicHandler() { public SchematicHandler initSchematicHandler() {
return new BukkitSchematicHandler(); return new BukkitSchematicHandler();
} }
@Override @Override
public AbstractTitle initTitleManager() { public AbstractTitle initTitleManager() {
// Already initialized in UUID handler // Already initialized in UUID handler
return AbstractTitle.TITLE_CLASS; return AbstractTitle.TITLE_CLASS;
} }
@Override @Override
public PlotPlayer wrapPlayer(final Object obj) { public PlotPlayer wrapPlayer(final Object obj) {
if (obj instanceof Player) { if (obj instanceof Player) {
@ -640,13 +639,13 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
return null; return null;
} }
@Override @Override
public String getNMSPackage() { public String getNMSPackage() {
String name = Bukkit.getServer().getClass().getPackage().getName(); String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1); return name.substring(name.lastIndexOf('.') + 1);
} }
@Override @Override
public ChatManager<?> initChatManager() { public ChatManager<?> initChatManager() {
if (Settings.FANCY_CHAT) { if (Settings.FANCY_CHAT) {
@ -655,12 +654,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
return new BukkitPlainChatManager(); return new BukkitPlainChatManager();
} }
} }
@Override @Override
public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) { public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(generator); return new BukkitPlotGenerator(generator);
} }
@Override @Override
public List<String> getPluginIds() { public List<String> getPluginIds() {
ArrayList<String> names = new ArrayList<>(); ArrayList<String> names = new ArrayList<>();

View File

@ -70,7 +70,7 @@ public abstract class TextualComponent implements Cloneable {
} }
static boolean isTranslatableText(final TextualComponent component) { static boolean isTranslatableText(final TextualComponent component) {
return (component instanceof ComplexTextTypeComponent) && ((ComplexTextTypeComponent) component).getKey().equals("translate"); return (component instanceof ComplexTextTypeComponent) && component.getKey().equals("translate");
} }
/** /**

View File

@ -42,7 +42,6 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
@ -63,16 +62,16 @@ usage = "/plot uuidconvert <lower|offline|online>",
requiredType = RequiredType.CONSOLE, requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG) category = CommandCategory.DEBUG)
public class DebugUUID extends SubCommand { public class DebugUUID extends SubCommand {
public DebugUUID() { public DebugUUID() {
requiredArguments = new Argument[] { Argument.String }; requiredArguments = new Argument[] { Argument.String };
} }
@Override @Override
public boolean onCommand(final PlotPlayer player, final String[] args) { public boolean onCommand(final PlotPlayer player, final String[] args) {
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper(); final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
final UUIDWrapper newWrapper; final UUIDWrapper newWrapper;
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "lower": case "lower":
newWrapper = new LowerOfflineUUIDWrapper(); newWrapper = new LowerOfflineUUIDWrapper();
@ -104,7 +103,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)"); MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)");
return false; return false;
} }
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) { if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
MainUtil.sendMessage(player, "&cUUID mode already in use!"); MainUtil.sendMessage(player, "&cUUID mode already in use!");
return false; return false;
@ -114,14 +113,14 @@ public class DebugUUID extends SubCommand {
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) { for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
entry.getValue().kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished."); entry.getValue().kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
} }
MainUtil.sendMessage(player, "&7 - Initializing map"); MainUtil.sendMessage(player, "&7 - Initializing map");
final HashMap<UUID, UUID> uCMap = new HashMap<>(); final HashMap<UUID, UUID> uCMap = new HashMap<>();
final HashMap<UUID, UUID> uCReverse = new HashMap<>(); final HashMap<UUID, UUID> uCReverse = new HashMap<>();
MainUtil.sendMessage(player, "&7 - Collecting playerdata"); MainUtil.sendMessage(player, "&7 - Collecting playerdata");
final HashSet<String> worlds = new HashSet<>(); final HashSet<String> worlds = new HashSet<>();
worlds.add(WorldUtil.IMP.getMainWorld()); worlds.add(WorldUtil.IMP.getMainWorld());
worlds.add("world"); worlds.add("world");
@ -142,7 +141,7 @@ public class DebugUUID extends SubCommand {
final UUID uuid = UUID.fromString(s); final UUID uuid = UUID.fromString(s);
uuids.add(uuid); uuids.add(uuid);
} catch (final Exception e) { } catch (final Exception e) {
MainUtil.sendMessage(player, C.PREFIX.s() + "Invalid playerdata: " + current); MainUtil.sendMessage(player, C.PREFIX + "Invalid playerdata: " + current);
} }
} }
final File playersFolder = new File(worldname + File.separator + "players"); final File playersFolder = new File(worldname + File.separator + "players");
@ -158,7 +157,7 @@ public class DebugUUID extends SubCommand {
} }
} }
} }
MainUtil.sendMessage(player, "&7 - Populating map"); MainUtil.sendMessage(player, "&7 - Populating map");
UUID uuid2; UUID uuid2;
final UUIDWrapper wrapper = new DefaultUUIDWrapper(); final UUIDWrapper wrapper = new DefaultUUIDWrapper();
@ -172,7 +171,7 @@ public class DebugUUID extends SubCommand {
uCReverse.put(uuid2, uuid); uCReverse.put(uuid2, uuid);
} }
} catch (final Throwable e) { } catch (final Throwable e) {
MainUtil.sendMessage(player, C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat"); MainUtil.sendMessage(player, C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
} }
} }
for (final String name : names) { for (final String name : names) {
@ -204,7 +203,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&a - Successfully repopulated"); MainUtil.sendMessage(player, "&a - Successfully repopulated");
} }
} }
MainUtil.sendMessage(player, "&7 - Replacing cache"); MainUtil.sendMessage(player, "&7 - Replacing cache");
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
@ -215,9 +214,9 @@ public class DebugUUID extends SubCommand {
UUIDHandler.add(new StringWrapper(name), entry.getValue()); UUIDHandler.add(new StringWrapper(name), entry.getValue());
} }
} }
MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)"); MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt"); final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
if (file.exists()) { if (file.exists()) {
try { try {
@ -250,12 +249,12 @@ public class DebugUUID extends SubCommand {
e.printStackTrace(); e.printStackTrace();
} }
} }
MainUtil.sendMessage(player, "&7 - Replacing wrapper"); MainUtil.sendMessage(player, "&7 - Replacing wrapper");
UUIDHandler.setUUIDWrapper(newWrapper); UUIDHandler.setUUIDWrapper(newWrapper);
MainUtil.sendMessage(player, "&7 - Updating plot objects"); MainUtil.sendMessage(player, "&7 - Updating plot objects");
for (final Plot plot : PS.get().getPlots()) { for (final Plot plot : PS.get().getPlots()) {
final UUID value = uCMap.get(plot.owner); final UUID value = uCMap.get(plot.owner);
if (value != null) { if (value != null) {
@ -265,13 +264,13 @@ public class DebugUUID extends SubCommand {
plot.getMembers().clear(); plot.getMembers().clear();
plot.getDenied().clear(); plot.getDenied().clear();
} }
MainUtil.sendMessage(player, "&7 - Deleting database"); MainUtil.sendMessage(player, "&7 - Deleting database");
final AbstractDB database = DBFunc.dbManager; final AbstractDB database = DBFunc.dbManager;
final boolean result = database.deleteTables(); final boolean result = database.deleteTables();
MainUtil.sendMessage(player, "&7 - Creating tables"); MainUtil.sendMessage(player, "&7 - Creating tables");
try { try {
database.createTables(); database.createTables();
if (!result) { if (!result) {
@ -294,7 +293,7 @@ public class DebugUUID extends SubCommand {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
if (newWrapper instanceof OfflineUUIDWrapper) { if (newWrapper instanceof OfflineUUIDWrapper) {
PS.get().config.set("UUID.force-lowercase", false); PS.get().config.set("UUID.force-lowercase", false);
PS.get().config.set("UUID.offline", true); PS.get().config.set("UUID.offline", true);
@ -307,9 +306,9 @@ public class DebugUUID extends SubCommand {
} catch (IOException e) { } catch (IOException e) {
MainUtil.sendMessage(player, "Could not save configuration. It will need to be manuall set!"); MainUtil.sendMessage(player, "Could not save configuration. It will need to be manuall set!");
} }
MainUtil.sendMessage(player, "&7 - Populating tables"); MainUtil.sendMessage(player, "&7 - Populating tables");
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -322,7 +321,7 @@ public class DebugUUID extends SubCommand {
}); });
} }
}); });
MainUtil.sendMessage(player, "&aIt is now safe for players to join"); MainUtil.sendMessage(player, "&aIt is now safe for players to join");
MainUtil.sendMessage(player, "&cConversion is still in progress, you will be notified when it is complete"); MainUtil.sendMessage(player, "&cConversion is still in progress, you will be notified when it is complete");
} }

View File

@ -53,16 +53,16 @@ public abstract class APlotMeConnector {
public Location getPlotTopLocAbs(final int path, final int plot, final PlotId plotid) { public Location getPlotTopLocAbs(final int path, final int plot, final PlotId plotid) {
final int px = plotid.x; final int px = plotid.x;
final int pz = plotid.y; final int pz = plotid.y;
final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1; final int x = (px * (path + plot)) - (int) Math.floor(path / 2) - 1;
final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1; final int z = (pz * (path + plot)) - (int) Math.floor(path / 2) - 1;
return new Location(null, x, 256, z); return new Location(null, x, 256, z);
} }
public Location getPlotBottomLocAbs(final int path, final int plot, final PlotId plotid) { public Location getPlotBottomLocAbs(final int path, final int plot, final PlotId plotid) {
final int px = plotid.x; final int px = plotid.x;
final int pz = plotid.y; final int pz = plotid.y;
final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; final int x = (px * (path + plot)) - plot - (int) Math.floor(path / 2) - 1;
final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; final int z = (pz * (path + plot)) - plot - (int) Math.floor(path / 2) - 1;
return new Location(null, x, 1, z); return new Location(null, x, 1, z);
} }

View File

@ -20,16 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.bukkit.listeners; package com.plotsquared.bukkit.listeners;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -37,8 +27,18 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent; import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
/**
*/ */
public class ForceFieldListener implements Listener { public class ForceFieldListener implements Listener {
private Set<PlotPlayer> getNearbyPlayers(final Player player, final Plot plot) { private Set<PlotPlayer> getNearbyPlayers(final Player player, final Plot plot) {
@ -73,17 +73,19 @@ public class ForceFieldListener implements Listener {
Location oPlayerLocation = e.getLocation(); Location oPlayerLocation = e.getLocation();
final double playerX = playerLocation.getX(), playerY = playerLocation.getY(), playerZ = playerLocation.getZ(), oPlayerX = oPlayerLocation.getX(), oPlayerY = oPlayerLocation.getY(), oPlayerZ = oPlayerLocation final double playerX = playerLocation.getX(), playerY = playerLocation.getY(), playerZ = playerLocation.getZ(), oPlayerX = oPlayerLocation.getX(), oPlayerY = oPlayerLocation.getY(), oPlayerZ = oPlayerLocation
.getZ(); .getZ();
double x = 0d, y = 0d, z = 0d; double x = 0d;
if (playerX < oPlayerX) { if (playerX < oPlayerX) {
x = 1.0d; x = 1.0d;
} else if (playerX > oPlayerX) { } else if (playerX > oPlayerX) {
x = -1.0d; x = -1.0d;
} }
double y = 0d;
if (playerY < oPlayerY) { if (playerY < oPlayerY) {
y = 0.5d; y = 0.5d;
} else if (playerY > oPlayerY) { } else if (playerY > oPlayerY) {
y = -0.5d; y = -0.5d;
} }
double z = 0d;
if (playerZ < oPlayerZ) { if (playerZ < oPlayerZ) {
z = 1.0d; z = 1.0d;
} else if (playerZ > oPlayerZ) { } else if (playerZ > oPlayerZ) {

View File

@ -615,6 +615,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
return; return;
} }
if (PS.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getItemInHand().getTypeId() == PS.get().worldedit.getConfiguration().wandItem) {
return;
}
}
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
event.setCancelled(true); event.setCancelled(true);
} }
@ -1165,6 +1170,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
default: default:
return; return;
} }
if (PS.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getItemInHand().getTypeId() == PS.get().worldedit.getConfiguration().wandItem) {
return;
}
}
if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, loc, lb, true)) { if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, loc, lb, true)) {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -2,19 +2,64 @@ package com.plotsquared.bukkit.util;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.AugmentedUtils; import com.intellectualcrafters.plot.generator.AugmentedUtils;
import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.bukkit.object.entity.EntityWrapper; import com.plotsquared.bukkit.object.entity.EntityWrapper;
import org.bukkit.*; import org.bukkit.Bukkit;
import org.bukkit.block.*; import org.bukkit.Chunk;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.SkullType;
import org.bukkit.World;
import org.bukkit.block.Banner;
import org.bukkit.block.Beacon;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.BrewingStand;
import org.bukkit.block.Chest;
import org.bukkit.block.CommandBlock;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Dispenser;
import org.bukkit.block.Dropper;
import org.bukkit.block.Furnace;
import org.bukkit.block.Hopper;
import org.bukkit.block.Jukebox;
import org.bukkit.block.NoteBlock;
import org.bukkit.block.Sign;
import org.bukkit.block.Skull;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.entity.*; import org.bukkit.entity.Animals;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
public class BukkitChunkManager extends ChunkManager { public class BukkitChunkManager extends ChunkManager {
@ -595,7 +640,6 @@ public class BukkitChunkManager extends ChunkManager {
} }
} }
while (SetQueue.IMP.forceChunkSet()) { while (SetQueue.IMP.forceChunkSet()) {
;
} }
restoreBlocks(world1, 0, 0); restoreBlocks(world1, 0, 0);
restoreEntities(world1, 0, 0); restoreEntities(world1, 0, 0);

View File

@ -20,7 +20,13 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.bukkit.util; package com.plotsquared.bukkit.util;
import com.intellectualcrafters.jnbt.*; import com.intellectualcrafters.jnbt.ByteArrayTag;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.IntTag;
import com.intellectualcrafters.jnbt.ListTag;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.StringTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
@ -35,8 +41,13 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import java.util.*; import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
/** /**
* Schematic Handler * Schematic Handler
@ -73,7 +84,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0)); schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0)); schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
// Arrays of data types // Arrays of data types
final List<Tag> tileEntities = new ArrayList<>(); final List<CompoundTag> tileEntities = new ArrayList<>();
final byte[] blocks = new byte[width * height * length]; final byte[] blocks = new byte[width * height * length];
final byte[] blockData = new byte[width * height * length]; final byte[] blockData = new byte[width * height * length];
// Queue // Queue
@ -126,7 +137,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
@Override @Override
public void run() { public void run() {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) { while (!chunks.isEmpty() && ((System.currentTimeMillis() - start) < 20)) {
// save schematics // save schematics
final ChunkLoc chunk = chunks.remove(0); final ChunkLoc chunk = chunks.remove(0);
final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z); final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
@ -154,7 +165,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
} }
for (int y = sy; y <= Math.min(255, ey); y++) { for (int y = sy; y <= Math.min(255, ey); y++) {
final int ry = y - sy; final int ry = y - sy;
final int i1 = (ry * width * length); final int i1 = ry * width * length;
for (int z = zzb; z <= zzt; z++) { for (int z = zzb; z <= zzt; z++) {
final int rz = z - bz; final int rz = z - bz;
final int i2 = i1 + (rz * width); final int i2 = i1 + (rz * width);
@ -275,7 +286,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
final StateWrapper wrapper = new StateWrapper(state); final StateWrapper wrapper = new StateWrapper(state);
final CompoundTag rawTag = wrapper.getTag(); final CompoundTag rawTag = wrapper.getTag();
if (rawTag != null) { if (rawTag != null) {
final Map<String, Tag> values = new HashMap<String, Tag>(); final Map<String, Tag> values = new HashMap<>();
for (final Entry<String, Tag> entry : rawTag.getValue().entrySet()) { for (final Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
values.put(entry.getKey(), entry.getValue()); values.put(entry.getKey(), entry.getValue());
} }
@ -283,7 +294,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
values.put("x", new IntTag("x", x)); values.put("x", new IntTag("x", x));
values.put("y", new IntTag("y", y)); values.put("y", new IntTag("y", y));
values.put("z", new IntTag("z", z)); values.put("z", new IntTag("z", z));
final CompoundTag tileEntityTag = new CompoundTag(values); CompoundTag tileEntityTag = new CompoundTag(values);
tileEntities.add(tileEntityTag); tileEntities.add(tileEntityTag);
} }
} }

View File

@ -227,10 +227,8 @@ public class FastQueue_1_9 extends SlowQueue {
int x = MainUtil.x_loc[j][k]; int x = MainUtil.x_loc[j][k];
int y = MainUtil.y_loc[j][k]; int y = MainUtil.y_loc[j][k];
int z = MainUtil.z_loc[j][k]; int z = MainUtil.z_loc[j][k];
int id = n;
Object iblock = methodGetByCombinedId.call((int) n); Object iblock = methodGetByCombinedId.call((int) n);
setType.call(x, y & 15, z, iblock); setType.call(x, y & 15, z, iblock);
continue;
} }
} }
} }

View File

@ -10,12 +10,15 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.util.NbtFactory; import com.plotsquared.bukkit.util.NbtFactory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FilenameFilter; import java.io.FilenameFilter;
@ -28,16 +31,16 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
public class FileUUIDHandler extends UUIDHandlerImplementation { public class FileUUIDHandler extends UUIDHandlerImplementation {
public FileUUIDHandler(final UUIDWrapper wrapper) { public FileUUIDHandler(final UUIDWrapper wrapper) {
super(wrapper); super(wrapper);
} }
@Override @Override
public boolean startCaching(final Runnable whenDone) { public boolean startCaching(final Runnable whenDone) {
return super.startCaching(whenDone) && cache(whenDone); return super.startCaching(whenDone) && cache(whenDone);
} }
public boolean cache(final Runnable whenDone) { public boolean cache(final Runnable whenDone) {
final File container = Bukkit.getWorldContainer(); final File container = Bukkit.getWorldContainer();
final List<World> worlds = Bukkit.getWorlds(); final List<World> worlds = Bukkit.getWorlds();
@ -50,7 +53,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
PS.debug(C.PREFIX.s() + "&6Starting player data caching for: " + world); PS.debug(C.PREFIX + "&6Starting player data caching for: " + world);
final File uuidfile = new File(PS.get().IMP.getDirectory(), "uuids.txt"); final File uuidfile = new File(PS.get().IMP.getDirectory(), "uuids.txt");
if (uuidfile.exists()) { if (uuidfile.exists()) {
try { try {
@ -112,7 +115,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
} }
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
PS.debug(C.PREFIX.s() + "Invalid playerdata: " + current); PS.debug(C.PREFIX + "Invalid playerdata: " + current);
} }
} }
} }
@ -150,7 +153,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
final UUID uuid = UUID.fromString(s); final UUID uuid = UUID.fromString(s);
uuids.add(uuid); uuids.add(uuid);
} catch (final Exception e) { } catch (final Exception e) {
PS.debug(C.PREFIX.s() + "Invalid playerdata: " + current); PS.debug(C.PREFIX + "Invalid playerdata: " + current);
} }
} }
break; break;
@ -195,7 +198,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
} }
toAdd.put(new StringWrapper(name), uuid); toAdd.put(new StringWrapper(name), uuid);
} catch (final Throwable e) { } catch (final Throwable e) {
PS.debug(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat"); PS.debug(C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
} }
} }
for (final String name : names) { for (final String name : names) {
@ -226,7 +229,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
}); });
return true; return true;
} }
@Override @Override
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) { public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {

View File

@ -1,5 +1,21 @@
package com.plotsquared.bukkit.uuid; package com.plotsquared.bukkit.uuid;
import com.google.common.collect.HashBiMap;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -13,25 +29,8 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import com.google.common.collect.HashBiMap;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
public class SQLUUIDHandler extends UUIDHandlerImplementation { public class SQLUUIDHandler extends UUIDHandlerImplementation {
final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/"; final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
final int MAX_REQUESTS = 500; final int MAX_REQUESTS = 500;
final int INTERVAL = 12000; final int INTERVAL = 12000;
@ -57,13 +56,13 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
} }
startCaching(null); startCaching(null);
} }
private Connection getConnection() { private Connection getConnection() {
synchronized (_sqLite) { synchronized (_sqLite) {
return _sqLite.getConnection(); return _sqLite.getConnection();
} }
} }
@Override @Override
public boolean startCaching(final Runnable whenDone) { public boolean startCaching(final Runnable whenDone) {
if (!super.startCaching(whenDone)) { if (!super.startCaching(whenDone)) {
@ -76,11 +75,9 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>()); final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
final PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`"); final PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
final ResultSet resultSet = statement.executeQuery(); final ResultSet resultSet = statement.executeQuery();
StringWrapper username;
UUID uuid;
while (resultSet.next()) { while (resultSet.next()) {
username = new StringWrapper(resultSet.getString("username")); StringWrapper username = new StringWrapper(resultSet.getString("username"));
uuid = UUID.fromString(resultSet.getString("uuid")); UUID uuid = UUID.fromString(resultSet.getString("uuid"));
toAdd.put(new StringWrapper(username.value), uuid); toAdd.put(new StringWrapper(username.value), uuid);
} }
statement.close(); statement.close();
@ -195,10 +192,10 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
}); });
return true; return true;
} }
@Override @Override
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) { public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
PS.debug(C.PREFIX.s() + "UUID for '" + name + "' was null. We'll cache this from the mojang servers!"); PS.debug(C.PREFIX + "UUID for '" + name + "' was null. We'll cache this from the mojang servers!");
if (ifFetch == null) { if (ifFetch == null) {
return; return;
} }
@ -230,7 +227,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
} }
}); });
} }
@Override @Override
public void handleShutdown() { public void handleShutdown() {
super.handleShutdown(); super.handleShutdown();
@ -240,7 +237,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
throw new SQLUUIDHandlerException("Couldn't close database connection", e); throw new SQLUUIDHandlerException("Couldn't close database connection", e);
} }
} }
@Override @Override
public boolean add(final StringWrapper name, final UUID uuid) { public boolean add(final StringWrapper name, final UUID uuid) {
// Ignoring duplicates // Ignoring duplicates
@ -253,7 +250,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setString(2, name.toString()); statement.setString(2, name.toString());
statement.execute(); statement.execute();
PS.debug(C.PREFIX.s() + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'"); PS.debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -263,7 +260,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
} }
return false; return false;
} }
/** /**
* This is useful for name changes * This is useful for name changes
*/ */
@ -278,7 +275,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
statement.setString(1, name.value); statement.setString(1, name.value);
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.execute(); statement.execute();
PS.debug(C.PREFIX.s() + "Name change for '" + uuid + "' to '" + name.value + "'"); PS.debug(C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + "'");
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -76,7 +76,7 @@ public class MemorySection implements ConfigurationSection {
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
} }
} else if (obj instanceof List) { } else if (obj instanceof List) {
final List<?> val = ((List<?>) obj); final List<?> val = (List<?>) obj;
if (!val.isEmpty()) { if (!val.isEmpty()) {
return toDouble(val.get(0), def); return toDouble(val.get(0), def);
} }
@ -94,7 +94,7 @@ public class MemorySection implements ConfigurationSection {
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
} }
} else if (obj instanceof List) { } else if (obj instanceof List) {
final List<?> val = ((List<?>) obj); final List<?> val = (List<?>) obj;
if (!val.isEmpty()) { if (!val.isEmpty()) {
return toInt(val.get(0), def); return toInt(val.get(0), def);
} }
@ -112,7 +112,7 @@ public class MemorySection implements ConfigurationSection {
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
} }
} else if (obj instanceof List) { } else if (obj instanceof List) {
final List<?> val = ((List<?>) obj); final List<?> val = (List<?>) obj;
if (!val.isEmpty()) { if (!val.isEmpty()) {
return toLong(val.get(0), def); return toLong(val.get(0), def);
} }
@ -166,7 +166,7 @@ public class MemorySection implements ConfigurationSection {
builder.insert(0, parent.getName()); builder.insert(0, parent.getName());
} }
if ((key != null) && (!key.isEmpty())) { if ((key != null) && !key.isEmpty()) {
if (builder.length() > 0) { if (builder.length() > 0) {
builder.append(separator); builder.append(separator);
} }
@ -528,7 +528,7 @@ public class MemorySection implements ConfigurationSection {
final List<String> result = new ArrayList<>(); final List<String> result = new ArrayList<>();
for (final Object object : list) { for (final Object object : list) {
if ((object instanceof String) || (isPrimitiveWrapper(object))) { if ((object instanceof String) || isPrimitiveWrapper(object)) {
result.add(String.valueOf(object)); result.add(String.valueOf(object));
} }
} }
@ -819,7 +819,7 @@ public class MemorySection implements ConfigurationSection {
for (final Map.Entry<String, Object> entry : sec.map.entrySet()) { for (final Map.Entry<String, Object> entry : sec.map.entrySet()) {
output.add(createPath(section, entry.getKey(), this)); output.add(createPath(section, entry.getKey(), this));
if ((deep) && (entry.getValue() instanceof ConfigurationSection)) { if (deep && (entry.getValue() instanceof ConfigurationSection)) {
final ConfigurationSection subsection = (ConfigurationSection) entry.getValue(); final ConfigurationSection subsection = (ConfigurationSection) entry.getValue();
mapChildrenKeys(output, subsection, deep); mapChildrenKeys(output, subsection, deep);
} }

View File

@ -159,7 +159,7 @@ public class YamlConfiguration extends FileConfiguration {
boolean readingHeader = true; boolean readingHeader = true;
boolean foundHeader = false; boolean foundHeader = false;
for (int i = 0; (i < lines.length) && (readingHeader); i++) { for (int i = 0; (i < lines.length) && readingHeader; i++) {
final String line = lines[i]; final String line = lines[i];
if (line.startsWith(COMMENT_PREFIX)) { if (line.startsWith(COMMENT_PREFIX)) {
@ -172,7 +172,7 @@ public class YamlConfiguration extends FileConfiguration {
} }
foundHeader = true; foundHeader = true;
} else if ((foundHeader) && (line.isEmpty())) { } else if (foundHeader && line.isEmpty()) {
result.append("\n"); result.append("\n");
} else if (foundHeader) { } else if (foundHeader) {
readingHeader = false; readingHeader = false;
@ -189,11 +189,11 @@ public class YamlConfiguration extends FileConfiguration {
if (options().copyHeader()) { if (options().copyHeader()) {
final Configuration def = getDefaults(); final Configuration def = getDefaults();
if ((def != null) && (def instanceof FileConfiguration)) { if (def != null && def instanceof FileConfiguration) {
final FileConfiguration filedefaults = (FileConfiguration) def; final FileConfiguration filedefaults = (FileConfiguration) def;
final String defaultsHeader = filedefaults.buildHeader(); final String defaultsHeader = filedefaults.buildHeader();
if ((defaultsHeader != null) && (!defaultsHeader.isEmpty())) { if ((defaultsHeader != null) && !defaultsHeader.isEmpty()) {
return defaultsHeader; return defaultsHeader;
} }
} }
@ -210,7 +210,7 @@ public class YamlConfiguration extends FileConfiguration {
for (int i = lines.length - 1; i >= 0; i--) { for (int i = lines.length - 1; i >= 0; i--) {
builder.insert(0, "\n"); builder.insert(0, "\n");
if ((startedHeader) || (!lines[i].isEmpty())) { if (startedHeader || !lines[i].isEmpty()) {
builder.insert(0, lines[i]); builder.insert(0, lines[i]);
builder.insert(0, COMMENT_PREFIX); builder.insert(0, COMMENT_PREFIX);
startedHeader = true; startedHeader = true;

View File

@ -363,7 +363,7 @@ public class JSONObject {
} }
public static Writer quote(final String string, final Writer w) throws IOException { public static Writer quote(final String string, final Writer w) throws IOException {
if ((string == null) || (string.isEmpty())) { if ((string == null) || string.isEmpty()) {
w.write("\"\""); w.write("\"\"");
return w; return w;
} }
@ -427,7 +427,7 @@ public class JSONObject {
*/ */
public static Object stringToValue(final String string) { public static Object stringToValue(final String string) {
Double d; Double d;
if (string.equals("")) { if (string.isEmpty()) {
return string; return string;
} }
if (string.equalsIgnoreCase("true")) { if (string.equalsIgnoreCase("true")) {
@ -1115,7 +1115,7 @@ public class JSONObject {
} else if (name.startsWith("is")) { } else if (name.startsWith("is")) {
key = name.substring(2); key = name.substring(2);
} }
if ((!key.isEmpty()) && Character.isUpperCase(key.charAt(0)) && (method.getParameterTypes().length == 0)) { if (!key.isEmpty() && Character.isUpperCase(key.charAt(0)) && (method.getParameterTypes().length == 0)) {
if (key.length() == 1) { if (key.length() == 1) {
key = key.toLowerCase(); key = key.toLowerCase();
} else if (!Character.isUpperCase(key.charAt(1))) { } else if (!Character.isUpperCase(key.charAt(1))) {

View File

@ -342,7 +342,7 @@ public class JSONTokener {
} }
back(); back();
string = sb.toString().trim(); string = sb.toString().trim();
if ("".equals(string)) { if (string != null && string.isEmpty()) {
throw syntaxError("Missing value"); throw syntaxError("Missing value");
} }
return JSONObject.stringToValue(string); return JSONObject.stringToValue(string);

View File

@ -54,7 +54,6 @@ import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.area.QuadMap; import com.intellectualcrafters.plot.util.area.QuadMap;
import com.plotsquared.listener.WESubscriber; import com.plotsquared.listener.WESubscriber;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -165,7 +164,7 @@ public class PS {
} }
TASK = IMP.getTaskManager(); TASK = IMP.getTaskManager();
if (!C.ENABLED.s().isEmpty()) { if (!C.ENABLED.s().isEmpty()) {
log(C.ENABLED.s()); log(C.ENABLED);
} }
setupConfigs(); setupConfigs();
translationFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "PlotSquared.use_THIS.yml"); translationFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "PlotSquared.use_THIS.yml");
@ -1370,10 +1369,10 @@ public class PS {
// Conventional plot generator // Conventional plot generator
PlotArea plotArea = pg.getNewPlotArea(world, null, null, null); PlotArea plotArea = pg.getNewPlotArea(world, null, null, null);
PlotManager plotManager = pg.getNewPlotManager(); PlotManager plotManager = pg.getNewPlotManager();
log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); log(C.PREFIX + "&aDetected world load for '" + world + "'");
log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + pg); log(C.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + pg);
log(C.PREFIX.s() + "&3 - plotworld: &7" + plotArea.getClass().getName()); log(C.PREFIX + "&3 - plotworld: &7" + plotArea.getClass().getName());
log(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName()); log(C.PREFIX + "&3 - manager: &7" + plotManager.getClass().getName());
if (!config.contains(path)) { if (!config.contains(path)) {
config.createSection(path); config.createSection(path);
worldSection = config.getConfigurationSection(path); worldSection = config.getConfigurationSection(path);
@ -1399,7 +1398,7 @@ public class PS {
PS.debug("World possibly already loaded: " + world); PS.debug("World possibly already loaded: " + world);
return; return;
} }
log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); log(C.PREFIX + "&aDetected world load for '" + world + "'");
String gen_string = worldSection.getString("generator.plugin", "PlotSquared"); String gen_string = worldSection.getString("generator.plugin", "PlotSquared");
if (type == 2) { if (type == 2) {
Set<PlotCluster> clusters = clusters_tmp != null ? clusters_tmp.get(world) : new HashSet<PlotCluster>(); Set<PlotCluster> clusters = clusters_tmp != null ? clusters_tmp.get(world) : new HashSet<PlotCluster>();
@ -1415,7 +1414,7 @@ public class PS {
worldSection.createSection("areas." + fullId); worldSection.createSection("areas." + fullId);
DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE
log(C.PREFIX.s() + "&3 - " + name + "-" + pos1 + "-" + pos2); log(C.PREFIX + "&3 - " + name + "-" + pos1 + "-" + pos2);
GeneratorWrapper<?> areaGen = IMP.getGenerator(world, gen_string); GeneratorWrapper<?> areaGen = IMP.getGenerator(world, gen_string);
if (areaGen == null) { if (areaGen == null) {
throw new IllegalArgumentException("Invalid Generator: " + gen_string); throw new IllegalArgumentException("Invalid Generator: " + gen_string);
@ -1428,10 +1427,10 @@ public class PS {
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); log(C.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa); log(C.PREFIX + "&c | &9plotworld: &7" + pa);
log(C.PREFIX.s() + "&c | &9manager: &7" + pa); log(C.PREFIX + "&c | &9manager: &7" + pa);
log(C.PREFIX.s() + "&cNote: &7Area created for cluster:" + name + " (invalid or old configuration?)"); log(C.PREFIX + "&cNote: &7Area created for cluster:" + name + " (invalid or old configuration?)");
areaGen.getPlotGenerator().initialize(pa); areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa); areaGen.augment(pa);
toLoad.add(pa); toLoad.add(pa);
@ -1453,9 +1452,9 @@ public class PS {
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + areaGen); log(C.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX.s() + "&3 - plotworld: &7" + pa); log(C.PREFIX + "&3 - plotworld: &7" + pa);
log(C.PREFIX.s() + "&3 - manager: &7" + pa.getPlotManager()); log(C.PREFIX + "&3 - manager: &7" + pa.getPlotManager());
areaGen.getPlotGenerator().initialize(pa); areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa); areaGen.augment(pa);
addPlotArea(pa); addPlotArea(pa);
@ -1465,7 +1464,7 @@ public class PS {
throw new IllegalArgumentException("Invalid type for multi-area world. Expected `2`, got `" + type + "`"); throw new IllegalArgumentException("Invalid type for multi-area world. Expected `2`, got `" + type + "`");
} }
for (String areaId : areasSection.getKeys(false)) { for (String areaId : areasSection.getKeys(false)) {
log(C.PREFIX.s() + "&3 - " + areaId); log(C.PREFIX + "&3 - " + areaId);
String[] split = areaId.split("([^\\-]+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)"); String[] split = areaId.split("([^\\-]+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)");
if (split.length != 3) { if (split.length != 3) {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<pos1>-<pos2>`"); throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<pos1>-<pos2>`");
@ -1524,10 +1523,10 @@ public class PS {
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
log(C.PREFIX.s() + "&aDetected area load for '" + world + "'"); log(C.PREFIX + "&aDetected area load for '" + world + "'");
log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); log(C.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa); log(C.PREFIX + "&c | &9plotworld: &7" + pa);
log(C.PREFIX.s() + "&c | &9manager: &7" + pa.getPlotManager()); log(C.PREFIX + "&c | &9manager: &7" + pa.getPlotManager());
areaGen.getPlotGenerator().initialize(pa); areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa); areaGen.augment(pa);
addPlotArea(pa); addPlotArea(pa);
@ -1764,7 +1763,7 @@ public class PS {
public void setupDatabase() { public void setupDatabase() {
try { try {
if (Settings.DB.USE_MONGO) { if (Settings.DB.USE_MONGO) {
log(C.PREFIX.s() + "MongoDB is not yet implemented"); log(C.PREFIX + "MongoDB is not yet implemented");
log(C.PREFIX + "&cNo storage type is set!"); log(C.PREFIX + "&cNo storage type is set!");
IMP.disable(); IMP.disable();
return; return;
@ -1786,7 +1785,7 @@ public class PS {
this.clusters_tmp = DBFunc.getClusters(); this.clusters_tmp = DBFunc.getClusters();
} }
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
log(C.PREFIX.s() + "&cFailed to open DATABASE connection. The plugin will disable itself."); log(C.PREFIX + "&cFailed to open DATABASE connection. The plugin will disable itself.");
if (Settings.DB.USE_MONGO) { if (Settings.DB.USE_MONGO) {
log("$4MONGO"); log("$4MONGO");
} else if (Settings.DB.USE_MYSQL) { } else if (Settings.DB.USE_MYSQL) {
@ -2195,7 +2194,7 @@ public class PS {
// Misc // Misc
Settings.DEBUG = config.getBoolean("debug"); Settings.DEBUG = config.getBoolean("debug");
if (Settings.DEBUG) { if (Settings.DEBUG) {
log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); log(C.PREFIX + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
} }
Settings.CONSOLE_COLOR = config.getBoolean("console.color"); Settings.CONSOLE_COLOR = config.getBoolean("console.color");
if (!config.getBoolean("chat.fancy") || !checkVersion(IMP.getServerVersion(), 1, 8, 0)) { if (!config.getBoolean("chat.fancy") || !checkVersion(IMP.getServerVersion(), 1, 8, 0)) {
@ -2216,7 +2215,7 @@ public class PS {
public void setupConfigs() { public void setupConfigs() {
final File folder = new File(IMP.getDirectory() + File.separator + "config"); final File folder = new File(IMP.getDirectory() + File.separator + "config");
if (!folder.exists() && !folder.mkdirs()) { if (!folder.exists() && !folder.mkdirs()) {
log(C.PREFIX.s() + "&cFailed to create the /plugins/config folder. Please create it manually."); log(C.PREFIX + "&cFailed to create the /plugins/config folder. Please create it manually.");
} }
try { try {
styleFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "style.yml"); styleFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "style.yml");
@ -2315,7 +2314,7 @@ public class PS {
settings.put("Schematics Save Path", "" + Settings.SCHEMATIC_SAVE_PATH); settings.put("Schematics Save Path", "" + Settings.SCHEMATIC_SAVE_PATH);
settings.put("API Location", "" + Settings.API_URL); settings.put("API Location", "" + Settings.API_URL);
for (final Entry<String, String> setting : settings.entrySet()) { for (final Entry<String, String> setting : settings.entrySet()) {
log(C.PREFIX.s() + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue())); log(C.PREFIX + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue()));
} }
} }
} }

View File

@ -37,7 +37,7 @@ aliases = { "biome", "sb", "setb", "b" },
category = CommandCategory.APPEARANCE, category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE) requiredType = RequiredType.NONE)
public class Biome extends SetCommand { public class Biome extends SetCommand {
@Override @Override
public boolean set(final PlotPlayer plr, final Plot plot, final String value) { public boolean set(final PlotPlayer plr, final Plot plot, final String value) {
final int biome = WorldUtil.IMP.getBiomeFromString(value); final int biome = WorldUtil.IMP.getBiomeFromString(value);

View File

@ -14,6 +14,6 @@ public class Chat extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, final String... args) { public boolean onCommand(final PlotPlayer player, final String... args) {
return MainCommand.onCommand(player, "plot", new String[] { "toggle", "chat" }); return MainCommand.onCommand(player, "plot", "toggle", "chat");
} }
} }

View File

@ -85,7 +85,7 @@ public class Database extends SubCommand {
MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]"); MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]");
return false; return false;
} }
File file = MainUtil.getFile(PS.get().IMP.getDirectory(), (args[1].endsWith(".db")) ? args[1] : args[1] + ".db"); File file = MainUtil.getFile(PS.get().IMP.getDirectory(), args[1].endsWith(".db") ? args[1] : args[1] + ".db");
if (!file.exists()) { if (!file.exists()) {
MainUtil.sendMessage(player, "&6Database does not exist: " + file); MainUtil.sendMessage(player, "&6Database does not exist: " + file);
return false; return false;

View File

@ -90,7 +90,7 @@ public class Delete extends SubCommand {
} }
} }
}; };
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) { if (Settings.CONFIRM_DELETE && !Permissions.hasPermission(plr, "plots.confirm.bypass")) {
CmdConfirm.addPending(plr, "/plot delete " + plot.getId(), run); CmdConfirm.addPending(plr, "/plot delete " + plot.getId(), run);
} else { } else {
TaskManager.runTask(run); TaskManager.runTask(run);

View File

@ -17,7 +17,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class GenerateDocs { public class GenerateDocs {
public static void main(final String[] args) {
public static void main(String[] args) {
MainCommand.getInstance().addCommand(new WE_Anywhere()); MainCommand.getInstance().addCommand(new WE_Anywhere());
MainCommand.getInstance().addCommand(new Cluster()); MainCommand.getInstance().addCommand(new Cluster());
final ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands(); final ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
@ -39,8 +40,8 @@ public class GenerateDocs {
printCommand(command); printCommand(command);
} }
} }
public static void printCommand(final Command<PlotPlayer> command) { public static void printCommand(Command<PlotPlayer> command) {
try { try {
final String clazz = command.getClass().getSimpleName(); final String clazz = command.getClass().getSimpleName();
final String name = command.getCommand(); final String name = command.getCommand();
@ -129,8 +130,8 @@ public class GenerateDocs {
return new ArrayList<>(usages); return new ArrayList<>(usages);
} }
public static List<String> getPerms(final String cmd, final List<String> lines) { public static List<String> getPerms(String cmd, List<String> lines) {
final HashSet<String> perms = new HashSet<String>(); final HashSet<String> perms = new HashSet<>();
final Pattern p = Pattern.compile("\"([^\"]*)\""); final Pattern p = Pattern.compile("\"([^\"]*)\"");
final Pattern p2 = Pattern.compile("C.PERMISSION_\\s*(\\w+)"); final Pattern p2 = Pattern.compile("C.PERMISSION_\\s*(\\w+)");
String last = null; String last = null;
@ -202,13 +203,13 @@ public class GenerateDocs {
} }
return new ArrayList<>(perms); return new ArrayList<>(perms);
} }
public static String getComments(final List<String> lines) { public static String getComments(List<String> lines) {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
for (String line : lines) { for (String line : lines) {
line = line.trim(); line = line.trim();
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) { if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) {
line = (line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "")).trim(); line = line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "").trim();
result.append(line + "\n"); result.append(line + "\n");
} }
} }

View File

@ -44,7 +44,7 @@ requiredType = RequiredType.NONE)
public class Inbox extends SubCommand { public class Inbox extends SubCommand {
public void displayComments(final PlotPlayer player, final List<PlotComment> oldComments, int page) { public void displayComments(final PlotPlayer player, final List<PlotComment> oldComments, int page) {
if ((oldComments == null) || (oldComments.isEmpty())) { if ((oldComments == null) || oldComments.isEmpty()) {
MainUtil.sendMessage(player, C.INBOX_EMPTY); MainUtil.sendMessage(player, C.INBOX_EMPTY);
return; return;
} }
@ -65,10 +65,10 @@ public class Inbox extends SubCommand {
} }
final StringBuilder string = new StringBuilder(); final StringBuilder string = new StringBuilder();
string.append(StringMan.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + "\n"); string.append(StringMan.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + "\n");
PlotComment c;
// This might work xD // This might work xD
for (int x = (page * 12); x < max; x++) { for (int x = page * 12; x < max; x++) {
c = comments[x]; PlotComment c = comments[x];
String color; String color;
if (player.getName().equals(c.senderName)) { if (player.getName().equals(c.senderName)) {
color = "&a"; color = "&a";
@ -152,12 +152,11 @@ public class Inbox extends SubCommand {
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() { if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
final List<PlotComment> comments = value; if (index > value.size()) {
if (index > comments.size()) {
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + ""); sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
return; return;
} }
final PlotComment comment = comments.get(index - 1); final PlotComment comment = value.get(index - 1);
inbox.removeComment(plot, comment); inbox.removeComment(plot, comment);
plot.getSettings().removeComment(comment); plot.getSettings().removeComment(comment);
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment); MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
@ -199,8 +198,7 @@ public class Inbox extends SubCommand {
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() { if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
final List<PlotComment> comments = value; displayComments(player, value, page);
displayComments(player, comments, page);
} }
})) { })) {
if (plot == null) { if (plot == null) {

View File

@ -33,7 +33,6 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
@ -43,7 +42,7 @@ import java.util.UUID;
public class Merge extends SubCommand { public class Merge extends SubCommand {
public final static String[] values = new String[] { "north", "east", "south", "west", "auto" }; public final static String[] values = new String[] { "north", "east", "south", "west", "auto" };
public final static String[] aliases = new String[] { "n", "e", "s", "w", "all" }; public final static String[] aliases = new String[] { "n", "e", "s", "w", "all" };
public static String direction(float yaw) { public static String direction(float yaw) {
yaw = yaw / 90; yaw = yaw / 90;
final int i = Math.round(yaw); final int i = Math.round(yaw);
@ -65,7 +64,7 @@ public class Merge extends SubCommand {
return ""; return "";
} }
} }
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocationFull(); final Location loc = plr.getLocationFull();
@ -131,7 +130,7 @@ public class Merge extends SubCommand {
} }
MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE); MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE);
return false; return false;
} }
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) { if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
@ -165,7 +164,7 @@ public class Merge extends SubCommand {
return false; return false;
} }
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) { if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s()); MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER);
return false; return false;
} }
HashSet<UUID> uuids = adjacent.getOwners(); HashSet<UUID> uuids = adjacent.getOwners();

View File

@ -1,9 +1,5 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.net.URL;
import java.util.List;
import java.util.UUID;
import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
@ -19,6 +15,10 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.net.URL;
import java.util.List;
import java.util.UUID;
@CommandDeclaration(command = "save", aliases = { "backup" }, description = "Save your plot", category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, permission = "plots.save") @CommandDeclaration(command = "save", aliases = { "backup" }, description = "Save your plot", category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, permission = "plots.save")
public class Save extends SubCommand { public class Save extends SubCommand {
@ -73,7 +73,7 @@ public class Save extends SubCommand {
return; return;
} }
MainUtil.sendMessage(plr, C.SAVE_SUCCESS); MainUtil.sendMessage(plr, C.SAVE_SUCCESS);
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics"); final List<String> schematics = plr.getMeta("plot_schematics");
if (schematics != null) { if (schematics != null) {
schematics.add(file); schematics.add(file);
} }

View File

@ -52,7 +52,7 @@ public class SetHome extends SetCommand {
Plot base = plot.getBasePlot(false); Plot base = plot.getBasePlot(false);
Location bot = base.getBottomAbs(); Location bot = base.getBottomAbs();
Location loc = plr.getLocationFull(); Location loc = plr.getLocationFull();
BlockLoc rel = new BlockLoc(loc.getX() - bot.getX(), loc.getY(), loc.getZ() - bot.getZ(), loc.getYaw(), loc.getPitch());; BlockLoc rel = new BlockLoc(loc.getX() - bot.getX(), loc.getY(), loc.getZ() - bot.getZ(), loc.getYaw(), loc.getPitch());
base.setHome(rel); base.setHome(rel);
return MainUtil.sendMessage(plr, C.POSITION_SET); return MainUtil.sendMessage(plr, C.POSITION_SET);
} }

View File

@ -66,7 +66,7 @@ public class Setup extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
// going through setup // going through setup
SetupObject object = (SetupObject) plr.getMeta("setup"); SetupObject object = plr.getMeta("setup");
if (object == null) { if (object == null) {
object = new SetupObject(); object = new SetupObject();
plr.setMeta("setup", object); plr.setMeta("setup", object);

View File

@ -23,22 +23,32 @@ package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import java.util.ArrayList;
import java.util.*; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/** /**
* Flag Manager Utility * Flag Manager Utility
* *
*/ */
public class FlagManager { public class FlagManager {
private final static HashSet<String> reserved = new HashSet<>(); private final static HashSet<String> reserved = new HashSet<>();
private final static HashSet<AbstractFlag> flags = new HashSet<>(); private final static HashSet<AbstractFlag> flags = new HashSet<>();
/** /**
* Reserve a flag so that it cannot be set by players * Reserve a flag so that it cannot be set by players
* @param flag * @param flag
@ -46,7 +56,7 @@ public class FlagManager {
public static void reserveFlag(final String flag) { public static void reserveFlag(final String flag) {
reserved.add(flag); reserved.add(flag);
} }
/** /**
* Get if a flag is reserved * Get if a flag is reserved
* @param flag * @param flag
@ -55,7 +65,7 @@ public class FlagManager {
public static boolean isReserved(final String flag) { public static boolean isReserved(final String flag) {
return reserved.contains(flag); return reserved.contains(flag);
} }
/** /**
* Get the reserved flags * Get the reserved flags
* @return * @return
@ -63,7 +73,7 @@ public class FlagManager {
public static HashSet<String> getReservedFlags() { public static HashSet<String> getReservedFlags() {
return (HashSet<String>) reserved.clone(); return (HashSet<String>) reserved.clone();
} }
/** /**
* Unreserve a flag * Unreserve a flag
* @param flag * @param flag
@ -71,7 +81,7 @@ public class FlagManager {
public static void unreserveFlag(final String flag) { public static void unreserveFlag(final String flag) {
reserved.remove(flag); reserved.remove(flag);
} }
/** /**
* Register an AbstractFlag with PlotSquared * Register an AbstractFlag with PlotSquared
* *
@ -82,9 +92,9 @@ public class FlagManager {
public static boolean addFlag(final AbstractFlag af) { public static boolean addFlag(final AbstractFlag af) {
return addFlag(af, false); return addFlag(af, false);
} }
public static boolean addFlag(final AbstractFlag af, final boolean reserved) { public static boolean addFlag(final AbstractFlag af, final boolean reserved) {
PS.debug(C.PREFIX.s() + "&8 - Adding flag: &7" + af); PS.debug(C.PREFIX + "&8 - Adding flag: &7" + af);
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() { PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override @Override
public void run(PlotArea value) { public void run(PlotArea value) {
@ -125,7 +135,7 @@ public class FlagManager {
} }
return flag_string.toString(); return flag_string.toString();
} }
public static Flag getSettingFlag(final PlotArea area, final PlotSettings settings, final String id) { public static Flag getSettingFlag(final PlotArea area, final PlotSettings settings, final String id) {
Flag flag; Flag flag;
if (settings.flags.isEmpty() || (flag = settings.flags.get(id)) == null) { if (settings.flags.isEmpty() || (flag = settings.flags.get(id)) == null) {
@ -139,7 +149,7 @@ public class FlagManager {
} }
return flag; return flag;
} }
public static boolean isBooleanFlag(final Plot plot, final String key, final boolean defaultValue) { public static boolean isBooleanFlag(final Plot plot, final String key, final boolean defaultValue) {
final Flag flag = FlagManager.getPlotFlagRaw(plot, key); final Flag flag = FlagManager.getPlotFlagRaw(plot, key);
if (flag == null) { if (flag == null) {
@ -151,7 +161,7 @@ public class FlagManager {
} }
return defaultValue; return defaultValue;
} }
/** /**
* Get the value of a flag for a plot (respects flag defaults) * Get the value of a flag for a plot (respects flag defaults)
* @param plot * @param plot
@ -177,7 +187,7 @@ public class FlagManager {
} }
return getSettingFlag(plot.getArea(), plot.getSettings(), flag); return getSettingFlag(plot.getArea(), plot.getSettings(), flag);
} }
public static boolean isPlotFlagTrue(final Plot plot, final String strFlag) { public static boolean isPlotFlagTrue(final Plot plot, final String strFlag) {
if (plot.owner == null) { if (plot.owner == null) {
return false; return false;
@ -185,7 +195,7 @@ public class FlagManager {
final Flag flag = getPlotFlagRaw(plot, strFlag); final Flag flag = getPlotFlagRaw(plot, strFlag);
return !(flag == null || !((Boolean) flag.getValue())); return !(flag == null || !((Boolean) flag.getValue()));
} }
public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) { public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) {
if (plot.owner == null) { if (plot.owner == null) {
return false; return false;
@ -196,7 +206,7 @@ public class FlagManager {
} }
return false; return false;
} }
/** /**
* Get the value of a flag for a plot (ignores flag defaults) * Get the value of a flag for a plot (ignores flag defaults)
* @param plot * @param plot
@ -206,14 +216,14 @@ public class FlagManager {
public static Flag getPlotFlagAbs(final Plot plot, final String flag) { public static Flag getPlotFlagAbs(final Plot plot, final String flag) {
return getSettingFlagAbs(plot.getSettings(), flag); return getSettingFlagAbs(plot.getSettings(), flag);
} }
public static Flag getSettingFlagAbs(final PlotSettings settings, final String flag) { public static Flag getSettingFlagAbs(final PlotSettings settings, final String flag) {
if (settings.flags.isEmpty()) { if (settings.flags.isEmpty()) {
return null; return null;
} }
return settings.flags.get(flag); return settings.flags.get(flag);
} }
/** /**
* Add a flag to a plot * Add a flag to a plot
* @param origin * @param origin
@ -231,7 +241,7 @@ public class FlagManager {
} }
return true; return true;
} }
public static boolean addPlotFlagAbs(final Plot plot, final Flag flag) { public static boolean addPlotFlagAbs(final Plot plot, final Flag flag) {
final boolean result = EventUtil.manager.callFlagAdd(flag, plot); final boolean result = EventUtil.manager.callFlagAdd(flag, plot);
if (!result) { if (!result) {
@ -240,14 +250,14 @@ public class FlagManager {
plot.getFlags().put(flag.getKey(), flag); plot.getFlags().put(flag.getKey(), flag);
return true; return true;
} }
public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag) { public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag) {
getSettingFlag(cluster.area, cluster.settings, flag.getKey()); getSettingFlag(cluster.area, cluster.settings, flag.getKey());
cluster.settings.flags.put(flag.getKey(), flag); cluster.settings.flags.put(flag.getKey(), flag);
DBFunc.setFlags(cluster, cluster.settings.flags.values()); DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true; return true;
} }
/** /**
* *
* @param plot * @param plot
@ -259,7 +269,7 @@ public class FlagManager {
} }
return getSettingFlags(plot.getArea(), plot.getSettings()); return getSettingFlags(plot.getArea(), plot.getSettings());
} }
public static HashMap<String, Flag> getPlotFlags(PlotArea area, final PlotSettings settings, final boolean ignorePluginflags) { public static HashMap<String, Flag> getPlotFlags(PlotArea area, final PlotSettings settings, final boolean ignorePluginflags) {
final HashMap<String, Flag> flags = new HashMap<>(); final HashMap<String, Flag> flags = new HashMap<>();
if (area != null && !area.DEFAULT_FLAGS.isEmpty()) { if (area != null && !area.DEFAULT_FLAGS.isEmpty()) {
@ -275,14 +285,14 @@ public class FlagManager {
} else { } else {
flags.putAll(settings.flags); flags.putAll(settings.flags);
} }
return flags; return flags;
} }
public static HashMap<String, Flag> getSettingFlags(PlotArea area, final PlotSettings settings) { public static HashMap<String, Flag> getSettingFlags(PlotArea area, final PlotSettings settings) {
return getPlotFlags(area, settings, false); return getPlotFlags(area, settings, false);
} }
public static boolean removePlotFlag(final Plot plot, final String id) { public static boolean removePlotFlag(final Plot plot, final String id) {
final Flag flag = plot.getFlags().remove(id); final Flag flag = plot.getFlags().remove(id);
if (flag == null) { if (flag == null) {
@ -297,7 +307,7 @@ public class FlagManager {
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags().values());
return true; return true;
} }
public static boolean removeClusterFlag(final PlotCluster cluster, final String id) { public static boolean removeClusterFlag(final PlotCluster cluster, final String id) {
final Flag flag = cluster.settings.flags.remove(id); final Flag flag = cluster.settings.flags.remove(id);
if (flag == null) { if (flag == null) {
@ -311,7 +321,7 @@ public class FlagManager {
DBFunc.setFlags(cluster, cluster.settings.flags.values()); DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true; return true;
} }
public static void setPlotFlags(final Plot origin, final Set<Flag> flags) { public static void setPlotFlags(final Plot origin, final Set<Flag> flags) {
for (Plot plot : origin.getConnectedPlots()) { for (Plot plot : origin.getConnectedPlots()) {
if (flags != null && !flags.isEmpty()) { if (flags != null && !flags.isEmpty()) {
@ -328,7 +338,7 @@ public class FlagManager {
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags().values());
} }
} }
public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags) { public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags) {
if (flags != null && !flags.isEmpty()) { if (flags != null && !flags.isEmpty()) {
cluster.settings.flags.clear(); cluster.settings.flags.clear();
@ -342,7 +352,7 @@ public class FlagManager {
} }
DBFunc.setFlags(cluster, cluster.settings.flags.values()); DBFunc.setFlags(cluster, cluster.settings.flags.values());
} }
public static Flag[] removeFlag(final Flag[] flags, final String r) { public static Flag[] removeFlag(final Flag[] flags, final String r) {
final Flag[] f = new Flag[flags.length - 1]; final Flag[] f = new Flag[flags.length - 1];
int index = 0; int index = 0;
@ -353,7 +363,7 @@ public class FlagManager {
} }
return f; return f;
} }
public static Set<Flag> removeFlag(final Set<Flag> flags, final String r) { public static Set<Flag> removeFlag(final Set<Flag> flags, final String r) {
final HashSet<Flag> newflags = new HashSet<>(); final HashSet<Flag> newflags = new HashSet<>();
for (final Flag flag : flags) { for (final Flag flag : flags) {
@ -363,7 +373,7 @@ public class FlagManager {
} }
return newflags; return newflags;
} }
/** /**
* Get a list of registered AbstractFlag objects * Get a list of registered AbstractFlag objects
* *
@ -372,7 +382,7 @@ public class FlagManager {
public static HashSet<AbstractFlag> getFlags() { public static HashSet<AbstractFlag> getFlags() {
return flags; return flags;
} }
/** /**
* Get a list of registered AbstractFlag objects based on player permissions * Get a list of registered AbstractFlag objects based on player permissions
* *
@ -389,7 +399,7 @@ public class FlagManager {
} }
return returnFlags; return returnFlags;
} }
/** /**
* Get an AbstractFlag by a string Returns null if flag does not exist * Get an AbstractFlag by a string Returns null if flag does not exist
* *
@ -405,7 +415,7 @@ public class FlagManager {
} }
return null; return null;
} }
/** /**
* Get an AbstractFlag by a string * Get an AbstractFlag by a string
* *
@ -420,7 +430,7 @@ public class FlagManager {
} }
return getFlag(string); return getFlag(string);
} }
/** /**
* Remove a registered AbstractFlag * Remove a registered AbstractFlag
* *
@ -431,7 +441,7 @@ public class FlagManager {
public static boolean removeFlag(final AbstractFlag flag) { public static boolean removeFlag(final AbstractFlag flag) {
return flags.remove(flag); return flags.remove(flag);
} }
public static HashMap<String, Flag> parseFlags(final List<String> flagstrings) { public static HashMap<String, Flag> parseFlags(final List<String> flagstrings) {
final HashMap<String, Flag> map = new HashMap<>(); final HashMap<String, Flag> map = new HashMap<>();
for (final String key : flagstrings) { for (final String key : flagstrings) {

View File

@ -23,17 +23,16 @@ package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
public interface GeneratorWrapper<T> { public interface GeneratorWrapper<T> {
public IndependentPlotGenerator getPlotGenerator();
public T getPlatformGenerator();
public void augment(PlotArea area); IndependentPlotGenerator getPlotGenerator();
public boolean isFull(); T getPlatformGenerator();
@Override void augment(PlotArea area);
public String toString();
boolean isFull();
@Override
public boolean equals(Object obj); @Override String toString();
@Override boolean equals(Object obj);
} }

View File

@ -32,7 +32,6 @@ import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -177,7 +176,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
PS.debug("&c - road schematics are disabled for this world."); PS.debug("&c - road schematics are disabled for this world.");
} }
} }
@Override @Override
public boolean isCompatible(PlotArea plotworld) { public boolean isCompatible(PlotArea plotworld) {
if (!(plotworld instanceof SquarePlotWorld)) { if (!(plotworld instanceof SquarePlotWorld)) {
@ -250,7 +249,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
} }
if (schem1 == null || schem2 == null || ROAD_WIDTH == 0) { if (schem1 == null || schem2 == null || ROAD_WIDTH == 0) {
PS.debug(C.PREFIX.s() + "&3 - schematic: &7false"); PS.debug(C.PREFIX + "&3 - schematic: &7false");
return; return;
} }
ROAD_SCHEMATIC_ENABLED = true; ROAD_SCHEMATIC_ENABLED = true;
@ -298,7 +297,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
} }
} }
public void addOverlayBlock(short x, final short y, short z, final short id, byte data, final boolean rotate) { public void addOverlayBlock(short x, final short y, short z, final short id, byte data, final boolean rotate) {
if (z < 0) { if (z < 0) {
z += SIZE; z += SIZE;

View File

@ -41,17 +41,17 @@ public abstract class SquarePlotManager extends GridPlotManager {
@Override @Override
public Location getPlotTopLocAbs(final PlotArea plotworld, final PlotId plotid) { public Location getPlotTopLocAbs(final PlotArea plotworld, final PlotId plotid) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = (SquarePlotWorld) plotworld;
final int px = plotid.x; final int px = plotid.x;
final int pz = plotid.y; final int pz = plotid.y;
final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - (int) Math.floor(dpw.ROAD_WIDTH / 2) - 1;
final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - (int) Math.floor(dpw.ROAD_WIDTH / 2) - 1;
return new Location(plotworld.worldname, x, Math.min(plotworld.MAX_BUILD_HEIGHT, 255), z); return new Location(plotworld.worldname, x, Math.min(plotworld.MAX_BUILD_HEIGHT, 255), z);
} }
@Override @Override
public PlotId getPlotIdAbs(final PlotArea plotworld, int x, final int y, int z) { public PlotId getPlotIdAbs(final PlotArea plotworld, int x, final int y, int z) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = (SquarePlotWorld) plotworld;
if (dpw.ROAD_OFFSET_X != 0) { if (dpw.ROAD_OFFSET_X != 0) {
x -= dpw.ROAD_OFFSET_X; x -= dpw.ROAD_OFFSET_X;
} }
@ -73,20 +73,20 @@ public abstract class SquarePlotManager extends GridPlotManager {
} }
final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
int idx; int idx;
int idz;
if (x < 0) { if (x < 0) {
idx = (x / size); idx = x / size;
x = size + (x % size); x = size + (x % size);
} else { } else {
idx = (x / size) + 1; idx = (x / size) + 1;
x = (x % size); x = x % size;
} }
int idz;
if (z < 0) { if (z < 0) {
idz = (z / size); idz = z / size;
z = size + (z % size); z = size + (z % size);
} else { } else {
idz = (z / size) + 1; idz = (z / size) + 1;
z = (z % size); z = z % size;
} }
return ((z <= pathWidthLower) || (z > end) || (x <= pathWidthLower) || (x > end)) ? null : new PlotId(idx, idz); return ((z <= pathWidthLower) || (z > end) || (x <= pathWidthLower) || (x > end)) ? null : new PlotId(idx, idz);
} }
@ -94,7 +94,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
@Override @Override
public PlotId getPlotId(final PlotArea plotworld, int x, final int y, int z) { public PlotId getPlotId(final PlotArea plotworld, int x, final int y, int z) {
try { try {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = (SquarePlotWorld) plotworld;
if (plotworld == null) { if (plotworld == null) {
return null; return null;
} }
@ -117,23 +117,23 @@ public abstract class SquarePlotManager extends GridPlotManager {
int dx; int dx;
int rx; int rx;
if (x < 0) { if (x < 0) {
dx = (x / size); dx = x / size;
rx = size + (x % size); rx = size + (x % size);
} else { } else {
dx = (x / size) + 1; dx = (x / size) + 1;
rx = (x % size); rx = x % size;
} }
int dz; int dz;
int rz; int rz;
if (z < 0) { if (z < 0) {
dz = (z / size); dz = z / size;
rz = size + (z % size); rz = size + (z % size);
} else { } else {
dz = (z / size) + 1; dz = (z / size) + 1;
rz = (z % size); rz = z % size;
} }
PlotId id = new PlotId(dx, dz); PlotId id = new PlotId(dx, dz);
boolean[] merged = new boolean[] { (rz <= pathWidthLower), (rx > end), (rz > end), (rx <= pathWidthLower) }; boolean[] merged = new boolean[]{rz <= pathWidthLower, rx > end, rz > end, rx <= pathWidthLower};
int hash = MainUtil.hash(merged); int hash = MainUtil.hash(merged);
// Not merged, and no need to check if it is // Not merged, and no need to check if it is
if (hash == 0) { if (hash == 0) {
@ -182,11 +182,11 @@ public abstract class SquarePlotManager extends GridPlotManager {
*/ */
@Override @Override
public Location getPlotBottomLocAbs(final PlotArea plotworld, final PlotId plotid) { public Location getPlotBottomLocAbs(final PlotArea plotworld, final PlotId plotid) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = (SquarePlotWorld) plotworld;
final int px = plotid.x; final int px = plotid.x;
final int pz = plotid.y; final int pz = plotid.y;
final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)); final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2);
final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)); final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2);
return new Location(plotworld.worldname, x, plotworld.MIN_BUILD_HEIGHT, z); return new Location(plotworld.worldname, x, plotworld.MIN_BUILD_HEIGHT, z);
} }
} }

View File

@ -1,8 +1,5 @@
package com.intellectualcrafters.plot.object.comment; package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -10,6 +7,9 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.util.ArrayList;
import java.util.List;
public class InboxOwner extends CommentInbox { public class InboxOwner extends CommentInbox {
@Override @Override
@ -17,10 +17,10 @@ public class InboxOwner extends CommentInbox {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString()); return Permissions.hasPermission(player, "plots.inbox.read." + toString());
} }
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read." .hasPermission(player, "plots.inbox.read."
+ toString() + toString()
+ ".other"))); + ".other"));
} }
@Override @Override
@ -28,9 +28,10 @@ public class InboxOwner extends CommentInbox {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString()); return Permissions.hasPermission(player, "plots.inbox.write." + toString());
} }
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write."
+ toString() + toString()
+ ".other"))); + ".other"));
} }
@Override @Override
@ -38,9 +39,10 @@ public class InboxOwner extends CommentInbox {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
} }
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.modify."
+ toString() + toString()
+ ".other"))); + ".other"));
} }
@Override @Override
@ -59,7 +61,7 @@ public class InboxOwner extends CommentInbox {
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
whenDone.value = value; whenDone.value = value;
if (value != null) { if (value != null) {
for (final PlotComment comment : (ArrayList<PlotComment>) value) { for (final PlotComment comment : value) {
plot.getSettings().addComment(comment); plot.getSettings().addComment(comment);
} }
} else { } else {

View File

@ -1,8 +1,5 @@
package com.intellectualcrafters.plot.object.comment; package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -10,6 +7,9 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.util.ArrayList;
import java.util.List;
public class InboxPublic extends CommentInbox { public class InboxPublic extends CommentInbox {
@Override @Override
@ -17,10 +17,10 @@ public class InboxPublic extends CommentInbox {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString()); return Permissions.hasPermission(player, "plots.inbox.read." + toString());
} }
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read." .hasPermission(player, "plots.inbox.read."
+ toString() + toString()
+ ".other"))); + ".other"));
} }
@Override @Override
@ -28,9 +28,10 @@ public class InboxPublic extends CommentInbox {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString()); return Permissions.hasPermission(player, "plots.inbox.write." + toString());
} }
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write."
+ toString() + toString()
+ ".other"))); + ".other"));
} }
@Override @Override
@ -38,9 +39,10 @@ public class InboxPublic extends CommentInbox {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
} }
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.modify."
+ toString() + toString()
+ ".other"))); + ".other"));
} }
@Override @Override
@ -59,7 +61,7 @@ public class InboxPublic extends CommentInbox {
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
whenDone.value = value; whenDone.value = value;
if (value != null) { if (value != null) {
for (final PlotComment comment : (ArrayList<PlotComment>) value) { for (final PlotComment comment : value) {
plot.getSettings().addComment(comment); plot.getSettings().addComment(comment);
} }
} }

View File

@ -6,7 +6,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
public class CmdConfirm { public class CmdConfirm {
public static CmdInstance getPending(final PlotPlayer player) { public static CmdInstance getPending(final PlotPlayer player) {
return player.<CmdInstance>getMeta("cmdConfirm"); return player.getMeta("cmdConfirm");
} }
public static void removePending(final PlotPlayer player) { public static void removePending(final PlotPlayer player) {

View File

@ -54,20 +54,22 @@ public class ExpireManager {
public void confirmExpiry(final PlotPlayer pp) { public void confirmExpiry(final PlotPlayer pp) {
if (Settings.AUTO_CLEAR_CONFIRMATION && plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) { if (Settings.AUTO_CLEAR_CONFIRMATION && plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) {
final int num = plotsToDelete.size(); final int num = plotsToDelete.size();
Iterator<Plot> iter = plotsToDelete.iterator(); for (final Plot current : plotsToDelete) {
while (iter.hasNext()) {
final Plot current = iter.next();
if (isExpired(current)) { if (isExpired(current)) {
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
pp.teleport(current.getCenter()); pp.teleport(current.getCenter());
PlotMessage msg = new PlotMessage() PlotMessage msg = new PlotMessage()
.text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired:").color("$1").command("/plot list expired").tooltip("/plot list expired") .text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired:").color("$1").command("/plot list expired")
.tooltip("/plot list expired")
//.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired") //.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired")
.text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").command("/plot delete").tooltip("/plot delete") .text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").command("/plot delete")
.text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").command("/plot set keep 1d").tooltip("/plot set keep 1d") .tooltip("/plot delete")
.text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").command("/plot set keep true").tooltip("/plot set keep true"); .text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").command("/plot set keep 1d")
.tooltip("/plot set keep 1d")
.text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").command("/plot set keep true")
.tooltip("/plot set keep true");
msg.send(pp); msg.send(pp);
} }
}); });
@ -75,7 +77,6 @@ public class ExpireManager {
} }
} }
plotsToDelete.clear(); plotsToDelete.clear();
return;
} }
} }
@ -247,7 +248,7 @@ public class ExpireManager {
return false; return false;
} }
final long compared = System.currentTimeMillis() - last; final long compared = System.currentTimeMillis() - last;
if (compared >= (TimeUnit.DAYS.toMillis(Settings.AUTO_CLEAR_DAYS))) { if (compared >= TimeUnit.DAYS.toMillis(Settings.AUTO_CLEAR_DAYS)) {
return true; return true;
} }
} }
@ -266,7 +267,7 @@ public class ExpireManager {
return false; return false;
} }
} else if (value instanceof Long) { } else if (value instanceof Long) {
if (((Long) value) > System.currentTimeMillis()) { if ((Long) value > System.currentTimeMillis()) {
return false; return false;
} }
} else { // Invalid? } else { // Invalid?

View File

@ -1,12 +1,12 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.util.HashMap;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandCaller; import com.plotsquared.general.commands.CommandCaller;
import java.util.HashMap;
/** /**
* The Permissions class handles checking user permissions.<br> * The Permissions class handles checking user permissions.<br>
* - This will respect * nodes and plots.admin and can be used to check permission ranges (e.g. plots.plot.5)<br> * - This will respect * nodes and plots.admin and can be used to check permission ranges (e.g. plots.plot.5)<br>
@ -34,7 +34,7 @@ public class Permissions {
if (!Settings.PERMISSION_CACHING) { if (!Settings.PERMISSION_CACHING) {
return hasPermission((CommandCaller) player, perm); return hasPermission((CommandCaller) player, perm);
} }
HashMap<String, Boolean> map = (HashMap<String, Boolean>) player.getMeta("perm"); HashMap<String, Boolean> map = player.getMeta("perm");
if (map != null) { if (map != null) {
Boolean result = map.get(perm); Boolean result = map.get(perm);
if (result != null) { if (result != null) {
@ -63,7 +63,7 @@ public class Permissions {
final String[] nodes = perm.split("\\."); final String[] nodes = perm.split("\\.");
final StringBuilder n = new StringBuilder(); final StringBuilder n = new StringBuilder();
for (int i = 0; i <= (nodes.length - 1); i++) { for (int i = 0; i <= (nodes.length - 1); i++) {
n.append(nodes[i] + (".")); n.append(nodes[i] + ".");
if (!perm.equals(n + C.PERMISSION_STAR.s())) { if (!perm.equals(n + C.PERMISSION_STAR.s())) {
if (player.hasPermission(n + C.PERMISSION_STAR.s())) { if (player.hasPermission(n + C.PERMISSION_STAR.s())) {
return true; return true;
@ -106,7 +106,7 @@ public class Permissions {
final String[] nodes = stub.split("\\."); final String[] nodes = stub.split("\\.");
final StringBuilder n = new StringBuilder(); final StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) { for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i] + (".")); n.append(nodes[i] + ".");
if (!stub.equals(n + C.PERMISSION_STAR.s())) { if (!stub.equals(n + C.PERMISSION_STAR.s())) {
if (player.hasPermission(n + C.PERMISSION_STAR.s())) { if (player.hasPermission(n + C.PERMISSION_STAR.s())) {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;

View File

@ -1,5 +1,5 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
public enum PlotGamemode { public enum PlotGamemode {
ADVENTURE, SURVIVAL, CREATIVE, SPECTATOR; ADVENTURE, SURVIVAL, CREATIVE, SPECTATOR
} }

View File

@ -1,5 +1,5 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
public enum PlotWeather { public enum PlotWeather {
RAIN, CLEAR, RESET; RAIN, CLEAR, RESET
} }

View File

@ -24,6 +24,7 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -166,7 +167,8 @@ public abstract class SchematicHandler {
final int HEIGHT = demensions.getY(); final int HEIGHT = demensions.getY();
// Validate dimensions // Validate dimensions
RegionWrapper region = plot.getLargestRegion(); RegionWrapper region = plot.getLargestRegion();
if ((((region.maxX - region.minX + x_offset) + 1) < WIDTH) || (((region.maxZ - region.minZ + z_offset) + 1) < LENGTH) || (HEIGHT > 256)) { if (((region.maxX - region.minX + x_offset + 1) < WIDTH) || ((region.maxZ - region.minZ + z_offset + 1) < LENGTH) || (HEIGHT
> 256)) {
PS.debug("Schematic is too large"); PS.debug("Schematic is too large");
PS.debug("(" + WIDTH + "," + LENGTH + "," + HEIGHT + ") is bigger than (" + (region.maxX - region.minX) + "," + (region.maxZ - region.minZ) + ",256)"); PS.debug("(" + WIDTH + "," + LENGTH + "," + HEIGHT + ") is bigger than (" + (region.maxX - region.minX) + "," + (region.maxZ - region.minZ) + ",256)");
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
@ -451,7 +453,7 @@ public abstract class SchematicHandler {
final List<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue(); final List<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue();
for (final Tag stateTag : blockStates) { for (final Tag stateTag : blockStates) {
try { try {
final CompoundTag ct = ((CompoundTag) stateTag); final CompoundTag ct = (CompoundTag) stateTag;
final Map<String, Tag> state = ct.getValue(); final Map<String, Tag> state = ct.getValue();
final short x = IntTag.class.cast(state.get("x")).getValue().shortValue(); final short x = IntTag.class.cast(state.get("x")).getValue().shortValue();
final short y = IntTag.class.cast(state.get("y")).getValue().shortValue(); final short y = IntTag.class.cast(state.get("y")).getValue().shortValue();
@ -782,15 +784,15 @@ public abstract class SchematicHandler {
int dz = schematicDimension.getZ(); int dz = schematicDimension.getZ();
for (int y = y1; y <= y2; y++) { for (int y = y1; y <= y2; y++) {
int yy = y >= 0 ? (y < dy ? y : y - dy) : y + dy; int yy = y >= 0 ? y < dy ? y : y - dy : y + dy;
int i1 = yy * dx * dz; int i1 = yy * dx * dz;
int j1 = (y - y1) * width * length; int j1 = (y - y1) * width * length;
for (int z = z1; z <= z2; z++) { for (int z = z1; z <= z2; z++) {
int zz = z >= 0 ? (z < dz ? z : z - dz) : z + dz; int zz = z >= 0 ? z < dz ? z : z - dz : z + dz;
int i2 = i1 + zz * dx; int i2 = i1 + zz * dx;
int j2 = j1 + (z - z1) * width; int j2 = j1 + (z - z1) * width;
for (int x = x1; x <= x2; x++) { for (int x = x1; x <= x2; x++) {
int xx = x >= 0 ? (x < dx ? x : x - dx) : x + dx; int xx = x >= 0 ? x < dx ? x : x - dx : x + dx;
int i3 = i2 + xx; int i3 = i2 + xx;
int j3 = j2 + (x - x1); int j3 = j2 + (x - x1);
ids2[j3] = ids[i3]; ids2[j3] = ids[i3];

View File

@ -179,7 +179,7 @@ public class SetQueue {
return false; return false;
} }
final ChunkWrapper other = (ChunkWrapper) obj; final ChunkWrapper other = (ChunkWrapper) obj;
return ((x == other.x) && (z == other.z) && (StringMan.isEqual(world, other.world))); return (x == other.x) && (z == other.z) && StringMan.isEqual(world, other.world);
} }
@Override @Override

View File

@ -14,7 +14,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -29,19 +28,19 @@ public abstract class UUIDHandlerImplementation {
public UUIDWrapper uuidWrapper = null; public UUIDWrapper uuidWrapper = null;
public HashSet<UUID> unknown = new HashSet<>(); public HashSet<UUID> unknown = new HashSet<>();
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>()); private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
public UUIDHandlerImplementation(final UUIDWrapper wrapper) { public UUIDHandlerImplementation(final UUIDWrapper wrapper) {
uuidWrapper = wrapper; uuidWrapper = wrapper;
players = new ConcurrentHashMap<>(); players = new ConcurrentHashMap<>();
} }
/** /**
* 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
*/ */
public abstract void fetchUUID(final String name, final RunnableVal<UUID> ifFetch); public abstract void fetchUUID(final String name, final RunnableVal<UUID> ifFetch);
/** /**
* Start UUID caching (this should be an async task) * Start UUID caching (this should be an async task)
* Recommended to override this is you want to cache offline players * Recommended to override this is you want to cache offline players
@ -52,20 +51,20 @@ public abstract class UUIDHandlerImplementation {
} }
return CACHED = true; return CACHED = true;
} }
public UUIDWrapper getUUIDWrapper() { public UUIDWrapper getUUIDWrapper() {
return uuidWrapper; return uuidWrapper;
} }
public void setUUIDWrapper(final UUIDWrapper wrapper) { public void setUUIDWrapper(final UUIDWrapper wrapper) {
uuidWrapper = wrapper; uuidWrapper = wrapper;
} }
public void rename(final UUID uuid, final StringWrapper name) { public void rename(final UUID uuid, final StringWrapper name) {
uuidMap.inverse().remove(uuid); uuidMap.inverse().remove(uuid);
uuidMap.put(name, uuid); uuidMap.put(name, uuid);
} }
public void add(final BiMap<StringWrapper, UUID> toAdd) { public void add(final BiMap<StringWrapper, UUID> toAdd) {
if (uuidMap.isEmpty()) { if (uuidMap.isEmpty()) {
uuidMap = toAdd; uuidMap = toAdd;
@ -86,9 +85,9 @@ public abstract class UUIDHandlerImplementation {
} }
uuidMap.put(name, uuid); uuidMap.put(name, uuid);
} }
PS.debug(C.PREFIX.s() + "&6Cached a total of: " + uuidMap.size() + " UUIDs"); PS.debug(C.PREFIX + "&6Cached a total of: " + uuidMap.size() + " UUIDs");
} }
public boolean add(final StringWrapper name, final UUID uuid) { public boolean add(final StringWrapper name, final UUID uuid) {
if ((uuid == null)) { if ((uuid == null)) {
return false; return false;
@ -102,7 +101,7 @@ public abstract class UUIDHandlerImplementation {
} }
return false; return false;
} }
/* /*
* 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
@ -165,25 +164,25 @@ public abstract class UUIDHandlerImplementation {
} }
return true; return true;
} }
public boolean uuidExists(final UUID uuid) { public boolean uuidExists(final UUID uuid) {
return uuidMap.containsValue(uuid); return uuidMap.containsValue(uuid);
} }
public BiMap<StringWrapper, UUID> getUUIDMap() { public BiMap<StringWrapper, UUID> getUUIDMap() {
return uuidMap; return uuidMap;
} }
public boolean nameExists(final StringWrapper wrapper) { public boolean nameExists(final StringWrapper wrapper) {
return uuidMap.containsKey(wrapper); return uuidMap.containsKey(wrapper);
} }
public void handleShutdown() { public void handleShutdown() {
players.clear(); players.clear();
uuidMap.clear(); uuidMap.clear();
uuidWrapper = null; uuidWrapper = null;
} }
public String getName(final UUID uuid) { public String getName(final UUID uuid) {
if (uuid == null) { if (uuid == null) {
return null; return null;
@ -200,7 +199,7 @@ public abstract class UUIDHandlerImplementation {
} }
return null; return null;
} }
public UUID getUUID(final String name, final RunnableVal<UUID> ifFetch) { public UUID getUUID(final String name, final RunnableVal<UUID> ifFetch) {
if ((name == null) || (name.isEmpty())) { if ((name == null) || (name.isEmpty())) {
return null; return null;
@ -228,15 +227,15 @@ public abstract class UUIDHandlerImplementation {
} }
return null; return null;
} }
public UUID getUUID(final PlotPlayer player) { public UUID getUUID(final PlotPlayer player) {
return uuidWrapper.getUUID(player); return uuidWrapper.getUUID(player);
} }
public UUID getUUID(final OfflinePlotPlayer player) { public UUID getUUID(final OfflinePlotPlayer player) {
return uuidWrapper.getUUID(player); return uuidWrapper.getUUID(player);
} }
public PlotPlayer getPlayer(final UUID uuid) { public PlotPlayer getPlayer(final UUID uuid) {
String name = getName(uuid); String name = getName(uuid);
if (name != null) { if (name != null) {
@ -244,13 +243,13 @@ public abstract class UUIDHandlerImplementation {
} }
return null; return null;
} }
public PlotPlayer getPlayer(final String name) { public PlotPlayer getPlayer(final String name) {
return players.get(name); return players.get(name);
} }
public Map<String, PlotPlayer> getPlayers() { public Map<String, PlotPlayer> getPlayers() {
return players; return players;
} }
} }

View File

@ -1,36 +1,35 @@
package com.intellectualcrafters.plot.util.helpmenu; package com.intellectualcrafters.plot.util.helpmenu;
import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.commands.CommandCategory; import com.intellectualcrafters.plot.commands.CommandCategory;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import java.util.ArrayList;
import java.util.List;
public class HelpPage { public class HelpPage {
private final List<HelpObject> helpObjects; private final List<HelpObject> helpObjects;
private final String _header; private final String _header;
public HelpPage(final CommandCategory category, final int currentPage, final int maxPages) { public HelpPage(final CommandCategory category, final int currentPage, final int maxPages) {
helpObjects = new ArrayList<>(); helpObjects = new ArrayList<>();
_header = C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "ALL" : category.toString()).replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + ""); _header = C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "ALL" : category.toString()).replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + "");
} }
public void render(final PlotPlayer player) { public void render(final PlotPlayer player) {
if (helpObjects.size() < 1) { if (helpObjects.size() < 1) {
MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)"); MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)");
} else { } else {
MainUtil.sendMessage(player, C.HELP_HEADER.s(), false); MainUtil.sendMessage(player, C.HELP_HEADER, false);
MainUtil.sendMessage(player, _header, false); MainUtil.sendMessage(player, _header, false);
for (final HelpObject object : helpObjects) { for (final HelpObject object : helpObjects) {
MainUtil.sendMessage(player, object.toString(), false); MainUtil.sendMessage(player, object.toString(), false);
} }
MainUtil.sendMessage(player, C.HELP_FOOTER.s(), false); MainUtil.sendMessage(player, C.HELP_FOOTER, false);
} }
} }
public void addHelpItem(final HelpObject object) { public void addHelpItem(final HelpObject object) {
helpObjects.add(object); helpObjects.add(object);
} }

View File

@ -85,10 +85,14 @@ public class CommandManager<T extends CommandCaller> {
} }
public int handle(final T plr, String input) { public int handle(final T plr, String input) {
if ((initialCharacter != null) && !input.startsWith(initialCharacter + "")) { if (initialCharacter != null && !input.startsWith(initialCharacter + "")) {
return CommandHandlingOutput.NOT_COMMAND; return CommandHandlingOutput.NOT_COMMAND;
} }
input = initialCharacter == null ? input : input.substring(1); if (initialCharacter == null) {
input = input;
} else {
input = input.substring(1);
}
final String[] parts = input.split(" "); final String[] parts = input.split(" ");
String[] args; String[] args;
final String command = parts[0].toLowerCase(); final String command = parts[0].toLowerCase();

View File

@ -29,8 +29,17 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.CommentManager;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -40,7 +49,7 @@ import java.util.UUID;
*/ */
public class PlotListener { public class PlotListener {
public static boolean plotEntry(final PlotPlayer pp, final Plot plot) { public static boolean plotEntry(final PlotPlayer pp, final Plot plot) {
if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) { if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) {
return false; return false;
@ -59,7 +68,7 @@ public class PlotListener {
final int size = flags.size(); final int size = flags.size();
boolean titles = Settings.TITLES; boolean titles = Settings.TITLES;
final String greeting; final String greeting;
if (size != 0) { if (size != 0) {
final Flag titleFlag = flags.get("titles"); final Flag titleFlag = flags.get("titles");
if (titleFlag != null) { if (titleFlag != null) {
@ -115,7 +124,7 @@ public class PlotListener {
if (weatherFlag != null) { if (weatherFlag != null) {
pp.setWeather((PlotWeather) weatherFlag.getValue()); pp.setWeather((PlotWeather) weatherFlag.getValue());
} }
final Flag musicFlag = flags.get("music"); final Flag musicFlag = flags.get("music");
if (musicFlag != null) { if (musicFlag != null) {
final Integer id = (Integer) musicFlag.getValue(); final Integer id = (Integer) musicFlag.getValue();
@ -174,7 +183,7 @@ public class PlotListener {
} }
return true; return true;
} }
public static boolean plotExit(final PlotPlayer pp, final Plot plot) { public static boolean plotExit(final PlotPlayer pp, final Plot plot) {
pp.deleteMeta("lastplot"); pp.deleteMeta("lastplot");
EventUtil.manager.callLeave(pp, plot); EventUtil.manager.callLeave(pp, plot);

View File

@ -17,6 +17,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
dependencies { dependencies {
compile project(':Core') compile project(':Core')
compile 'org.spongepowered:spongeapi:4.0.3' compile 'org.spongepowered:spongeapi:4.0.3'
compile 'org.mcstats.sponge:metrics:R8-SNAPSHOT'
} }
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@ -31,6 +32,10 @@ repositories {
name = "Sponge" name = "Sponge"
url = "https://repo.spongepowered.org/maven" url = "https://repo.spongepowered.org/maven"
} }
maven {
name = "Sponge Metrics"
url = "http://repo.mcstats.org/content/repositories/releases/"
}
} }
minecraft { minecraft {
version = "1.8.9-11.15.1.1742" version = "1.8.9-11.15.1.1742"
@ -49,7 +54,9 @@ processResources {
shadowJar { shadowJar {
dependencies { dependencies {
include(dependency(':Core')) include(dependency(':Core'))
include(dependency('org.mcstats.sponge:metrics:R8-SNAPSHOT'))
} }
relocate 'org.mcstats', 'com.plotsquared.stats'
archiveName = "${parent.name}-${project.name}-${parent.version}.jar" archiveName = "${parent.name}-${project.name}-${parent.version}.jar"
destinationDir = file '../target' destinationDir = file '../target'
} }

View File

@ -41,7 +41,6 @@ import com.plotsquared.sponge.util.SpongeEconHandler;
import com.plotsquared.sponge.util.SpongeEventUtil; import com.plotsquared.sponge.util.SpongeEventUtil;
import com.plotsquared.sponge.util.SpongeHybridUtils; import com.plotsquared.sponge.util.SpongeHybridUtils;
import com.plotsquared.sponge.util.SpongeInventoryUtil; import com.plotsquared.sponge.util.SpongeInventoryUtil;
import com.plotsquared.sponge.util.SpongeMetrics;
import com.plotsquared.sponge.util.SpongeSchematicHandler; import com.plotsquared.sponge.util.SpongeSchematicHandler;
import com.plotsquared.sponge.util.SpongeSetupUtils; import com.plotsquared.sponge.util.SpongeSetupUtils;
import com.plotsquared.sponge.util.SpongeTaskManager; import com.plotsquared.sponge.util.SpongeTaskManager;
@ -52,6 +51,7 @@ import com.plotsquared.sponge.util.block.SlowQueue;
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeUUIDHandler; import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
import org.mcstats.Metrics;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.Server; import org.spongepowered.api.Server;
@ -70,6 +70,7 @@ import org.spongepowered.api.world.gen.WorldGenerator;
import org.spongepowered.api.world.gen.WorldGeneratorModifier; import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -303,10 +304,10 @@ public class SpongeMain implements IPlotMain {
@Override @Override
public void startMetrics() { public void startMetrics() {
try { try {
final SpongeMetrics metrics = new SpongeMetrics(game, (PluginContainer) this); Metrics metrics = new Metrics(game, (PluginContainer) this);
metrics.start(); metrics.start();
log(C.PREFIX.s() + "&6Metrics enabled."); log(C.PREFIX.s() + "&6Metrics enabled.");
} catch (final Exception e) { } catch (IOException e) {
log(C.PREFIX.s() + "&cFailed to load up metrics."); log(C.PREFIX.s() + "&cFailed to load up metrics.");
} }
} }

View File

@ -18,9 +18,10 @@ import java.util.List;
public class SpongeAugmentedGenerator implements GenerationPopulator { public class SpongeAugmentedGenerator implements GenerationPopulator {
private static SpongeAugmentedGenerator generator; private static SpongeAugmentedGenerator generator;
private SpongeAugmentedGenerator() {}; private SpongeAugmentedGenerator() {
}
public static SpongeAugmentedGenerator get(World world) { public static SpongeAugmentedGenerator get(World world) {
WorldGenerator wg = world.getWorldGenerator(); WorldGenerator wg = world.getWorldGenerator();
List<GenerationPopulator> populators = wg.getGenerationPopulators(); List<GenerationPopulator> populators = wg.getGenerationPopulators();

View File

@ -84,7 +84,7 @@ public class MainListener {
if (Settings.USE_PLOTME_ALIAS) { if (Settings.USE_PLOTME_ALIAS) {
SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim()); SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
} else { } else {
source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME.s())); source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME));
} }
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -1,518 +0,0 @@
package com.plotsquared.sponge.util;
/*
* Copyright 2011-2013 Tyler Blair. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and contributors and should not be interpreted as representing official policies,
* either expressed or implied, of anybody else.
*/
import com.google.inject.Inject;
import com.intellectualcrafters.plot.PS;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.spongepowered.api.Game;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.scheduler.Task;
public class SpongeMetrics {
/**
* The current revision number
*/
private final static int REVISION = 7;
/**
* The base url of the metrics domain
*/
private static final String BASE_URL = "http://report.mcstats.org";
/**
* The url used to report a server's status
*/
private static final String REPORT_URL = "/plugin/%s";
/**
* Interval of time to ping (in minutes)
*/
private static final int PING_INTERVAL = 15;
/**
* The game data is being sent for
*/
private final Game game;
/**
* The plugin this metrics submits for
*/
private final PluginContainer plugin;
/**
* Lock for synchronization
*/
private final Object optOutLock = new Object();
/**
* The plugin configuration file
*/
private CommentedConfigurationNode config;
/**
* The configuration loader
*/
private ConfigurationLoader<CommentedConfigurationNode> configurationLoader;
/**
* The plugin configuration file
*/
private File configurationFile;
/**
* Unique server id
*/
private String guid;
/**
* Debug mode
*/
private boolean debug;
/**
* The scheduled task
*/
private volatile Task task = null;
@Inject
public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
this.game = game;
this.plugin = plugin;
loadConfiguration();
}
/**
* GZip compress a string of bytes
*
* @param input
* @return
*/
public static byte[] gzip(final String input) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes("UTF-8"));
} catch (final IOException e) {
e.printStackTrace();
} finally {
if (gzos != null) {
try {
gzos.close();
} catch (final IOException ignore) {
}
}
}
return baos.toByteArray();
}
/**
* Appends a json encoded key/value pair to the given string builder.
*
* @param json
* @param key
* @param value
* @throws java.io.UnsupportedEncodingException
*/
private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false;
try {
if (value.equals("0") || !value.endsWith("0")) {
Double.parseDouble(value);
isValueNumeric = true;
}
} catch (final NumberFormatException e) {
isValueNumeric = false;
}
if (json.charAt(json.length() - 1) != '{') {
json.append(',');
}
json.append(escapeJSON(key));
json.append(':');
if (isValueNumeric) {
json.append(value);
} else {
json.append(escapeJSON(value));
}
}
/**
* Escape a string to create a valid JSON string
*
* @param text
* @return
*/
private static String escapeJSON(final String text) {
final StringBuilder builder = new StringBuilder();
builder.append('"');
for (int index = 0; index < text.length(); index++) {
final char chr = text.charAt(index);
switch (chr) {
case '"':
case '\\':
builder.append('\\');
builder.append(chr);
break;
case '\b':
builder.append("\\b");
break;
case '\t':
builder.append("\\t");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
default:
if (chr < ' ') {
final String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4));
} else {
builder.append(chr);
}
break;
}
}
builder.append('"');
return builder.toString();
}
/**
* Encode text as UTF-8
*
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String urlEncode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/**
* Loads the configuration
*/
private void loadConfiguration() {
configurationFile = getConfigFile();
configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build();
try {
if (!configurationFile.exists()) {
configurationFile.createNewFile();
config = configurationLoader.load();
config.setComment("This contains settings for MCStats: http://mcstats.org");
config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString());
config.getNode("mcstats.opt-out").setValue(false);
config.getNode("mcstats.debug").setValue(false);
configurationLoader.save(config);
} else {
config = configurationLoader.load();
}
guid = config.getNode("mcstats.guid").getString();
debug = config.getNode("mcstats.debug").getBoolean();
} catch (final IOException e) {
e.printStackTrace();
}
}
/**
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
* ticks.
*
* @return True if statistics measuring is running, otherwise false.
*/
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
}
// Is metrics already running?
if (task != null) {
return true;
}
// Begin hitting the server with glorious data
final Task.Builder builder = game.getScheduler().createTaskBuilder();
builder.async().interval(PING_INTERVAL, TimeUnit.MINUTES).execute(new Runnable() {
private boolean firstPost = true;
@Override
public void run() {
try {
// This has to be synchronized or it can collide with the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the server owner decided to opt-out
if (isOptOut() && (task != null)) {
task.cancel();
task = null;
}
}
// We use the inverse of firstPost because if it is the first time we are posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e PING!
postPlugin(!firstPost);
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch (final IOException e) {
if (debug) {
PS.debug("[Metrics] " + e.getMessage());
}
}
}
});
return true;
}
}
/**
* Has the server owner denied plugin metrics?
*
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized (optOutLock) {
loadConfiguration();
return config.getNode("mcstats.opt-out").getBoolean();
}
}
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws java.io.IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
config.getNode("mcstats.opt-out").setValue(false);
configurationLoader.save(config);
}
// Enable Task, if it is not running
if (task == null) {
start();
}
}
}
/**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
*
* @throws java.io.IOException
*/
public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (!isOptOut()) {
config.getNode("mcstats.opt-out").setValue(true);
configurationLoader.save(config);
}
// Disable Task, if it is running
if (task != null) {
task.cancel();
task = null;
}
}
}
/**
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
*
* @return the File object for the config file
*/
public File getConfigFile() {
// TODO configDir
final File configFolder = new File("config");
return new File(configFolder, "PluginMetrics.conf");
}
/**
* Generic method that posts a plugin to the metrics website
*
*/
private void postPlugin(final boolean isPing) throws IOException {
// Server software specific section
final String pluginName = plugin.getName();
final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
final String pluginVersion = plugin.getVersion().get();
// TODO no visible way to get MC version at the moment
// TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1
final String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion());
final int playersOnline = game.getServer().getOnlinePlayers().size();
// END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data
final StringBuilder json = new StringBuilder(1024);
json.append('{');
// The plugin's description file containg all of the plugin data such as name, version, author, etc
appendJSONPair(json, "guid", guid);
appendJSONPair(json, "plugin_version", pluginVersion);
appendJSONPair(json, "server_version", serverVersion);
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
// New data as of R6
final String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
final String osversion = System.getProperty("os.version");
final String java_version = System.getProperty("java.version");
final int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) {
osarch = "x86_64";
}
appendJSONPair(json, "osname", osname);
appendJSONPair(json, "osarch", osarch);
appendJSONPair(json, "osversion", osversion);
appendJSONPair(json, "cores", Integer.toString(coreCount));
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
appendJSONPair(json, "java_version", java_version);
// If we're pinging, append it
if (isPing) {
appendJSONPair(json, "ping", "1");
}
// close json
json.append('}');
// Create the url
final URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
// Connect to the website
URLConnection connection;
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
final byte[] uncompressed = json.toString().getBytes();
final byte[] compressed = gzip(json.toString());
// Headers
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("Content-Encoding", "gzip");
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.setDoOutput(true);
if (debug) {
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
}
// Write the data
final OutputStream os = connection.getOutputStream();
os.write(compressed);
os.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = reader.readLine();
// close resources
os.close();
reader.close();
if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) {
if (response == null) {
response = "null";
} else if (response.startsWith("7")) {
response = response.substring(response.startsWith("7,") ? 2 : 1);
}
throw new IOException(response);
}
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
*
* @return true if mineshafter is installed on the server
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (final Exception e) {
return false;
}
}
}

View File

@ -86,7 +86,7 @@ public class SpongeUtil extends WorldUtil {
System.out.println(method + ": " + cause.toString()); System.out.println(method + ": " + cause.toString());
System.out.println(method + ": " + cause.getClass()); System.out.println(method + ": " + cause.getClass());
System.out.println(method + ": " + StringMan.getString(cause.all())); System.out.println(method + ": " + StringMan.getString(cause.all()));
System.out.println(method + ": " + (cause.root())); System.out.println(method + ": " + cause.root());
} }
public static void initBiomeCache() { public static void initBiomeCache() {
@ -291,7 +291,7 @@ public class SpongeUtil extends WorldUtil {
id = Short.parseShort(split[0]); id = Short.parseShort(split[0]);
match = 0; match = 0;
} else { } else {
List<BlockType> types = ReflectionUtils.<BlockType>getStaticFields(BlockTypes.class); List<BlockType> types = ReflectionUtils.getStaticFields(BlockTypes.class);
final StringComparison<BlockType>.ComparisonResult comparison = final StringComparison<BlockType>.ComparisonResult comparison =
new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) { new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
@Override @Override