Cleanup of code

This commit is contained in:
MattBDev
2016-03-28 13:28:21 -04:00
parent feee63b3af
commit 8d4f042abc
19 changed files with 375 additions and 335 deletions

View File

@@ -53,6 +53,7 @@ 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;
@@ -1902,7 +1903,7 @@ public class PS {
case "3":
return PlotGameMode.SPECTATOR;
default:
return null;
return PlotGameMode.NOT_SET;
}
}
@@ -2246,23 +2247,23 @@ public class PS {
log("Failed to save storage.yml");
}
try {
commandsFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "commands.yml");
if (!commandsFile.exists()) {
if (!commandsFile.createNewFile()) {
this.commandsFile = new File(this.IMP.getDirectory() + File.separator + "config" + File.separator + "commands.yml");
if (!this.commandsFile.exists()) {
if (!this.commandsFile.createNewFile()) {
log("Could not the storage settings file, please create \"commands.yml\" manually.");
}
}
commands = YamlConfiguration.loadConfiguration(commandsFile);
this.commands = YamlConfiguration.loadConfiguration(this.commandsFile);
setupStorage();
} catch (IOException err_trans) {
log("Failed to save commands.yml");
}
try {
style.save(styleFile);
config.save(configFile);
storage.save(storageFile);
commands.save(commandsFile);
} catch (final IOException e) {
this.style.save(this.styleFile);
this.config.save(this.configFile);
this.storage.save(this.storageFile);
this.commands.save(this.commandsFile);
} catch (IOException e) {
log("Configuration file saving failed");
e.printStackTrace();
}

View File

@@ -1,64 +1,55 @@
package com.intellectualcrafters.plot.commands;
/**
* CommandCategory
*
* CommandCategory.
*/
public enum CommandCategory {
/**
* Claiming CommandConfig
*
* Claiming CommandConfig.
* Such as: /plot claim
*/
CLAIMING("Claiming"),
/**
* Teleportation CommandConfig
*
* Teleportation CommandConfig.
* Such as: /plot visit
*/
TELEPORT("Teleport"),
/**
* Protection
* Protection.
*/
SETTINGS("Protection"),
/**
* Chat
* Chat.
*/
CHAT("Chat"),
/**
* Web
* Web.
*/
SCHEMATIC("Web"),
/**
* Cosmetic
* Cosmetic.
*/
APPEARANCE("Cosmetic"),
/**
* Information CommandConfig
*
* Information CommandConfig.
* Such as: /plot info
*/
INFO("Info"),
/**
* Debug CommandConfig
*
* Debug CommandConfig.
* Such as: /plot debug
*/
DEBUG("Debug"),
/**
* Administration commands
* Administration commands.
*/
ADMINISTRATION("Admin");
/**
* The category name (Readable)
* The category name (Readable).
*/
private final String name;
/**
* Constructor
* Constructor.
*
* @param name readable name
*/

View File

@@ -45,7 +45,8 @@ public class Toggle extends Command {
aliases = {"spy"},
permission = "plots.admin.command.chat",
description = "Toggle admin chat spying")
public void chatspy(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
public void chatspy(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "chatspy")) {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
} else {
@@ -58,7 +59,8 @@ public class Toggle extends Command {
aliases = {"we", "wea"},
permission = "plots.worldedit.bypass",
description = "Toggle worldedit area restrictions")
public void worldedit(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
public void worldedit(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "worldedit")) {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
} else {
@@ -70,7 +72,8 @@ public class Toggle extends Command {
command = "chat",
permission = "plots.toggle.chat",
description = "Toggle plot chat")
public void chat(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
public void chat(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "chat")) {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
} else {
@@ -82,7 +85,8 @@ public class Toggle extends Command {
command = "titles",
permission = "plots.toggle.titles",
description = "Toggle plot title messages")
public void titles(Command command, final PlotPlayer player, String[] args, RunnableVal3<Command,Runnable,Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
public void titles(Command command, PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "titles")) {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, command.toString());
} else {

View File

@@ -85,11 +85,11 @@ public class HybridPlotManager extends ClassicPlotManager {
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
}
createSchemAbs(hpw, pos1, pos2, 0, true);
createSchemAbs(hpw, pos1, pos2, true);
return true;
}
private void createSchemAbs(HybridPlotWorld hpw, Location pos1, Location pos2, int height, boolean clear) {
private void createSchemAbs(HybridPlotWorld hpw, Location pos1, Location pos2, boolean clear) {
int size = hpw.SIZE;
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
short absX = (short) ((x - hpw.ROAD_OFFSET_X) % size);
@@ -103,13 +103,13 @@ public class HybridPlotManager extends ClassicPlotManager {
}
HashMap<Integer, PlotBlock> blocks = hpw.G_SCH.get(MathMan.pair(absX, absZ));
if (clear) {
for (short y = (short) height; y <= (height + hpw.SCHEMATIC_HEIGHT); y++) {
for (short y = (short) 0; y <= hpw.SCHEMATIC_HEIGHT; y++) {
SetQueue.IMP.setBlock(hpw.worldname, x, y, z, 0);
}
}
if (blocks != null) {
for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) {
SetQueue.IMP.setBlock(hpw.worldname, x, height + entry.getKey(), z, entry.getValue());
SetQueue.IMP.setBlock(hpw.worldname, x, entry.getKey(), z, entry.getValue());
}
}
}
@@ -130,7 +130,7 @@ public class HybridPlotManager extends ClassicPlotManager {
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
}
createSchemAbs(hpw, pos1, pos2, 0, true);
createSchemAbs(hpw, pos1, pos2, true);
return true;
}
@@ -144,11 +144,11 @@ public class HybridPlotManager extends ClassicPlotManager {
Location pos2 = getPlotBottomLocAbs(hpw, id2);
pos1.setY(0);
pos2.setY(256);
createSchemAbs(hpw, pos1, pos2, 0, true);
createSchemAbs(hpw, pos1, pos2, true);
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
}
createSchemAbs(hpw, pos1, pos2, 0, true);
createSchemAbs(hpw, pos1, pos2, true);
return true;
}
@@ -221,6 +221,6 @@ public class HybridPlotManager extends ClassicPlotManager {
if (!plotworld.PLOT_SCHEMATIC) {
return;
}
createSchemAbs(plotworld, l1, l2, 0, false);
createSchemAbs(plotworld, l1, l2, false);
}
}

View File

@@ -20,25 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.geom.PathIterator;
import java.io.File;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
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;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS;
@@ -60,6 +41,25 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.listener.PlotListener;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.geom.PathIterator;
import java.io.File;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
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;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* The plot class<br>
* [IMPORTANT]
@@ -1128,15 +1128,14 @@ public class Plot {
/**
* Set the home location
* @param loc
* @param location
*/
public void setHome(BlockLoc loc) {
public void setHome(BlockLoc location) {
Plot plot = this.getBasePlot(false);
BlockLoc pos = plot.getSettings().getPosition();
if (new BlockLoc(0, 0, 0).equals(loc)) {
if (new BlockLoc(0, 0, 0).equals(location)) {
return;
}
plot.getSettings().setPosition(loc);
plot.getSettings().setPosition(location);
DBFunc.setPosition(plot, plot.getSettings().getPosition().toString());
}
@@ -1273,7 +1272,7 @@ public class Plot {
}
/**
* Set the plot sign if plot signs are enabled
* Set the plot sign if plot signs are enabled.
*/
public void setSign() {
if (this.owner == null) {
@@ -1338,6 +1337,8 @@ public class Plot {
* - The plot will not be created if the owner is null<br>
* - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot
* creation.
* @param uuid
* @param notify
* @return true if plot was created successfully
*/
public boolean create(final UUID uuid, final boolean notify) {
@@ -1377,7 +1378,7 @@ public class Plot {
}
/**
* Set components such as border, wall, floor
* Set components such as border, wall, floor.
* (components are generator specific)
*/
public boolean setComponent(String component, String blocks) {
@@ -1386,7 +1387,7 @@ public class Plot {
}
/**
* Get the biome (String)
* Get the biome.
*/
public String getBiome() {
Location loc = this.getBottomAbs();
@@ -1394,7 +1395,7 @@ public class Plot {
}
/**
* Return the top location for the plot
* Return the top location for the plot.
* @return
*/
public Location getTopAbs() {
@@ -1402,7 +1403,7 @@ public class Plot {
}
/**
* Return the bottom location for the plot
* Return the bottom location for the plot.
* @return
*/
public Location getBottomAbs() {
@@ -1410,43 +1411,43 @@ public class Plot {
}
/**
* Swap the settings for two plots
* @param p2
* Swap the settings for two plots.
* @param plot
* @param whenDone
* @return
*/
public boolean swapData(Plot p2, Runnable whenDone) {
public boolean swapData(Plot plot, Runnable whenDone) {
if (this.owner == null) {
if (p2 != null && p2.hasOwner()) {
p2.moveData(this, whenDone);
if (plot != null && plot.hasOwner()) {
plot.moveData(this, whenDone);
return true;
}
return false;
}
if (p2 == null || p2.owner == null) {
this.moveData(p2, whenDone);
if (plot == null || plot.owner == null) {
this.moveData(plot, whenDone);
return true;
}
// Swap cached
PlotId temp = new PlotId(this.getId().x, this.getId().y);
this.getId().x = p2.getId().x;
this.getId().y = p2.getId().y;
p2.getId().x = temp.x;
p2.getId().y = temp.y;
this.getId().x = plot.getId().x;
this.getId().y = plot.getId().y;
plot.getId().x = temp.x;
plot.getId().y = temp.y;
this.area.removePlot(this.getId());
p2.area.removePlot(p2.getId());
plot.area.removePlot(plot.getId());
this.getId().recalculateHash();
p2.getId().recalculateHash();
plot.getId().recalculateHash();
this.area.addPlotAbs(this);
p2.area.addPlotAbs(p2);
plot.area.addPlotAbs(plot);
// Swap database
DBFunc.dbManager.swapPlots(p2, this);
DBFunc.dbManager.swapPlots(plot, this);
TaskManager.runTaskLater(whenDone, 1);
return true;
}
/**
* Move the settings for a plot
* Move the settings for a plot.
* @param pos2
* @param whenDone
* @return
@@ -1621,7 +1622,7 @@ public class Plot {
}
/**
* Get plot display name
* Get plot display name.
*
* @return alias if set, else id
*/
@@ -1718,7 +1719,7 @@ public class Plot {
}
/**
* Export the plot as a schematic to the configured output directory
* Export the plot as a schematic to the configured output directory.
* @return
*/
public void export(final RunnableVal<Boolean> whenDone) {
@@ -1764,7 +1765,7 @@ public class Plot {
}
/**
* Upload the plot as a schematic to the configured web interface<br>
* Upload the plot as a schematic to the configured web interface.
* @param whenDone value will be null if uploading fails
*/
public void upload(final RunnableVal<URL> whenDone) {
@@ -1838,7 +1839,7 @@ public class Plot {
}
/**
* Set a flag for this plot
* Set a flag for this plot.
* @param flags
*/
public void setFlags(Set<Flag> flags) {
@@ -1846,9 +1847,9 @@ public class Plot {
}
/**
* Get the plot Alias<br>
* Get the plot alias.
* - Returns an empty string if no alias is set
* @return
* @return The plot alias
*/
public String getAlias() {
if (this.settings == null) {
@@ -1858,8 +1859,8 @@ public class Plot {
}
/**
* Set the plot alias
* @param alias
* Set the plot alias.
* @param alias The alias
*/
public void setAlias(String alias) {
for (Plot current : this.getConnectedPlots()) {
@@ -1912,7 +1913,7 @@ public class Plot {
}
/**
* Get the merged array
* Get the merged array.
* @return boolean [ north, east, south, west ]
*/
public boolean[] getMerged() {
@@ -2512,8 +2513,8 @@ public class Plot {
}
/**
* Get all the corners of the plot (supports non-rectangular shapes)<br>
* @return
* Get all the corners of the plot (supports non-rectangular shapes).
* @return A list of the plot corners
*/
public List<Location> getAllCorners() {
Area area = new Area();
@@ -2536,7 +2537,7 @@ public class Plot {
/**
* Teleport a player to a plot and send them the teleport message.
* @param player
* @param player The player
* @return If the teleportation is allowed.
*/
public boolean teleportPlayer(final PlotPlayer player) {
@@ -2605,7 +2606,7 @@ public class Plot {
}
/**
* Expand the world border to include the provided plot (if applicable)
* Expand the world border to include the provided plot (if applicable).
*/
public void updateWorldBorder() {
if (this.owner == null) {
@@ -2672,7 +2673,7 @@ public class Plot {
greaterPlot.setMerged(3, true);
lesserPlot.mergeData(greaterPlot);
if (removeRoads) {
final Plot other = lesserPlot.getRelative(0);
Plot other = lesserPlot.getRelative(0);
if (other.getMerged(2) && other.getMerged(1)) {
greaterPlot.mergePlot(other, removeRoads);
other.removeRoadSouthEast();

View File

@@ -274,7 +274,7 @@ public abstract class PlotArea {
this.GAMEMODE = PlotGameMode.SPECTATOR;
break;
default:
PS.debug("&cInvalid gamemode set for: " + this.worldname);
this.GAMEMODE = PlotGameMode.NOT_SET;
break;
}

View File

@@ -1,5 +1,33 @@
package com.intellectualcrafters.plot.util;
public enum PlotGameMode {
ADVENTURE, SURVIVAL, CREATIVE, SPECTATOR
NOT_SET(-1, ""),
SURVIVAL(0, "survival"),
CREATIVE(1, "creative"),
ADVENTURE(2, "adventure"),
SPECTATOR(3, "spectator");
private final int id;
private final String name;
PlotGameMode(int id, String name) {
this.id = id;
this.name = name;
}
/**
* The magic-value id of the GameMode.
* @return the GameMode id
*/
public int getId() {
return this.id;
}
/**
* Get the name of this GameMode
* @return the GameMode name
*/
public String getName() {
return this.name;
}
}

View File

@@ -22,7 +22,7 @@ public class UUIDHandler {
}
/**
* Get the map containing all names/uuids
* Get the map containing all names/uuids.
*
* @return map with names + uuids
*

View File

@@ -189,12 +189,6 @@ public abstract class UUIDHandlerImplementation {
if (uuid == null) {
return null;
}
// // check online
// final PlotPlayer player = getPlayer(uuid);
// if (player != null) {
// return player.getName();
// }
// check cache
StringWrapper name = this.uuidMap.inverse().get(uuid);
if (name != null) {
return name.value;
@@ -203,7 +197,7 @@ public abstract class UUIDHandlerImplementation {
}
public UUID getUUID(String name, RunnableVal<UUID> ifFetch) {
if (name == null || name.isEmpty()) {
if (name.isEmpty()) {
return null;
}
// check online