Code cleanup

maybe a bug fix or two
This commit is contained in:
MattBDev 2016-03-28 17:31:40 -04:00
parent 8d4f042abc
commit 76e2b1f416
18 changed files with 99 additions and 97 deletions

View File

@ -33,7 +33,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.commands.DebugUUID;
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector; import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter; import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017; import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
@ -73,12 +72,6 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -93,6 +86,13 @@ 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.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
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;
@ -171,7 +171,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
plotCommand.setExecutor(bcmd); plotCommand.setExecutor(bcmd);
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot")); plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
plotCommand.setTabCompleter(bcmd); plotCommand.setTabCompleter(bcmd);
new DebugUUID();
} }
@Override @Override

View File

@ -53,7 +53,7 @@ public class Metrics {
/** /**
* The current revision number * The current revision number
*/ */
private final static int REVISION = 7; private static final int REVISION = 7;
/** /**
* The base url of the metrics domain * The base url of the metrics domain
*/ */

View File

@ -41,7 +41,7 @@ import java.util.UUID;
usage = "/plot add <player>", usage = "/plot add <player>",
category = CommandCategory.SETTINGS, category = CommandCategory.SETTINGS,
permission = "plots.add", permission = "plots.add",
requiredType = RequiredType.NONE) requiredType = RequiredType.PLAYER)
public class Add extends SubCommand { public class Add extends SubCommand {
public Add() { public Add() {

View File

@ -39,7 +39,7 @@ import java.util.Set;
description = "Create a new PlotArea", description = "Create a new PlotArea",
aliases = "world", aliases = "world",
usage = "/plot area <create|info|list|tp|regen>", usage = "/plot area <create|info|list|tp|regen>",
confirmation=true) confirmation = true)
public class Area extends SubCommand { public class Area extends SubCommand {
@Override @Override

View File

@ -41,7 +41,7 @@ import java.util.UUID;
description = "Deny a user from a plot", description = "Deny a user from a plot",
usage = "/plot deny <player>", usage = "/plot deny <player>",
category = CommandCategory.SETTINGS, category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE) requiredType = RequiredType.PLAYER)
public class Deny extends SubCommand { public class Deny extends SubCommand {
public Deny() { public Deny() {

View File

@ -28,6 +28,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "kick", @CommandDeclaration(command = "kick",
@ -35,9 +36,13 @@ import com.plotsquared.general.commands.CommandDeclaration;
description = "Kick a player from your plot", description = "Kick a player from your plot",
permission = "plots.kick", permission = "plots.kick",
category = CommandCategory.TELEPORT, category = CommandCategory.TELEPORT,
requiredType = RequiredType.NONE) requiredType = RequiredType.PLAYER)
public class Kick extends SubCommand { public class Kick extends SubCommand {
public Kick() {
super(Argument.PlayerName);
}
@Override @Override
public boolean onCommand(PlotPlayer plr, String[] args) { public boolean onCommand(PlotPlayer plr, String[] args) {
Location loc = plr.getLocation(); Location loc = plr.getLocation();

View File

@ -46,8 +46,8 @@ import java.util.UUID;
confirmation=true) confirmation=true)
public class Merge extends SubCommand { public class Merge extends SubCommand {
public final static String[] values = new String[]{"north", "east", "south", "west", "auto"}; public static final String[] values = new String[]{"north", "east", "south", "west", "auto"};
public final static String[] aliases = new String[]{"n", "e", "s", "w", "all"}; public static final 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;

View File

@ -40,7 +40,7 @@ import java.util.UUID;
description = "Remove a player from a plot", description = "Remove a player from a plot",
usage = "/plot remove <player>", usage = "/plot remove <player>",
category = CommandCategory.SETTINGS, category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE, requiredType = RequiredType.PLAYER,
permission = "plots.remove") permission = "plots.remove")
public class Remove extends SubCommand { public class Remove extends SubCommand {

View File

@ -52,8 +52,8 @@ import java.util.HashSet;
requiredType = RequiredType.NONE) requiredType = RequiredType.NONE)
public class Set extends SubCommand { public class Set extends SubCommand {
public final static String[] values = new String[]{"biome", "alias", "home", "flag"}; public static final String[] values = new String[]{"biome", "alias", "home", "flag"};
public final static String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"}; public static final String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"};
private final SetCommand component; private final SetCommand component;

View File

@ -37,7 +37,7 @@ import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "trust", command = "trust",
aliases = {"t"}, aliases = {"t"},
requiredType = RequiredType.NONE, requiredType = RequiredType.PLAYER,
usage = "/plot trust <player>", usage = "/plot trust <player>",
description = "Allow a player to build in a plot", description = "Allow a player to build in a plot",
category = CommandCategory.SETTINGS) category = CommandCategory.SETTINGS)

View File

@ -46,9 +46,9 @@ import java.util.Set;
*/ */
public class FlagManager { public class FlagManager {
private final static HashSet<String> reserved = new HashSet<>(); private static final HashSet<String> reserved = new HashSet<>();
private final static HashSet<AbstractFlag> flags = new HashSet<>(); private static final 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

View File

@ -25,7 +25,8 @@ public class BlockLoc {
public static BlockLoc fromString(String string) { public static BlockLoc fromString(String string) {
String[] parts = string.split(","); String[] parts = string.split(",");
float yaw, pitch; float yaw;
float pitch;
if (parts.length == 3) { if (parts.length == 3) {
yaw = 0f; yaw = 0f;
pitch = 0f; pitch = 0f;

View File

@ -20,23 +20,20 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
/**
*/
public class PlotBlock { public class PlotBlock {
public final static PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0); public static final PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0);
public final short id; public final short id;
public final byte data; public final byte data;
public PlotBlock(final short id, final byte data) { public PlotBlock(short id, byte data) {
this.id = id; this.id = id;
this.data = data; this.data = data;
} }
@Override @Override
public boolean equals(final Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@ -46,20 +43,20 @@ public class PlotBlock {
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
return false; return false;
} }
final PlotBlock other = (PlotBlock) obj; PlotBlock other = (PlotBlock) obj;
return ((id == other.id) && ((data == other.data) || (data == -1) || (other.data == -1))); return (this.id == other.id) && ((this.data == other.data) || (this.data == -1) || (other.data == -1));
} }
@Override @Override
public int hashCode() { public int hashCode() {
return id; return this.id;
} }
@Override @Override
public String toString() { public String toString() {
if (data == -1) { if (this.data == -1) {
return id + ""; return this.id + "";
} }
return id + ":" + data; return this.id + ":" + this.data;
} }
} }

View File

@ -62,19 +62,19 @@ public class BO3Handler {
} }
/** /**
* Save a plot as a BO3 file<br> * Save a plot as a BO3 file.
* - Use null for the player object if no player is applicable * - Use null for the player object if no player is applicable
* @param plr * @param player
* @param plot * @param plot
* @return * @return
*/ */
public static boolean saveBO3(PlotPlayer plr, Plot plot, RunnableVal<BO3> saveTask) { public static boolean saveBO3(PlotPlayer player, Plot plot, RunnableVal<BO3> saveTask) {
if (saveTask == null) { if (saveTask == null) {
throw new IllegalArgumentException("Save task cannot be null!"); throw new IllegalArgumentException("Save task cannot be null!");
} }
PlotArea plotworld = plot.getArea(); PlotArea plotworld = plot.getArea();
if (!(plotworld instanceof ClassicPlotWorld) || plotworld.TYPE != 0) { if (!(plotworld instanceof ClassicPlotWorld) || plotworld.TYPE != 0) {
MainUtil.sendMessage(plr, "BO3 exporting only supports type 0 classic generation."); MainUtil.sendMessage(player, "BO3 exporting only supports type 0 classic generation.");
return false; return false;
} }
String alias = plot.toString(); String alias = plot.toString();
@ -150,7 +150,7 @@ public class BO3Handler {
} }
if (!content) { if (!content) {
MainUtil.sendMessage(plr, "No content found!"); MainUtil.sendMessage(player, "No content found!");
return false; return false;
} }
@ -177,7 +177,7 @@ public class BO3Handler {
} }
} }
if (parentLoc == null) { if (parentLoc == null) {
MainUtil.sendMessage(plr, MainUtil.sendMessage(player,
"Exporting BO3 cancelled due to detached chunk: " + chunk + " - Make sure you only have one object per plot"); "Exporting BO3 cancelled due to detached chunk: " + chunk + " - Make sure you only have one object per plot");
return false; return false;
} }
@ -189,7 +189,7 @@ public class BO3Handler {
saveTask.run(entry.getValue()); saveTask.run(entry.getValue());
} }
MainUtil.sendMessage(plr, "BO3 exporting was successful!"); MainUtil.sendMessage(player, "BO3 exporting was successful!");
return true; return true;
} }

View File

@ -473,7 +473,11 @@ public abstract class Command {
String arg = args[0].toLowerCase(); String arg = args[0].toLowerCase();
if (space) { if (space) {
Command cmd = getCommand(arg); Command cmd = getCommand(arg);
return (cmd != null && cmd.canExecute(player, false)) ? cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space) : null; if (cmd != null && cmd.canExecute(player, false)) {
return cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space);
} else {
return null;
}
} else { } else {
Set<Command> commands = new HashSet<Command>(); Set<Command> commands = new HashSet<Command>();
for (Map.Entry<String, Command> entry : this.staticCommands.entrySet()) { for (Map.Entry<String, Command> entry : this.staticCommands.entrySet()) {
@ -485,7 +489,11 @@ public abstract class Command {
} }
default: default:
Command cmd = getCommand(args[0]); Command cmd = getCommand(args[0]);
return cmd != null ? cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space) : null; if (cmd != null) {
return cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space);
} else {
return null;
}
} }
} }

