Code cleanup and Optimizations

This commit is contained in:
MattBDev
2016-03-29 00:56:44 -04:00
parent 49d18b9229
commit 32ba55baf5
34 changed files with 456 additions and 540 deletions

View File

@ -39,19 +39,20 @@ import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.util.BukkitUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
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;
import java.util.Set;
import java.util.UUID;
/**
* PlotSquared API<br>
* PlotSquared API.
* <br>
* @version API 3.3.1
* <br>
@ -95,7 +96,7 @@ public class PlotAPI {
}
/**
* Get all plots
* Get all plots.
*
* @return all plots
*
@ -106,7 +107,7 @@ public class PlotAPI {
}
/**
* Return all plots for a player
* Return all plots for a player.
*
* @param player Player, whose plots to search for
*
@ -117,7 +118,7 @@ public class PlotAPI {
}
/**
* Add a plot world
* Add a plot world.
*
* @param plotArea Plot World Object
* @see PS#addPlotArea(PlotArea)
@ -491,7 +492,7 @@ public class PlotAPI {
*/
@Deprecated
public boolean hasPlot(World world, Player player) {
return getPlots(world, player, true) != null && getPlots(world, player, true).length > 0;
return getPlots(world, player, true).length > 0;
}
/**
@ -510,10 +511,8 @@ public class PlotAPI {
if (plot.hasOwner() && plot.isOwner(uuid)) {
pPlots.add(plot);
}
} else {
if (plot.isAdded(uuid)) {
pPlots.add(plot);
}
} else if (plot.isAdded(uuid)) {
pPlots.add(plot);
}
}
return pPlots.toArray(new Plot[pPlots.size()]);

View File

@ -14,10 +14,10 @@ import java.util.Map;
*/
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
private final String _value;
private final String value;
public JsonString(CharSequence value) {
this._value = value == null ? null : value.toString();
this.value = value == null ? null : value.toString();
}
public static JsonString deserialize(Map<String, Object> map) {
@ -30,18 +30,18 @@ final class JsonString implements JsonRepresentedObject, ConfigurationSerializab
}
public String getValue() {
return this._value;
return this.value;
}
@Override
public Map<String, Object> serialize() {
HashMap<String, Object> theSingleValue = new HashMap<>();
theSingleValue.put("stringValue", this._value);
theSingleValue.put("stringValue", this.value);
return theSingleValue;
}
@Override
public String toString() {
return this._value;
return this.value;
}
}

View File

@ -835,14 +835,14 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onChange(BlockFromToEvent e) {
Block from = e.getBlock();
Block to = e.getToBlock();
Location tloc = BukkitUtil.getLocation(to.getLocation());
PlotArea area = tloc.getPlotArea();
Location tLocation = BukkitUtil.getLocation(to.getLocation());
PlotArea area = tLocation.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getOwnedPlot(tloc);
Location floc = BukkitUtil.getLocation(from.getLocation());
if (!area.contains(floc.getX(), floc.getZ()) || !Objects.equals(plot, area.getOwnedPlot(floc)) || (plot != null && FlagManager
Plot plot = area.getOwnedPlot(tLocation);
Location fLocation = BukkitUtil.getLocation(from.getLocation());
if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation)) || (plot != null && FlagManager
.isPlotFlagTrue(plot, "disable-physics"))) {
e.setCancelled(true);
}

View File

