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.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@ -70,7 +69,7 @@ public class PlotAPI {
/**
* Permission that allows for admin access, this permission node will allow the player to use any part of the
* plugin, without limitations.
* @deprecated Use C.PERMISSION_ADMIN.s() instead
* @deprecated Use C.PERMISSION_ADMIN instead
*/
@Deprecated
public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s();
@ -400,7 +399,7 @@ public class PlotAPI {
* @see com.intellectualcrafters.plot.config.C
*/
public void sendConsoleMessage(final C c) {
sendConsoleMessage(c.s());
sendConsoleMessage(c);
}
/**

View File

@ -87,7 +87,6 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -192,7 +191,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
public void runEntityTask() {
log(C.PREFIX.s() + "KillAllEntities started.");
log(C.PREFIX + "KillAllEntities started.");
TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
@ -514,7 +513,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
Settings.OFFLINE_MODE = true;
}
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;
FlagManager.removeFlag(FlagManager.getFlag("titles"));
} else {
@ -524,9 +523,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
}
}
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 {
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);
}
@ -571,9 +570,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
try {
Metrics metrics = new Metrics(this);
metrics.start();
log(C.PREFIX.s() + "&6Metrics enabled.");
log(C.PREFIX + "&6Metrics enabled.");
} catch (IOException e) {
log(C.PREFIX.s() + "&cFailed to load up metrics.");
log(C.PREFIX + "&cFailed to load up metrics.");
}
}

View File

@ -70,7 +70,7 @@ public abstract class TextualComponent implements Cloneable {
}
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.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
@ -142,7 +141,7 @@ public class DebugUUID extends SubCommand {
final UUID uuid = UUID.fromString(s);
uuids.add(uuid);
} 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");
@ -172,7 +171,7 @@ public class DebugUUID extends SubCommand {
uCReverse.put(uuid2, uuid);
}
} 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) {

View File

@ -53,16 +53,16 @@ public abstract class APlotMeConnector {
public Location getPlotTopLocAbs(final int path, final int plot, final PlotId plotid) {
final int px = plotid.x;
final int pz = plotid.y;
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 x = (px * (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);
}
public Location getPlotBottomLocAbs(final int path, final int plot, final PlotId plotid) {
final int px = plotid.x;
final int pz = plotid.y;
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 x = (px * (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);
}

View File

@ -20,16 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
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.object.Location;
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.object.BukkitPlayer;
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 {
private Set<PlotPlayer> getNearbyPlayers(final Player player, final Plot plot) {
@ -73,17 +73,19 @@ public class ForceFieldListener implements Listener {
Location oPlayerLocation = e.getLocation();
final double playerX = playerLocation.getX(), playerY = playerLocation.getY(), playerZ = playerLocation.getZ(), oPlayerX = oPlayerLocation.getX(), oPlayerY = oPlayerLocation.getY(), oPlayerZ = oPlayerLocation
.getZ();
double x = 0d, y = 0d, z = 0d;
double x = 0d;
if (playerX < oPlayerX) {
x = 1.0d;
} else if (playerX > oPlayerX) {
x = -1.0d;
}
double y = 0d;
if (playerY < oPlayerY) {
y = 0.5d;
} else if (playerY > oPlayerY) {
y = -0.5d;
}
double z = 0d;
if (playerZ < oPlayerZ) {
z = 1.0d;
} 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)) {
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);
event.setCancelled(true);
}
@ -1165,6 +1170,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
default:
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)) {
event.setCancelled(true);
}

View File

@ -2,19 +2,64 @@ package com.plotsquared.bukkit.util;
import com.intellectualcrafters.plot.PS;
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.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 org.bukkit.*;
import org.bukkit.block.*;
import org.bukkit.Bukkit;
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.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.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.Set;
public class BukkitChunkManager extends ChunkManager {
@ -595,7 +640,6 @@ public class BukkitChunkManager extends ChunkManager {
}
}
while (SetQueue.IMP.forceChunkSet()) {
;
}
restoreBlocks(world1, 0, 0);
restoreEntities(world1, 0, 0);

View File

@ -20,7 +20,13 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
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.Location;
import com.intellectualcrafters.plot.object.RegionWrapper;
@ -35,8 +41,13 @@ import org.bukkit.World;
import org.bukkit.block.Block;
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.Set;
/**
* Schematic Handler
@ -73,7 +84,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
// 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[] blockData = new byte[width * height * length];
// Queue
@ -126,7 +137,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
@Override
public void run() {
final long start = System.currentTimeMillis();
while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) {
while (!chunks.isEmpty() && ((System.currentTimeMillis() - start) < 20)) {
// save schematics
final ChunkLoc chunk = chunks.remove(0);
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++) {
final int ry = y - sy;
final int i1 = (ry * width * length);
final int i1 = ry * width * length;
for (int z = zzb; z <= zzt; z++) {
final int rz = z - bz;
final int i2 = i1 + (rz * width);
@ -275,7 +286,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
final StateWrapper wrapper = new StateWrapper(state);
final CompoundTag rawTag = wrapper.getTag();
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()) {
values.put(entry.getKey(), entry.getValue());
}
@ -283,7 +294,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
values.put("x", new IntTag("x", x));
values.put("y", new IntTag("y", y));
values.put("z", new IntTag("z", z));
final CompoundTag tileEntityTag = new CompoundTag(values);
CompoundTag tileEntityTag = new CompoundTag(values);
tileEntities.add(tileEntityTag);
}
}

View File

@ -227,10 +227,8 @@ public class FastQueue_1_9 extends SlowQueue {
int x = MainUtil.x_loc[j][k];
int y = MainUtil.y_loc[j][k];
int z = MainUtil.z_loc[j][k];
int id = n;
Object iblock = methodGetByCombinedId.call((int) n);
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.RunnableVal;
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.plotsquared.bukkit.util.NbtFactory;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
@ -50,7 +53,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
TaskManager.runTaskAsync(new Runnable() {
@Override
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");
if (uuidfile.exists()) {
try {
@ -112,7 +115,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
}
} catch (final Exception e) {
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);
uuids.add(uuid);
} catch (final Exception e) {
PS.debug(C.PREFIX.s() + "Invalid playerdata: " + current);
PS.debug(C.PREFIX + "Invalid playerdata: " + current);
}
}
break;
@ -195,7 +198,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
}
toAdd.put(new StringWrapper(name), uuid);
} 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) {

View File

@ -1,22 +1,5 @@
package com.plotsquared.bukkit.uuid;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.HashMap;
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;
@ -29,6 +12,22 @@ 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.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.HashMap;
import java.util.UUID;
public class SQLUUIDHandler extends UUIDHandlerImplementation {
@ -76,11 +75,9 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
final PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
final ResultSet resultSet = statement.executeQuery();
StringWrapper username;
UUID uuid;
while (resultSet.next()) {
username = new StringWrapper(resultSet.getString("username"));
uuid = UUID.fromString(resultSet.getString("uuid"));
StringWrapper username = new StringWrapper(resultSet.getString("username"));
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
toAdd.put(new StringWrapper(username.value), uuid);
}
statement.close();
@ -198,7 +195,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
@Override
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) {
return;
}
@ -253,7 +250,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
statement.setString(1, uuid.toString());
statement.setString(2, name.toString());
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) {
e.printStackTrace();
}
@ -278,7 +275,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
statement.setString(1, name.value);
statement.setString(2, uuid.toString());
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) {
e.printStackTrace();
}

View File

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

View File

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

View File

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

View File

@ -342,7 +342,7 @@ public class JSONTokener {
}
back();
string = sb.toString().trim();
if ("".equals(string)) {
if (string != null && string.isEmpty()) {
throw syntaxError("Missing value");
}
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.plotsquared.listener.WESubscriber;
import com.sk89q.worldedit.WorldEdit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -165,7 +164,7 @@ public class PS {
}
TASK = IMP.getTaskManager();
if (!C.ENABLED.s().isEmpty()) {
log(C.ENABLED.s());
log(C.ENABLED);
}
setupConfigs();
translationFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "PlotSquared.use_THIS.yml");
@ -1370,10 +1369,10 @@ public class PS {
// Conventional plot generator
PlotArea plotArea = pg.getNewPlotArea(world, null, null, null);
PlotManager plotManager = pg.getNewPlotManager();
log(C.PREFIX.s() + "&aDetected world load for '" + world + "'");
log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + pg);
log(C.PREFIX.s() + "&3 - plotworld: &7" + plotArea.getClass().getName());
log(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName());
log(C.PREFIX + "&aDetected world load for '" + world + "'");
log(C.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + pg);
log(C.PREFIX + "&3 - plotworld: &7" + plotArea.getClass().getName());
log(C.PREFIX + "&3 - manager: &7" + plotManager.getClass().getName());
if (!config.contains(path)) {
config.createSection(path);
worldSection = config.getConfigurationSection(path);
@ -1399,7 +1398,7 @@ public class PS {
PS.debug("World possibly already loaded: " + world);
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");
if (type == 2) {
Set<PlotCluster> clusters = clusters_tmp != null ? clusters_tmp.get(world) : new HashSet<PlotCluster>();
@ -1415,7 +1414,7 @@ public class PS {
worldSection.createSection("areas." + fullId);
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);
if (areaGen == null) {
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
@ -1428,10 +1427,10 @@ public class PS {
} catch (final IOException e) {
e.printStackTrace();
}
log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa);
log(C.PREFIX.s() + "&c | &9manager: &7" + pa);
log(C.PREFIX.s() + "&cNote: &7Area created for cluster:" + name + " (invalid or old configuration?)");
log(C.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX + "&c | &9plotworld: &7" + pa);
log(C.PREFIX + "&c | &9manager: &7" + pa);
log(C.PREFIX + "&cNote: &7Area created for cluster:" + name + " (invalid or old configuration?)");
areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa);
toLoad.add(pa);
@ -1453,9 +1452,9 @@ public class PS {
} catch (final IOException e) {
e.printStackTrace();
}
log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX.s() + "&3 - plotworld: &7" + pa);
log(C.PREFIX.s() + "&3 - manager: &7" + pa.getPlotManager());
log(C.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX + "&3 - plotworld: &7" + pa);
log(C.PREFIX + "&3 - manager: &7" + pa.getPlotManager());
areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa);
addPlotArea(pa);
@ -1465,7 +1464,7 @@ public class PS {
throw new IllegalArgumentException("Invalid type for multi-area world. Expected `2`, got `" + type + "`");
}
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+)");
if (split.length != 3) {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<pos1>-<pos2>`");
@ -1524,10 +1523,10 @@ public class PS {
} catch (final IOException e) {
e.printStackTrace();
}
log(C.PREFIX.s() + "&aDetected area load for '" + world + "'");
log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa);
log(C.PREFIX.s() + "&c | &9manager: &7" + pa.getPlotManager());
log(C.PREFIX + "&aDetected area load for '" + world + "'");
log(C.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
log(C.PREFIX + "&c | &9plotworld: &7" + pa);
log(C.PREFIX + "&c | &9manager: &7" + pa.getPlotManager());
areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa);
addPlotArea(pa);
@ -1764,7 +1763,7 @@ public class PS {
public void setupDatabase() {
try {
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!");
IMP.disable();
return;
@ -1786,7 +1785,7 @@ public class PS {
this.clusters_tmp = DBFunc.getClusters();
}
} 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) {
log("$4MONGO");
} else if (Settings.DB.USE_MYSQL) {
@ -2195,7 +2194,7 @@ public class PS {
// Misc
Settings.DEBUG = config.getBoolean("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");
if (!config.getBoolean("chat.fancy") || !checkVersion(IMP.getServerVersion(), 1, 8, 0)) {
@ -2216,7 +2215,7 @@ public class PS {
public void setupConfigs() {
final File folder = new File(IMP.getDirectory() + File.separator + "config");
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 {
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("API Location", "" + Settings.API_URL);
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

@ -14,6 +14,6 @@ public class Chat extends SubCommand {
@Override
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]");
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()) {
MainUtil.sendMessage(player, "&6Database does not exist: " + file);
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);
} else {
TaskManager.runTask(run);

View File

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

View File

@ -44,7 +44,7 @@ requiredType = RequiredType.NONE)
public class Inbox extends SubCommand {
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);
return;
}
@ -65,10 +65,10 @@ public class Inbox extends SubCommand {
}
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");
PlotComment c;
// This might work xD
for (int x = (page * 12); x < max; x++) {
c = comments[x];
for (int x = page * 12; x < max; x++) {
PlotComment c = comments[x];
String color;
if (player.getName().equals(c.senderName)) {
color = "&a";
@ -152,12 +152,11 @@ public class Inbox extends SubCommand {
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
@Override
public void run(List<PlotComment> value) {
final List<PlotComment> comments = value;
if (index > comments.size()) {
if (index > value.size()) {
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
return;
}
final PlotComment comment = comments.get(index - 1);
final PlotComment comment = value.get(index - 1);
inbox.removeComment(plot, comment);
plot.getSettings().removeComment(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>>() {
@Override
public void run(List<PlotComment> value) {
final List<PlotComment> comments = value;
displayComments(player, comments, page);
displayComments(player, value, page);
}
})) {
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.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.HashSet;
import java.util.UUID;
@ -165,7 +164,7 @@ public class Merge extends SubCommand {
return false;
}
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;
}
HashSet<UUID> uuids = adjacent.getOwners();

View File

@ -1,9 +1,5 @@
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.plot.PS;
import com.intellectualcrafters.plot.config.C;
@ -19,6 +15,10 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.TaskManager;
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")
public class Save extends SubCommand {
@ -73,7 +73,7 @@ public class Save extends SubCommand {
return;
}
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) {
schematics.add(file);
}

View File

@ -52,7 +52,7 @@ public class SetHome extends SetCommand {
Plot base = plot.getBasePlot(false);
Location bot = base.getBottomAbs();
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);
return MainUtil.sendMessage(plr, C.POSITION_SET);
}

View File

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

View File

@ -23,11 +23,21 @@ package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
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.Permissions;
import java.util.*;
import java.util.ArrayList;
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
@ -84,7 +94,7 @@ public class FlagManager {
}
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>() {
@Override
public void run(PlotArea value) {

View File

@ -23,17 +23,16 @@ package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.object.PlotArea;
public interface GeneratorWrapper<T> {
public IndependentPlotGenerator getPlotGenerator();
public T getPlatformGenerator();
IndependentPlotGenerator getPlotGenerator();
public void augment(PlotArea area);
T getPlatformGenerator();
public boolean isFull();
void augment(PlotArea area);
@Override
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.Dimension;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
@ -250,7 +249,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
}
}
if (schem1 == null || schem2 == null || ROAD_WIDTH == 0) {
PS.debug(C.PREFIX.s() + "&3 - schematic: &7false");
PS.debug(C.PREFIX + "&3 - schematic: &7false");
return;
}
ROAD_SCHEMATIC_ENABLED = true;

View File

@ -41,17 +41,17 @@ public abstract class SquarePlotManager extends GridPlotManager {
@Override
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 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 z = (dpw.ROAD_OFFSET_Z + (pz * (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;
return new Location(plotworld.worldname, x, Math.min(plotworld.MAX_BUILD_HEIGHT, 255), z);
}
@Override
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) {
x -= dpw.ROAD_OFFSET_X;
}
@ -73,20 +73,20 @@ public abstract class SquarePlotManager extends GridPlotManager {
}
final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
int idx;
int idz;
if (x < 0) {
idx = (x / size);
idx = x / size;
x = size + (x % size);
} else {
idx = (x / size) + 1;
x = (x % size);
x = x % size;
}
int idz;
if (z < 0) {
idz = (z / size);
idz = z / size;
z = size + (z % size);
} else {
idz = (z / size) + 1;
z = (z % size);
z = z % size;
}
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
public PlotId getPlotId(final PlotArea plotworld, int x, final int y, int z) {
try {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
final SquarePlotWorld dpw = (SquarePlotWorld) plotworld;
if (plotworld == null) {
return null;
}
@ -117,23 +117,23 @@ public abstract class SquarePlotManager extends GridPlotManager {
int dx;
int rx;
if (x < 0) {
dx = (x / size);
dx = x / size;
rx = size + (x % size);
} else {
dx = (x / size) + 1;
rx = (x % size);
rx = x % size;
}
int dz;
int rz;
if (z < 0) {
dz = (z / size);
dz = z / size;
rz = size + (z % size);
} else {
dz = (z / size) + 1;
rz = (z % size);
rz = z % size;
}
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);
// Not merged, and no need to check if it is
if (hash == 0) {
@ -182,11 +182,11 @@ public abstract class SquarePlotManager extends GridPlotManager {
*/
@Override
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 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 z = (dpw.ROAD_OFFSET_Z + (pz * (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);
return new Location(plotworld.worldname, x, plotworld.MIN_BUILD_HEIGHT, z);
}
}

View File

@ -1,8 +1,5 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
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.TaskManager;
import java.util.ArrayList;
import java.util.List;
public class InboxOwner extends CommentInbox {
@Override
@ -17,10 +17,10 @@ public class InboxOwner extends CommentInbox {
if (plot == null) {
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."
+ toString()
+ ".other")));
+ ".other"));
}
@Override
@ -28,9 +28,10 @@ public class InboxOwner extends CommentInbox {
if (plot == null) {
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()
+ ".other")));
+ ".other"));
}
@Override
@ -38,9 +39,10 @@ public class InboxOwner extends CommentInbox {
if (plot == null) {
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()
+ ".other")));
+ ".other"));
}
@Override
@ -59,7 +61,7 @@ public class InboxOwner extends CommentInbox {
public void run(List<PlotComment> value) {
whenDone.value = value;
if (value != null) {
for (final PlotComment comment : (ArrayList<PlotComment>) value) {
for (final PlotComment comment : value) {
plot.getSettings().addComment(comment);
}
} else {

View File

@ -1,8 +1,5 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
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.TaskManager;
import java.util.ArrayList;
import java.util.List;
public class InboxPublic extends CommentInbox {
@Override
@ -17,10 +17,10 @@ public class InboxPublic extends CommentInbox {
if (plot == null) {
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."
+ toString()
+ ".other")));
+ ".other"));
}
@Override
@ -28,9 +28,10 @@ public class InboxPublic extends CommentInbox {
if (plot == null) {
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()
+ ".other")));
+ ".other"));
}
@Override
@ -38,9 +39,10 @@ public class InboxPublic extends CommentInbox {
if (plot == null) {
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()
+ ".other")));
+ ".other"));
}
@Override
@ -59,7 +61,7 @@ public class InboxPublic extends CommentInbox {
public void run(List<PlotComment> value) {
whenDone.value = value;
if (value != null) {
for (final PlotComment comment : (ArrayList<PlotComment>) value) {
for (final PlotComment comment : value) {
plot.getSettings().addComment(comment);
}
}

View File

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

View File

@ -54,20 +54,22 @@ public class ExpireManager {
public void confirmExpiry(final PlotPlayer pp) {
if (Settings.AUTO_CLEAR_CONFIRMATION && plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) {
final int num = plotsToDelete.size();
Iterator<Plot> iter = plotsToDelete.iterator();
while (iter.hasNext()) {
final Plot current = iter.next();
for (final Plot current : plotsToDelete) {
if (isExpired(current)) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
pp.teleport(current.getCenter());
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 this (/plot delete)").color("$2").command("/plot delete").tooltip("/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")
.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("Delete this (/plot delete)").color("$2").command("/plot delete")
.tooltip("/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")
.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);
}
});
@ -75,7 +77,6 @@ public class ExpireManager {
}
}
plotsToDelete.clear();
return;
}
}
@ -247,7 +248,7 @@ public class ExpireManager {
return false;
}
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;
}
}
@ -266,7 +267,7 @@ public class ExpireManager {
return false;
}
} else if (value instanceof Long) {
if (((Long) value) > System.currentTimeMillis()) {
if ((Long) value > System.currentTimeMillis()) {
return false;
}
} else { // Invalid?

View File

@ -1,12 +1,12 @@
package com.intellectualcrafters.plot.util;
import java.util.HashMap;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandCaller;
import java.util.HashMap;
/**
* 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>
@ -34,7 +34,7 @@ public class Permissions {
if (!Settings.PERMISSION_CACHING) {
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) {
Boolean result = map.get(perm);
if (result != null) {
@ -63,7 +63,7 @@ public class Permissions {
final String[] nodes = perm.split("\\.");
final StringBuilder n = new StringBuilder();
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 (player.hasPermission(n + C.PERMISSION_STAR.s())) {
return true;
@ -106,7 +106,7 @@ public class Permissions {
final String[] nodes = stub.split("\\.");
final StringBuilder n = new StringBuilder();
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 (player.hasPermission(n + C.PERMISSION_STAR.s())) {
return Integer.MAX_VALUE;

View File

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

View File

@ -1,5 +1,5 @@
package com.intellectualcrafters.plot.util;
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.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -166,7 +167,8 @@ public abstract class SchematicHandler {
final int HEIGHT = demensions.getY();
// Validate dimensions
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("(" + WIDTH + "," + LENGTH + "," + HEIGHT + ") is bigger than (" + (region.maxX - region.minX) + "," + (region.maxZ - region.minZ) + ",256)");
TaskManager.runTask(whenDone);
@ -451,7 +453,7 @@ public abstract class SchematicHandler {
final List<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue();
for (final Tag stateTag : blockStates) {
try {
final CompoundTag ct = ((CompoundTag) stateTag);
final CompoundTag ct = (CompoundTag) stateTag;
final Map<String, Tag> state = ct.getValue();
final short x = IntTag.class.cast(state.get("x")).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();
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 j1 = (y - y1) * width * length;
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 j2 = j1 + (z - z1) * width;
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 j3 = j2 + (x - x1);
ids2[j3] = ids[i3];

View File

@ -179,7 +179,7 @@ public class SetQueue {
return false;
}
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

View File

@ -14,7 +14,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -86,7 +85,7 @@ public abstract class UUIDHandlerImplementation {
}
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) {

View File

@ -1,12 +1,11 @@
package com.intellectualcrafters.plot.util.helpmenu;
import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.commands.CommandCategory;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import java.util.ArrayList;
import java.util.List;
public class HelpPage {
@ -22,12 +21,12 @@ public class HelpPage {
if (helpObjects.size() < 1) {
MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)");
} else {
MainUtil.sendMessage(player, C.HELP_HEADER.s(), false);
MainUtil.sendMessage(player, C.HELP_HEADER, false);
MainUtil.sendMessage(player, _header, false);
for (final HelpObject object : helpObjects) {
MainUtil.sendMessage(player, object.toString(), false);
}
MainUtil.sendMessage(player, C.HELP_FOOTER.s(), false);
MainUtil.sendMessage(player, C.HELP_FOOTER, false);
}
}

View File

@ -85,10 +85,14 @@ public class CommandManager<T extends CommandCaller> {
}
public int handle(final T plr, String input) {
if ((initialCharacter != null) && !input.startsWith(initialCharacter + "")) {
if (initialCharacter != null && !input.startsWith(initialCharacter + "")) {
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(" ");
String[] args;
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.PlotPlayer;
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.Map;
import java.util.UUID;

View File

@ -17,6 +17,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
dependencies {
compile project(':Core')
compile 'org.spongepowered:spongeapi:4.0.3'
compile 'org.mcstats.sponge:metrics:R8-SNAPSHOT'
}
sourceCompatibility = 1.8
@ -31,6 +32,10 @@ repositories {
name = "Sponge"
url = "https://repo.spongepowered.org/maven"
}
maven {
name = "Sponge Metrics"
url = "http://repo.mcstats.org/content/repositories/releases/"
}
}
minecraft {
version = "1.8.9-11.15.1.1742"
@ -49,7 +54,9 @@ processResources {
shadowJar {
dependencies {
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"
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.SpongeHybridUtils;
import com.plotsquared.sponge.util.SpongeInventoryUtil;
import com.plotsquared.sponge.util.SpongeMetrics;
import com.plotsquared.sponge.util.SpongeSchematicHandler;
import com.plotsquared.sponge.util.SpongeSetupUtils;
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.SpongeOnlineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
import org.mcstats.Metrics;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Server;
@ -70,6 +70,7 @@ import org.spongepowered.api.world.gen.WorldGenerator;
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -303,10 +304,10 @@ public class SpongeMain implements IPlotMain {
@Override
public void startMetrics() {
try {
final SpongeMetrics metrics = new SpongeMetrics(game, (PluginContainer) this);
Metrics metrics = new Metrics(game, (PluginContainer) this);
metrics.start();
log(C.PREFIX.s() + "&6Metrics enabled.");
} catch (final Exception e) {
} catch (IOException e) {
log(C.PREFIX.s() + "&cFailed to load up metrics.");
}
}

View File

@ -19,7 +19,8 @@ public class SpongeAugmentedGenerator implements GenerationPopulator {
private static SpongeAugmentedGenerator generator;
private SpongeAugmentedGenerator() {};
private SpongeAugmentedGenerator() {
}
public static SpongeAugmentedGenerator get(World world) {
WorldGenerator wg = world.getWorldGenerator();

View File

@ -84,7 +84,7 @@ public class MainListener {
if (Settings.USE_PLOTME_ALIAS) {
SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
} else {
source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME.s()));
source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME));
}
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.getClass());
System.out.println(method + ": " + StringMan.getString(cause.all()));
System.out.println(method + ": " + (cause.root()));
System.out.println(method + ": " + cause.root());
}
public static void initBiomeCache() {
@ -291,7 +291,7 @@ public class SpongeUtil extends WorldUtil {
id = Short.parseShort(split[0]);
match = 0;
} else {
List<BlockType> types = ReflectionUtils.<BlockType>getStaticFields(BlockTypes.class);
List<BlockType> types = ReflectionUtils.getStaticFields(BlockTypes.class);
final StringComparison<BlockType>.ComparisonResult comparison =
new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
@Override