View File

@ -130,17 +130,13 @@ public class SpongePlayer extends PlotPlayer {
GameMode gamemode = this.player.getGameModeData().type().get(); GameMode gamemode = this.player.getGameModeData().type().get();
if (gamemode == GameModes.ADVENTURE) { if (gamemode == GameModes.ADVENTURE) {
return PlotGameMode.ADVENTURE; return PlotGameMode.ADVENTURE;
} } else if (gamemode == GameModes.CREATIVE) {
if (gamemode == GameModes.CREATIVE) {
return PlotGameMode.CREATIVE; return PlotGameMode.CREATIVE;
} } else if (gamemode == GameModes.SPECTATOR) {
if (gamemode == GameModes.SPECTATOR) {
return PlotGameMode.SPECTATOR; return PlotGameMode.SPECTATOR;
} } else if (gamemode == GameModes.SURVIVAL) {
if (gamemode == GameModes.SURVIVAL) {
return PlotGameMode.SURVIVAL; return PlotGameMode.SURVIVAL;
} } else {
if (gamemode == GameModes.NOT_SET) {
return PlotGameMode.NOT_SET; return PlotGameMode.NOT_SET;
} }
} }

View File

@ -5,10 +5,7 @@ import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ReflectionUtils;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer; import net.minecraft.world.gen.ChunkProviderServer;
import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.Entity;
@ -18,8 +15,6 @@ import org.spongepowered.api.entity.living.monster.Monster;
import org.spongepowered.api.world.Chunk; import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -27,20 +22,20 @@ import java.util.function.Predicate;
public class SpongeChunkManager extends ChunkManager { public class SpongeChunkManager extends ChunkManager {
@Override @Override
public int[] countEntities(final Plot plot) { public int[] countEntities(Plot plot) {
final Location pos1 = plot.getBottomAbs(); Location pos1 = plot.getBottomAbs();
final Location pos2 = plot.getTopAbs(); Location pos2 = plot.getTopAbs();
final World world = SpongeUtil.getWorld(pos1.getWorld()); World world = SpongeUtil.getWorld(pos1.getWorld());
final int bx = pos1.getX(); int bx = pos1.getX();
final int bz = pos1.getZ(); int bz = pos1.getZ();
final int tx = pos2.getX(); int tx = pos2.getX();
final int tz = pos2.getZ(); int tz = pos2.getZ();
final int[] count = new int[6]; int[] count = new int[6];
world.getEntities(entity -> { world.getEntities(entity -> {
final org.spongepowered.api.world.Location loc = entity.getLocation(); org.spongepowered.api.world.Location loc = entity.getLocation();
final int x = loc.getBlockX(); int x = loc.getBlockX();
if ((x >= bx) && (x <= tx)) { if ((x >= bx) && (x <= tx)) {
final int z = loc.getBlockZ(); int z = loc.getBlockZ();
if ((z >= bz) && (z <= tz)) { if ((z >= bz) && (z <= tz)) {
count[0]++; count[0]++;
if (entity instanceof Living) { if (entity instanceof Living) {
@ -62,22 +57,22 @@ public class SpongeChunkManager extends ChunkManager {
} }
@Override @Override
public boolean loadChunk(final String world, final ChunkLoc loc, final boolean force) { public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
final World worldObj = SpongeUtil.getWorld(world); World worldObj = SpongeUtil.getWorld(world);
return worldObj.loadChunk(loc.x << 4, 0, loc.z << 4, force).isPresent(); return worldObj.loadChunk(loc.x << 4, 0, loc.z << 4, force).isPresent();
} }
@Override @Override
public Set<ChunkLoc> getChunkChunks(final String world) { public Set<ChunkLoc> getChunkChunks(String world) {
// TODO save world; // TODO save world;
return super.getChunkChunks(world); return super.getChunkChunks(world);
} }
@Override @Override
public void regenerateChunk(final String world, final ChunkLoc loc) { public void regenerateChunk(String world, ChunkLoc loc) {
final World spongeWorld = SpongeUtil.getWorld(world); World spongeWorld = SpongeUtil.getWorld(world);
final net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeWorld; net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeWorld;
final Optional<Chunk> chunkOpt = spongeWorld.getChunk(loc.x, 0, loc.z); Optional<Chunk> chunkOpt = spongeWorld.getChunk(loc.x, 0, loc.z);
if (chunkOpt.isPresent()) { if (chunkOpt.isPresent()) {
try { try {
Chunk spongeChunk = chunkOpt.get(); Chunk spongeChunk = chunkOpt.get();
@ -86,7 +81,7 @@ public class SpongeChunkManager extends ChunkManager {
PS.debug("Not valid world generator for: " + world); PS.debug("Not valid world generator for: " + world);
return; return;
} }
ChunkProviderServer chunkServer = (ChunkProviderServer) provider; /* ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z); long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z);
@ -103,6 +98,7 @@ public class SpongeChunkManager extends ChunkManager {
} }
Set<Long> set = (Set<Long>) fieldDroppedChunksSet.get(chunkServer); Set<Long> set = (Set<Long>) fieldDroppedChunksSet.get(chunkServer);
set.remove(pos); set.remove(pos);
ReflectionUtils.findField(chunkServer.getClass(),)
chunkServer.id2ChunkMap.remove(pos); chunkServer.id2ChunkMap.remove(pos);
mcChunk = chunkProvider.provideChunk(loc.x, loc.z); mcChunk = chunkProvider.provideChunk(loc.x, loc.z);
chunkServer.id2ChunkMap.add(pos, mcChunk); chunkServer.id2ChunkMap.add(pos, mcChunk);
@ -114,7 +110,7 @@ public class SpongeChunkManager extends ChunkManager {
} }
else { else {
PS.debug("CHUNK IS NULL!?"); PS.debug("CHUNK IS NULL!?");
} }*/
} catch (Throwable e){ } catch (Throwable e){
e.printStackTrace(); e.printStackTrace();
} }
@ -122,27 +118,27 @@ public class SpongeChunkManager extends ChunkManager {
} }
@Override @Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) { public boolean copyRegion(Location pos1, Location pos2, Location newPos, Runnable whenDone) {
// TODO copy a region // TODO copy a region
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return false; return false;
} }
@Override @Override
public void clearAllEntities(final Location pos1, final Location pos2) { public void clearAllEntities(Location pos1, Location pos2) {
final String worldname = pos1.getWorld(); String worldname = pos1.getWorld();
final World world = SpongeUtil.getWorld(worldname); World world = SpongeUtil.getWorld(worldname);
final int bx = pos1.getX(); int bx = pos1.getX();
final int bz = pos1.getZ(); int bz = pos1.getZ();
final int tx = pos2.getX(); int tx = pos2.getX();
final int tz = pos2.getZ(); int tz = pos2.getZ();
world.getEntities(new Predicate<Entity>() { world.getEntities(new Predicate<Entity>() {
@Override @Override
public boolean test(final Entity entity) { public boolean test(Entity entity) {
final org.spongepowered.api.world.Location loc = entity.getLocation(); org.spongepowered.api.world.Location loc = entity.getLocation();
final int x = loc.getBlockX(); int x = loc.getBlockX();
if ((x >= bx) && (x <= tx)) { if ((x >= bx) && (x <= tx)) {
final int z = loc.getBlockZ(); int z = loc.getBlockZ();
if ((z >= bz) && (z <= tz)) { if ((z >= bz) && (z <= tz)) {
entity.remove(); entity.remove();
} }
@ -160,8 +156,8 @@ public class SpongeChunkManager extends ChunkManager {
@Override @Override
public void unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe) { public void unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe) {
final World worldObj = SpongeUtil.getWorld(world); World worldObj = SpongeUtil.getWorld(world);
final Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4); Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
if (chunk.isPresent()) { if (chunk.isPresent()) {
worldObj.unloadChunk(chunk.get()); worldObj.unloadChunk(chunk.get());
} }

View File

@ -10,7 +10,7 @@ buildscript {
} }
group = 'com.intellectualcrafters' group = 'com.intellectualcrafters'
version = '3.3.3-SNAPSHOT' version = '3.3.3'
description = """PlotSquared""" description = """PlotSquared"""
subprojects { subprojects {