@ -40,10 +40,9 @@ public class DefaultTitleManager {
private boolean ticks = false;
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title
* @param title Title
* @throws ClassNotFoundException
*/
public DefaultTitleManager(String title) throws ClassNotFoundException {
@ -52,12 +51,10 @@ public class DefaultTitleManager {
}
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param title Title text
* @param subtitle Subtitle text
* @throws ClassNotFoundException
*/
public DefaultTitleManager(String title, String subtitle) throws ClassNotFoundException {
@ -118,8 +115,7 @@ public class DefaultTitleManager {
}
/**
* Load spigot and NMS classes
* @throws ClassNotFoundException
* Load spigot and NMS classes.
*/
private void loadClasses() {
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
@ -129,7 +125,7 @@ public class DefaultTitleManager {
}
/**
* Get title text
* Get title text.
*
* @return Title text
*/
@ -138,17 +134,16 @@ public class DefaultTitleManager {
}
/**
* Set title text
* Set title text.
*
* @param title
* Title
* @param title Title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Get subtitle text
* Get subtitle text.
*
* @return Subtitle text
*/

View File

@ -6,7 +6,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@ -53,12 +52,10 @@ public class DefaultTitleManager_183 {
}
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param title Title text
* @param subtitle Subtitle text
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(String title, String subtitle) throws ClassNotFoundException {
@ -68,10 +65,9 @@ public class DefaultTitleManager_183 {
}
/**
* Copy 1.8 title
* Copy 1.8 title.
*
* @param title
* Title
* @param title Title
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(DefaultTitleManager_183 title) throws ClassNotFoundException {
@ -88,18 +84,13 @@ public class DefaultTitleManager_183 {
}
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param fadeInTime
* Fade in time
* @param stayTime
* Stay on screen time
* @param fadeOutTime
* Fade out time
* @param title Title text
* @param subtitle Subtitle text
* @param fadeInTime Fade in time
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) throws ClassNotFoundException {
@ -124,8 +115,7 @@ public class DefaultTitleManager_183 {
}
/**
* Load spigot and NMS classes
* @throws ClassNotFoundException
* Load spigot and NMS classes.
*/
private void loadClasses() {
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
@ -136,7 +126,7 @@ public class DefaultTitleManager_183 {
}
/**
* Get title text
* Get title text.
*
* @return Title text
*/
@ -145,17 +135,16 @@ public class DefaultTitleManager_183 {
}
/**
* Set title text
* Set title text.
*
* @param title
* Title
* @param title Title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Get subtitle text
* Get subtitle text.
*
* @return Subtitle text
*/
@ -164,37 +153,34 @@ public class DefaultTitleManager_183 {
}
/**
* Set subtitle text
* Set subtitle text.
*
* @param subtitle
* Subtitle text
* @param subtitle Subtitle text
*/
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
/**
* Set the title color
* Set the title color.
*
* @param color
* Chat color
* @param color Chat color
*/
public void setTitleColor(ChatColor color) {
this.titleColor = color;
}
/**
* Set the subtitle color
* Set the subtitle color.
*
* @param color
* Chat color
* @param color Chat color
*/
public void setSubtitleColor(ChatColor color) {
this.subtitleColor = color;
}
/**
* Set title fade in time
* Set title fade in time.
*
* @param time
* Time
@ -204,47 +190,42 @@ public class DefaultTitleManager_183 {
}
/**
* Set title fade out time
* Set title fade out time.
*
* @param time
* Time
* @param time Time
*/
public void setFadeOutTime(int time) {
this.fadeOutTime = time;
}
/**
* Set title stay time
* Set title stay time.
*
* @param time
* Time
* @param time Time
*/
public void setStayTime(int time) {
this.stayTime = time;
}
/**
* Set timings to ticks
* Set timings to ticks.
*/
public void setTimingsToTicks() {
this.ticks = true;
}
/**
* Set timings to seconds
* Set timings to seconds.
*/
public void setTimingsToSeconds() {
this.ticks = false;
}
/**
* Send the title to a player
* Send the title to a player.
*
* @param player
* Player
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @param player Player
* @throws Exception
*/
public void send(Player player) throws Exception {
if (this.packetTitle != null) {
@ -258,11 +239,7 @@ public class DefaultTitleManager_183 {
Object packet = this.packetTitle
.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE)
.newInstance(actions[2], null,
this.fadeInTime * (
this.ticks ? 1 : 20),
this.fadeInTime * (this.ticks ? 1 : 20),
this.stayTime * (this.ticks ? 1 : 20), this.fadeOutTime * (this.ticks ? 1 : 20));
// Send if set
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
@ -285,7 +262,7 @@ public class DefaultTitleManager_183 {
}
/**
* Broadcast the title to all players
* Broadcast the title to all players.
* @throws Exception
*/
public void broadcast() throws Exception {
@ -295,12 +272,10 @@ public class DefaultTitleManager_183 {
}
/**
* Clear the title
* Clear the title.
*
* @param player
* Player
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @param player Player
* @throws Exception
*/
public void clearTitle(Player player) throws Exception {
// Send timings first
@ -313,16 +288,10 @@ public class DefaultTitleManager_183 {
}
/**
* Reset the title settings
* Reset the title settings.
*
* @param player
* Player
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
* @param player Player
* @throws Exception
*/
public void resetTitle(Player player) throws Exception {
// Send timings first

View File

@ -114,7 +114,6 @@ public class HackTitleManager {
/**
* Load spigot and NMS classes.
* @throws ClassNotFoundException Spigot Error.
*/
private void loadClasses() {
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");

View File

@ -51,39 +51,39 @@ import java.util.zip.GZIPOutputStream;
public class Metrics {
/**
* The current revision number
* The current revision number.
*/
private static final int REVISION = 7;
/**
* The base url of the metrics domain
* 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
* The url used to report a server's status.
*/
private static final String REPORT_URL = "/plugin/%s";
/**
* Interval of time to ping (in minutes)
* Interval of time to ping (in minutes).
*/
private static final int PING_INTERVAL = 15;
/**
* The plugin this metrics submits for
* The plugin this metrics submits for.
*/
private final Plugin plugin;
/**
* All of the custom graphs to submit to metrics
* All of the custom graphs to submit to metrics.
*/
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
/**
* Unique server id
* Unique server id.
*/
private final String guid;
/**
* Debug mode
* Debug mode.
*/
private final boolean debug;
/**
* The scheduled task
* The scheduled task.
*/
private volatile BukkitTask task = null;
@ -97,7 +97,7 @@ public class Metrics {
}
/**
* GZip compress a string of bytes
* GZip compress a string of bytes.
*
* @param input
*
@ -129,7 +129,6 @@ public class Metrics {
* @param key
* @param value
*
* @throws UnsupportedEncodingException
*/
private static void appendJSONPair(StringBuilder json, String key, String value) {
boolean isValueNumeric = false;

View File

@ -336,7 +336,7 @@ public class NbtFactory {
}
/**
* Search for the first publically and privately defined method of the given name and parameter count.
* Search for the first publicly and privately defined method of the given name and parameter count.
* @param requireMod - modifiers that are required.
* @param bannedMod - modifiers that are banned.
* @param clazz - a class to start with.
@ -366,7 +366,7 @@ public class NbtFactory {
}
/**
* Search for the first publically and privately defined field of the given name.
* Search for the first publicly and privately defined field of the given name.
* @param instance - an instance of the class with the field.
* @param clazz - an optional class to start with, or NULL to deduce it from instance.
* @param fieldName - the field name.

View File

@ -56,7 +56,7 @@ public class OfflinePlayerUtil {
return name;
}
Constructor gameProfileConstructor = makeConstructor(gameProfileClass, UUID.class, String.class);
if (gameProfileConstructor == null) { //Verson has string constructor
if (gameProfileConstructor == null) { //Version has string constructor
gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
return callConstructor(gameProfileConstructor, id.toString(), name);
} else { //Version has uuid constructor

View File

@ -127,10 +127,10 @@ public class SendChunk {
}
}
public void sendChunk(String worldname, Collection<ChunkLoc> locs) {
public void sendChunk(String worldname, Collection<ChunkLoc> chunkLocs) {
World myworld = Bukkit.getWorld(worldname);
ArrayList<Chunk> chunks = new ArrayList<>();
for (ChunkLoc loc : locs) {
for (ChunkLoc loc : chunkLocs) {
if (myworld.isChunkLoaded(loc.x, loc.z)) {
chunks.add(myworld.getChunkAt(loc.x, loc.z));
}