Code cleanup

This commit is contained in:
MattBDev 2016-03-28 19:30:55 -04:00
parent 874da8c5bc
commit b1fa258688
35 changed files with 548 additions and 552 deletions

View File

@ -7,34 +7,34 @@ import org.bukkit.Bukkit;
public class BukkitTaskManager extends TaskManager { public class BukkitTaskManager extends TaskManager {
@Override @Override
public int taskRepeat(Runnable r, int interval) { public int taskRepeat(Runnable runnable, int interval) {
return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, r, interval, interval); return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public int taskRepeatAsync(Runnable r, int interval) { public int taskRepeatAsync(Runnable runnable, int interval) {
return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, r, interval, interval); return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval);
} }
@Override @Override
public void taskAsync(Runnable r) { public void taskAsync(Runnable runnable) {
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r).getTaskId(); BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, runnable).getTaskId();
} }
@Override @Override
public void task(Runnable r) { public void task(Runnable runnable) {
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r).getTaskId(); BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, runnable).getTaskId();
} }
@Override @Override
public void taskLater(Runnable r, int delay) { public void taskLater(Runnable runnable, int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, r, delay).getTaskId(); BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, runnable, delay).getTaskId();
} }
@Override @Override
public void taskLaterAsync(Runnable r, int delay) { public void taskLaterAsync(Runnable runnable, int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, r, delay); BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, runnable, delay);
} }
@Override @Override

View File

@ -1,34 +1,35 @@
package com.intellectualcrafters.configuration.file; package com.intellectualcrafters.configuration.file;
import java.util.LinkedHashMap;
import java.util.Map;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.representer.Representer;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable; import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization; import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.representer.Representer;
import java.util.LinkedHashMap;
import java.util.Map;
public class YamlRepresenter extends Representer { public class YamlRepresenter extends Representer {
public YamlRepresenter() { public YamlRepresenter() {
multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection()); this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable()); this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
} }
private class RepresentConfigurationSection extends RepresentMap { private class RepresentConfigurationSection extends RepresentMap {
@Override @Override
public Node representData(final Object data) { public Node representData(Object data) {
return super.representData(((ConfigurationSection) data).getValues(false)); return super.representData(((ConfigurationSection) data).getValues(false));
} }
} }
private class RepresentConfigurationSerializable extends RepresentMap { private class RepresentConfigurationSerializable extends RepresentMap {
@Override @Override
public Node representData(final Object data) { public Node representData(Object data) {
final ConfigurationSerializable serializable = (ConfigurationSerializable) data; ConfigurationSerializable serializable = (ConfigurationSerializable) data;
final Map<String, Object> values = new LinkedHashMap<>(); Map<String, Object> values = new LinkedHashMap<>();
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass())); values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
values.putAll(serializable.serialize()); values.putAll(serializable.serialize());

View File

@ -89,7 +89,6 @@ import java.util.zip.ZipInputStream;
*/ */
public class PS { public class PS {
// protected static:
private static PS instance; private static PS instance;
private final HashSet<Integer> plotareaHashCheck = new HashSet<>(); private final HashSet<Integer> plotareaHashCheck = new HashSet<>();
/** /**
@ -99,10 +98,9 @@ public class PS {
/** /**
* All plot areas mapped by location (quick location based access). * All plot areas mapped by location (quick location based access).
*/ */
private final HashMap<String, QuadMap<PlotArea>> plotareagrid = new HashMap<>(); private final HashMap<String, QuadMap<PlotArea>> plotAreaGrid = new HashMap<>();
public HashMap<String, Set<PlotCluster>> clusters_tmp; public HashMap<String, Set<PlotCluster>> clusters_tmp;
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp; public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
// public:
public File styleFile; public File styleFile;
public File configFile; public File configFile;
public File commandsFile; public File commandsFile;
@ -119,11 +117,11 @@ public class PS {
/** /**
* All plot areas (quick global access). * All plot areas (quick global access).
*/ */
private PlotArea[] plotareas = new PlotArea[0]; private PlotArea[] plotAreas = new PlotArea[0];
// private:
private File storageFile; private File storageFile;
private File file = null; // This file private File file = null; // This file
private int[] version = null; private int[] version;
private int[] lastVersion; private int[] lastVersion;
private String platform = null; private String platform = null;
private Database database; private Database database;
@ -429,11 +427,11 @@ public class PS {
* @return * @return
*/ */
public PlotArea getApplicablePlotArea(Location location) { public PlotArea getApplicablePlotArea(Location location) {
switch (this.plotareas.length) { switch (this.plotAreas.length) {
case 0: case 0:
return null; return null;
case 1: case 1:
return this.plotareas[0]; return this.plotAreas[0];
case 2: case 2:
case 3: case 3:
case 4: case 4:
@ -443,7 +441,7 @@ public class PS {
case 8: case 8:
String world = location.getWorld(); String world = location.getWorld();
int hash = world.hashCode(); int hash = world.hashCode();
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
if (hash == area.worldhash) { if (hash == area.worldhash) {
if (area.contains(location.getX(), location.getZ()) && (!this.plotareaHasCollision || world.equals(area.worldname))) { if (area.contains(location.getX(), location.getZ()) && (!this.plotareaHasCollision || world.equals(area.worldname))) {
return area; return area;
@ -477,7 +475,7 @@ public class PS {
} }
return null; return null;
default: default:
QuadMap<PlotArea> search = this.plotareagrid.get(location.getWorld()); QuadMap<PlotArea> search = this.plotAreaGrid.get(location.getWorld());
return search.get(location.getX(), location.getZ()); return search.get(location.getX(), location.getZ());
} }
} }
@ -519,7 +517,7 @@ public class PS {
String[] split = search.split(";|,"); String[] split = search.split(";|,");
PlotArea[] areas = this.plotareamap.get(split[0]); PlotArea[] areas = this.plotareamap.get(split[0]);
if (areas == null) { if (areas == null) {
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
if (area.worldname.equalsIgnoreCase(split[0])) { if (area.worldname.equalsIgnoreCase(split[0])) {
if (area.id == null || split.length == 2 && area.id.equalsIgnoreCase(split[1])) { if (area.id == null || split.length == 2 && area.id.equalsIgnoreCase(split[1])) {
return area; return area;
@ -543,7 +541,7 @@ public class PS {
} }
public Set<PlotArea> getPlotAreas(String world, RegionWrapper region) { public Set<PlotArea> getPlotAreas(String world, RegionWrapper region) {
QuadMap<PlotArea> areas = this.plotareagrid.get(world); QuadMap<PlotArea> areas = this.plotAreaGrid.get(world);
return areas != null ? areas.get(region) : new HashSet<PlotArea>(); return areas != null ? areas.get(region) : new HashSet<PlotArea>();
} }
@ -557,11 +555,11 @@ public class PS {
* @return * @return
*/ */
public PlotArea getPlotAreaAbs(Location location) { public PlotArea getPlotAreaAbs(Location location) {
switch (this.plotareas.length) { switch (this.plotAreas.length) {
case 0: case 0:
return null; return null;
case 1: case 1:
PlotArea pa = this.plotareas[0]; PlotArea pa = this.plotAreas[0];
return pa.contains(location) ? pa : null; return pa.contains(location) ? pa : null;
case 2: case 2:
case 3: case 3:
@ -572,7 +570,7 @@ public class PS {
case 8: case 8:
String world = location.getWorld(); String world = location.getWorld();
int hash = world.hashCode(); int hash = world.hashCode();
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
if (hash == area.worldhash) { if (hash == area.worldhash) {
if (area.contains(location.getX(), location.getZ()) && (!this.plotareaHasCollision || world.equals(area.worldname))) { if (area.contains(location.getX(), location.getZ()) && (!this.plotareaHasCollision || world.equals(area.worldname))) {
return area; return area;
@ -607,7 +605,7 @@ public class PS {
} }
return null; return null;
default: default:
QuadMap<PlotArea> search = this.plotareagrid.get(location.getWorld()); QuadMap<PlotArea> search = this.plotAreaGrid.get(location.getWorld());
return search.get(location.getX(), location.getZ()); return search.get(location.getX(), location.getZ());
} }
} }
@ -625,21 +623,21 @@ public class PS {
/** /**
* Add a global reference to a plot world. * Add a global reference to a plot world.
* *
* @param plotarea The PlotArea * @param plotArea The PlotArea
* @see #removePlotArea(PlotArea) To remove the reference * @see #removePlotArea(PlotArea) To remove the reference
*/ */
public void addPlotArea(PlotArea plotarea) { public void addPlotArea(PlotArea plotArea) {
HashMap<PlotId, Plot> plots = this.plots_tmp.remove(plotarea.toString()); HashMap<PlotId, Plot> plots = this.plots_tmp.remove(plotArea.toString());
if (plots == null) { if (plots == null) {
if (plotarea.TYPE == 2) { if (plotArea.TYPE == 2) {
plots = this.plots_tmp.get(plotarea.worldname); plots = this.plots_tmp.get(plotArea.worldname);
if (plots != null) { if (plots != null) {
Iterator<Entry<PlotId, Plot>> iter = plots.entrySet().iterator(); Iterator<Entry<PlotId, Plot>> iter = plots.entrySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Entry<PlotId, Plot> next = iter.next(); Entry<PlotId, Plot> next = iter.next();
PlotId id = next.getKey(); PlotId id = next.getKey();
if (plotarea.contains(id)) { if (plotArea.contains(id)) {
next.getValue().setArea(plotarea); next.getValue().setArea(plotArea);
iter.remove(); iter.remove();
} }
} }
@ -648,19 +646,19 @@ public class PS {
} else { } else {
for (Entry<PlotId, Plot> entry : plots.entrySet()) { for (Entry<PlotId, Plot> entry : plots.entrySet()) {
Plot plot = entry.getValue(); Plot plot = entry.getValue();
plot.setArea(plotarea); plot.setArea(plotArea);
} }
} }
Set<PlotCluster> clusters = this.clusters_tmp.remove(plotarea.toString()); Set<PlotCluster> clusters = this.clusters_tmp.remove(plotArea.toString());
if (clusters == null) { if (clusters == null) {
if (plotarea.TYPE == 2) { if (plotArea.TYPE == 2) {
clusters = this.clusters_tmp.get(plotarea.worldname); clusters = this.clusters_tmp.get(plotArea.worldname);
if (clusters != null) { if (clusters != null) {
Iterator<PlotCluster> iter = clusters.iterator(); Iterator<PlotCluster> iter = clusters.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
PlotCluster next = iter.next(); PlotCluster next = iter.next();
if (next.intersects(plotarea.getMin(), plotarea.getMax())) { if (next.intersects(plotArea.getMin(), plotArea.getMax())) {
next.setArea(plotarea); next.setArea(plotArea);
iter.remove(); iter.remove();
} }
} }
@ -668,16 +666,16 @@ public class PS {
} }
} else { } else {
for (PlotCluster cluster : clusters) { for (PlotCluster cluster : clusters) {
cluster.setArea(plotarea); cluster.setArea(plotArea);
} }
} }
Set<PlotArea> localAreas = getPlotAreas(plotarea.worldname); Set<PlotArea> localAreas = getPlotAreas(plotArea.worldname);
Set<PlotArea> globalAreas = getPlotAreas(); Set<PlotArea> globalAreas = getPlotAreas();
localAreas.add(plotarea); localAreas.add(plotArea);
globalAreas.add(plotarea); globalAreas.add(plotArea);
this.plotareas = globalAreas.toArray(new PlotArea[globalAreas.size()]); this.plotAreas = globalAreas.toArray(new PlotArea[globalAreas.size()]);
this.plotareamap.put(plotarea.worldname, localAreas.toArray(new PlotArea[localAreas.size()])); this.plotareamap.put(plotArea.worldname, localAreas.toArray(new PlotArea[localAreas.size()]));
QuadMap<PlotArea> map = this.plotareagrid.get(plotarea.worldname); QuadMap<PlotArea> map = this.plotAreaGrid.get(plotArea.worldname);
if (map == null) { if (map == null) {
map = new QuadMap<PlotArea>(Integer.MAX_VALUE, 0, 0) { map = new QuadMap<PlotArea>(Integer.MAX_VALUE, 0, 0) {
@Override @Override
@ -685,9 +683,9 @@ public class PS {
return value.getRegion(); return value.getRegion();
} }
}; };
this.plotareagrid.put(plotarea.worldname, map); this.plotAreaGrid.put(plotArea.worldname, map);
} }
map.add(plotarea); map.add(plotArea);
} }
/** /**
@ -699,13 +697,13 @@ public class PS {
public void removePlotArea(PlotArea area) { public void removePlotArea(PlotArea area) {
Set<PlotArea> areas = getPlotAreas(area.worldname); Set<PlotArea> areas = getPlotAreas(area.worldname);
areas.remove(area); areas.remove(area);
this.plotareas = areas.toArray(new PlotArea[areas.size()]); this.plotAreas = areas.toArray(new PlotArea[areas.size()]);
if (areas.isEmpty()) { if (areas.isEmpty()) {
this.plotareamap.remove(area.worldname); this.plotareamap.remove(area.worldname);
this.plotareagrid.remove(area.worldname); this.plotAreaGrid.remove(area.worldname);
} else { } else {
this.plotareamap.put(area.worldname, areas.toArray(new PlotArea[areas.size()])); this.plotareamap.put(area.worldname, areas.toArray(new PlotArea[areas.size()]));
this.plotareagrid.get(area.worldname).remove(area); this.plotAreaGrid.get(area.worldname).remove(area);
} }
setPlotsTmp(area); setPlotsTmp(area);
} }
@ -1040,11 +1038,11 @@ public class PS {
HashMap<PlotArea, Collection<Plot>> map = new HashMap<>(); HashMap<PlotArea, Collection<Plot>> map = new HashMap<>();
int totalSize = getPlotCount(); int totalSize = getPlotCount();
if (myplots.size() == totalSize) { if (myplots.size() == totalSize) {
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
map.put(area, area.getPlots()); map.put(area, area.getPlots());
} }
} else { } else {
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
map.put(area, new ArrayList<Plot>(0)); map.put(area, new ArrayList<Plot>(0));
} }
Collection<Plot> lastList = null; Collection<Plot> lastList = null;
@ -1059,7 +1057,7 @@ public class PS {
} }
} }
} }
List<PlotArea> areas = Arrays.asList(this.plotareas); List<PlotArea> areas = Arrays.asList(this.plotAreas);
Collections.sort(areas, new Comparator<PlotArea>() { Collections.sort(areas, new Comparator<PlotArea>() {
@Override @Override
public int compare(PlotArea a, PlotArea b) { public int compare(PlotArea a, PlotArea b) {
@ -1189,11 +1187,11 @@ public class PS {
* @return if a plot world is registered * @return if a plot world is registered
*/ */
public boolean hasPlotArea(String world) { public boolean hasPlotArea(String world) {
switch (this.plotareas.length) { switch (this.plotAreas.length) {
case 0: case 0:
return false; return false;
case 1: case 1:
PlotArea a = this.plotareas[0]; PlotArea a = this.plotAreas[0];
return world.hashCode() == a.worldhash && (!this.plotareaHasCollision || a.worldname.equals(world)); return world.hashCode() == a.worldhash && (!this.plotareaHasCollision || a.worldname.equals(world));
case 2: case 2:
case 3: case 3:
@ -1203,7 +1201,7 @@ public class PS {
case 7: case 7:
case 8: case 8:
int hash = world.hashCode(); int hash = world.hashCode();
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
if (area.worldhash == hash && (!this.plotareaHasCollision || area.worldname.equals(world))) { if (area.worldhash == hash && (!this.plotareaHasCollision || area.worldname.equals(world))) {
return true; return true;
} }
@ -1726,7 +1724,7 @@ public class PS {
private Map<String, Map<PlotId, Plot>> getPlotsRaw() { private Map<String, Map<PlotId, Plot>> getPlotsRaw() {
HashMap<String, Map<PlotId, Plot>> map = new HashMap<>(); HashMap<String, Map<PlotId, Plot>> map = new HashMap<>();
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
Map<PlotId, Plot> map2 = map.get(area.toString()); Map<PlotId, Plot> map2 = map.get(area.toString());
if (map2 == null) { if (map2 == null) {
map.put(area.toString(), area.getPlotsRaw()); map.put(area.toString(), area.getPlotsRaw());
@ -2347,13 +2345,13 @@ public class PS {
} }
public void foreachPlotArea(RunnableVal<PlotArea> runnable) { public void foreachPlotArea(RunnableVal<PlotArea> runnable) {
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
runnable.run(area); runnable.run(area);
} }
} }
public void foreachPlot(RunnableVal<Plot> runnable) { public void foreachPlot(RunnableVal<Plot> runnable) {
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
for (Plot plot : area.getPlots()) { for (Plot plot : area.getPlots()) {
runnable.run(plot); runnable.run(plot);
} }
@ -2361,7 +2359,7 @@ public class PS {
} }
public void foreachPlotRaw(RunnableVal<Plot> runnable) { public void foreachPlotRaw(RunnableVal<Plot> runnable) {
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
for (Plot plot : area.getPlots()) { for (Plot plot : area.getPlots()) {
runnable.run(plot); runnable.run(plot);
} }
@ -2376,7 +2374,7 @@ public class PS {
} }
public void foreachBasePlot(RunnableVal<Plot> run) { public void foreachBasePlot(RunnableVal<Plot> run) {
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
area.foreachBasePlot(run); area.foreachBasePlot(run);
} }
} }
@ -2392,16 +2390,16 @@ public class PS {
} }
public PlotArea getFirstPlotArea() { public PlotArea getFirstPlotArea() {
return this.plotareas.length > 0 ? this.plotareas[0] : null; return this.plotAreas.length > 0 ? this.plotAreas[0] : null;
} }
public int getPlotAreaCount() { public int getPlotAreaCount() {
return this.plotareas.length; return this.plotAreas.length;
} }
public int getPlotCount() { public int getPlotCount() {
int count = 0; int count = 0;
for (PlotArea area : this.plotareas) { for (PlotArea area : this.plotAreas) {
count += area.getPlotCount(); count += area.getPlotCount();
} }
return count; return count;
@ -2412,8 +2410,8 @@ public class PS {
} }
public Set<PlotArea> getPlotAreas() { public Set<PlotArea> getPlotAreas() {
HashSet<PlotArea> set = new HashSet<>(this.plotareas.length); HashSet<PlotArea> set = new HashSet<>(this.plotAreas.length);
Collections.addAll(set, this.plotareas); Collections.addAll(set, this.plotAreas);
return set; return set;
} }

View File

@ -59,7 +59,6 @@ public class Updater {
} else { } else {
version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), 0}; version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), 0};
} }
URL url = new URL(asset.getString("browser_download_url"));
// If current version >= update // If current version >= update
if (PS.get().checkVersion(PS.get().getVersion(), version)) { if (PS.get().checkVersion(PS.get().getVersion(), version)) {
PS.debug("&7PlotSquared is already up to date!"); PS.debug("&7PlotSquared is already up to date!");
@ -68,7 +67,7 @@ public class Updater {
log("&6PlotSquared " + StringMan.join(split, ".") + " is available:"); log("&6PlotSquared " + StringMan.join(split, ".") + " is available:");
log("&8 - &3Use: &7/plot update"); log("&8 - &3Use: &7/plot update");
log("&8 - &3Or: &7" + downloadURL); log("&8 - &3Or: &7" + downloadURL);
return url; return new URL(asset.getString("browser_download_url"));
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();
log("&dCould not check for updates (1)"); log("&dCould not check for updates (1)");

View File

@ -70,14 +70,16 @@ public class Inbox extends SubCommand {
// This might work xD // This might work xD
for (int x = page * 12; x < max; x++) { for (int x = page * 12; x < max; x++) {
PlotComment c = comments[x]; PlotComment comment = comments[x];
String color; String color;
if (player.getName().equals(c.senderName)) { if (player.getName().equals(comment.senderName)) {
color = "&a"; color = "&a";
} else { } else {
color = "&7"; color = "&7";
} }
string.append("&8[&7#" + (x + 1) + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n"); string.append(
"&8[&7#" + (x + 1) + "&8][&7" + comment.world + ";" + comment.id + "&8][&6" + comment.senderName + "&8]" + color + comment.comment
+ "\n");
} }
MainUtil.sendMessage(player, string.toString()); MainUtil.sendMessage(player, string.toString());
} }

View File

@ -38,7 +38,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
description = "Player music in a plot", description = "Player music in a plot",
usage = "/plot music", usage = "/plot music",
category = CommandCategory.APPEARANCE, category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE) requiredType = RequiredType.PLAYER)
public class Music extends SubCommand { public class Music extends SubCommand {
@Override @Override

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.InvalidConfigurationException;
import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
@ -158,7 +159,7 @@ public class Template extends SubCommand {
try { try {
PS.get().config.save(PS.get().configFile); PS.get().config.save(PS.get().configFile);
PS.get().config.load(PS.get().configFile); PS.get().config.load(PS.get().configFile);
} catch (Exception e) { } catch (InvalidConfigurationException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
String manager = worldConfig.getString("generator.plugin", "PlotSquared"); String manager = worldConfig.getString("generator.plugin", "PlotSquared");

View File

@ -113,8 +113,8 @@ public class Trim extends SubCommand {
} }
/** /**
* Runs the result task with the parameters (viable, nonViable).<br> * Runs the result task with the parameters (viable, nonViable).
* @param world * @param world The world
* @param result (viable = .mcr to trim, nonViable = .mcr keep) * @param result (viable = .mcr to trim, nonViable = .mcr keep)
* @return * @return
*/ */

View File

@ -38,7 +38,7 @@ import java.util.UUID;
aliases = {"ud"}, aliases = {"ud"},
description = "Remove a denied user from a plot", description = "Remove a denied user from a plot",
usage = "/plot undeny <player>", usage = "/plot undeny <player>",
requiredType = RequiredType.NONE, requiredType = RequiredType.PLAYER,
category = CommandCategory.SETTINGS) category = CommandCategory.SETTINGS)
public class Undeny extends SubCommand { public class Undeny extends SubCommand {

View File

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

View File

@ -44,7 +44,7 @@ import java.util.UUID;
description = "Visit someones plot", description = "Visit someones plot",
usage = "/plot visit [player|alias|world|id] [#]", usage = "/plot visit [player|alias|world|id] [#]",
aliases = {"v", "tp", "teleport", "goto", "home", "h"}, aliases = {"v", "tp", "teleport", "goto", "home", "h"},
requiredType = RequiredType.NONE, requiredType = RequiredType.PLAYER,
category = CommandCategory.TELEPORT) category = CommandCategory.TELEPORT)
public class Visit extends SubCommand { public class Visit extends SubCommand {

View File

@ -218,7 +218,7 @@ public class Configuration {
/** /**
* Create your own SettingValue object to make the management of plotworld configuration easier * Create your own SettingValue object to make the management of plotworld configuration easier
*/ */
public static abstract class SettingValue<T> { public abstract static class SettingValue<T> {
private final String type; private final String type;

View File

@ -20,81 +20,81 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.config; package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.intellectualcrafters.plot.config.Configuration.SettingValue; import com.intellectualcrafters.plot.config.Configuration.SettingValue;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** /**
* Configuration Node * Configuration Node.
*
*/ */
public class ConfigurationNode { public class ConfigurationNode {
private final String constant; private final String constant;
private final Object default_value; private final Object defaultValue;
private final String description; private final String description;
private final SettingValue type; private final SettingValue type;
private Object value; private Object value;
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) { public ConfigurationNode(String constant, Object defaultValue, String description, SettingValue type, boolean required) {
this.constant = constant; this.constant = constant;
this.default_value = default_value; this.defaultValue = defaultValue;
this.description = description; this.description = description;
value = default_value; this.value = defaultValue;
this.type = type; this.type = type;
} }
public SettingValue getType() { public SettingValue getType() {
return type; return this.type;
} }
public boolean isValid(final String string) { public boolean isValid(String string) {
try { try {
final Object result = type.parseString(string); Object result = this.type.parseString(string);
return result != null; return result != null;
} catch (final Exception e) { } catch (Exception e) {
return false; return false;
} }
} }
public boolean setValue(final String string) { public boolean setValue(String string) {
if (!type.validateValue(string)) { if (!this.type.validateValue(string)) {
return false; return false;
} }
value = type.parseString(string); this.value = this.type.parseString(string);
return true; return true;
} }
public Object getValue() { public Object getValue() {
if (value instanceof String[]) { if (this.value instanceof String[]) {
return Arrays.asList((String[]) value); return Arrays.asList((String[]) this.value);
} else if (value instanceof Object[]) { } else if (this.value instanceof Object[]) {
final List<String> values = new ArrayList<String>(); List<String> values = new ArrayList<String>();
for (final Object value : (Object[]) this.value) { for (Object value : (Object[]) this.value) {
values.add(value.toString()); values.add(value.toString());
} }
return values; return values;
} else if (value instanceof PlotBlock) { } else if (this.value instanceof PlotBlock) {
return value.toString(); return this.value.toString();
} }
return value; return this.value;
} }
public String getConstant() { public String getConstant() {
return constant; return this.constant;
} }
public Object getDefaultValue() { public Object getDefaultValue() {
if (default_value instanceof Object[]) { if (this.defaultValue instanceof Object[]) {
return StringMan.join((Object[]) default_value, ","); return StringMan.join((Object[]) this.defaultValue, ",");
} }
return default_value; return this.defaultValue;
} }
public String getDescription() { public String getDescription() {
return description; return this.description;
} }
} }

View File

@ -44,7 +44,7 @@ import java.util.UUID;
*/ */
public class DBFunc { public class DBFunc {
/** /**
* The "global" uuid * The "global" uuid.
*/ */
public static final UUID everyone = UUID.fromString("1-1-3-3-7"); public static final UUID everyone = UUID.fromString("1-1-3-3-7");
/** /**

View File

@ -267,35 +267,35 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
/** /**
* PLOT MERGING * PLOT MERGING.
*/ */
@Override @Override
public boolean createRoadEast(PlotArea plotworld, Plot plot) { public boolean createRoadEast(PlotArea plotArea, Plot plot) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId()); Location pos1 = getPlotBottomLocAbs(plotArea, plot.getId());
Location pos2 = getPlotTopLocAbs(plotworld, plot.getId()); Location pos2 = getPlotTopLocAbs(plotArea, plot.getId());
int sx = pos2.getX() + 1; int sx = pos2.getX() + 1;
int ex = sx + dpw.ROAD_WIDTH - 1; int ex = sx + dpw.ROAD_WIDTH - 1;
int sz = pos1.getZ() - 2; int sz = pos1.getZ() - 2;
int ez = pos2.getZ() + 2; int ez = pos2.getZ() + 2;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, MainUtil.setSimpleCuboidAsync(plotArea.worldname,
new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotArea.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1),
new Location(plotworld.worldname, ex, 255, ez - 1), new PlotBlock((short) 0, (byte) 0)); new Location(plotArea.worldname, ex, 255, ez - 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 0, sz + 1), MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx, 0, sz + 1),
new Location(plotworld.worldname, ex, 0, ez - 1), new PlotBlock((short) 7, new Location(plotArea.worldname, ex, 0, ez - 1), new PlotBlock((short) 7,
(byte) 0)); (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx, 1, sz + 1),
new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING); new Location(plotArea.worldname, sx, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1), MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1),
new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, ez - 1), new Location(plotArea.worldname, sx, dpw.WALL_HEIGHT + 1, ez - 1),
dpw.WALL_BLOCK); dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, 1, sz + 1), MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, ex, 1, sz + 1),
new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING); new Location(plotArea.worldname, ex, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1),
new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, ez - 1), new Location(plotArea.worldname, ex, dpw.WALL_HEIGHT + 1, ez - 1),
dpw.WALL_BLOCK); dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx + 1, 1, sz + 1),
new Location(plotworld.worldname, ex - 1, dpw.ROAD_HEIGHT, ez - 1), dpw.ROAD_BLOCK); new Location(plotArea.worldname, ex - 1, dpw.ROAD_HEIGHT, ez - 1), dpw.ROAD_BLOCK);
return true; return true;
} }
@ -400,7 +400,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
/** /**
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED) * Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED).
*/ */
@Override @Override
public boolean finishPlotMerge(PlotArea plotworld, ArrayList<PlotId> plotIds) { public boolean finishPlotMerge(PlotArea plotworld, ArrayList<PlotId> plotIds) {

View File

@ -72,16 +72,16 @@ public class HybridPlotManager extends ClassicPlotManager {
} }
@Override @Override
public boolean createRoadEast(PlotArea plotworld, Plot plot) { public boolean createRoadEast(PlotArea plotArea, Plot plot) {
super.createRoadEast(plotworld, plot); super.createRoadEast(plotArea, plot);
HybridPlotWorld hpw = (HybridPlotWorld) plotworld; HybridPlotWorld hpw = (HybridPlotWorld) plotArea;
PlotId id = plot.getId(); PlotId id = plot.getId();
PlotId id2 = new PlotId(id.x + 1, id.y); PlotId id2 = new PlotId(id.x + 1, id.y);
Location bot = getPlotBottomLocAbs(hpw, id2); Location bot = getPlotBottomLocAbs(hpw, id2);
Location top = getPlotTopLocAbs(hpw, id); Location top = getPlotTopLocAbs(hpw, id);
Location pos1 = new Location(plotworld.worldname, top.getX() + 1, 0, bot.getZ() - 1); Location pos1 = new Location(plotArea.worldname, top.getX() + 1, 0, bot.getZ() - 1);
Location pos2 = new Location(plotworld.worldname, bot.getX(), 255, top.getZ() + 1); Location pos2 = new Location(plotArea.worldname, bot.getX(), 255, top.getZ() + 1);
MainUtil.resetBiome(plotworld, pos1, pos2); MainUtil.resetBiome(plotArea, pos1, pos2);
if (!hpw.ROAD_SCHEMATIC_ENABLED) { if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true; return true;
} }

View File

@ -47,8 +47,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public HashMap<Integer, HashMap<Integer, PlotBlock>> G_SCH; public HashMap<Integer, HashMap<Integer, PlotBlock>> G_SCH;
public HashMap<Integer, HashSet<PlotItem>> G_SCH_STATE; public HashMap<Integer, HashSet<PlotItem>> G_SCH_STATE;
public HybridPlotWorld(String worldname, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) { public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
super(worldname, id, generator, min, max); super(worldName, id, generator, min, max);
} }
public static byte wrap(byte data, int start) { public static byte wrap(byte data, int start) {

View File

@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
public abstract class PlotGenerator<T> { public abstract class PlotGenerator<T> {
public T generator; public T generator;
public PlotGenerator(T generator) { public PlotGenerator(T generator) {

View File

@ -183,15 +183,15 @@ public abstract class SquarePlotManager extends GridPlotManager {
} }
/** /**
* Get the bottom plot loc (some basic math) * Get the bottom plot loc (some basic math).
*/ */
@Override @Override
public Location getPlotBottomLocAbs(PlotArea plotworld, PlotId plotid) { public Location getPlotBottomLocAbs(PlotArea plotArea, PlotId plotId) {
SquarePlotWorld dpw = (SquarePlotWorld) plotworld; SquarePlotWorld dpw = (SquarePlotWorld) plotArea;
int px = plotid.x; int px = plotId.x;
int pz = plotid.y; int pz = plotId.y;
int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2); int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2);
int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2); int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2);
return new Location(plotworld.worldname, x, plotworld.MIN_BUILD_HEIGHT, z); return new Location(plotArea.worldname, x, plotArea.MIN_BUILD_HEIGHT, z);
} }
} }

View File

@ -158,12 +158,13 @@ public class PlotSettings {
} }
/** /**
* Get the "farewell" flag value * Get the "farewell" flag value.
* *
* @param plotArea The PlotArea
* @return Farewell flag * @return Farewell flag
*/ */
public String getLeaveMessage(PlotArea area) { public String getLeaveMessage(PlotArea plotArea) {
Flag farewell = FlagManager.getSettingFlag(area, this, "farewell"); Flag farewell = FlagManager.getSettingFlag(plotArea, this, "farewell");
if (farewell != null) { if (farewell != null) {
return farewell.getValueString(); return farewell.getValueString();
} }

View File

@ -6,23 +6,23 @@ public class PseudoRandom {
public long state = System.nanoTime(); public long state = System.nanoTime();
public long nextLong() { public long nextLong() {
final long a = state; long a = this.state;
state = xorShift64(a); this.state = xorShift64(a);
return a; return a;
} }
public long xorShift64(long a) { public long xorShift64(long a) {
a ^= (a << 21); a ^= a << 21;
a ^= (a >>> 35); a ^= a >>> 35;
a ^= (a << 4); a ^= a << 4;
return a; return a;
} }
public int random(final int n) { public int random(int n) {
if (n == 1) { if (n == 1) {
return 0; return 0;
} }
final long r = ((nextLong() >>> 32) * n) >> 32; long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r; return (int) r;
} }
} }

View File

@ -21,16 +21,19 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
/** /**
*/ */
public class StringWrapper { public class StringWrapper {
public final String value; public final String value;
private int hash;
/** /**
* Constructor * Constructor
* *
* @param value to wrap * @param value to wrap
*/ */
public StringWrapper(final String value) { public StringWrapper(String value) {
this.value = value; this.value = value;
} }
@ -42,7 +45,7 @@ public class StringWrapper {
* @return true if obj equals the stored value * @return true if obj equals the stored value
*/ */
@Override @Override
public boolean equals(final Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@ -55,38 +58,36 @@ public class StringWrapper {
if (obj.hashCode() != hashCode()) { if (obj.hashCode() != hashCode()) {
return false; return false;
} }
final StringWrapper other = (StringWrapper) obj; StringWrapper other = (StringWrapper) obj;
if ((other.value == null) || (value == null)) { if ((other.value == null) || (this.value == null)) {
return false; return false;
} }
return other.value.equalsIgnoreCase(value.toLowerCase()); return other.value.equalsIgnoreCase(this.value.toLowerCase());
} }
/** /**
* Get the string value * Get the string value.
* *
* @return string value * @return string value
*/ */
@Override @Override
public String toString() { public String toString() {
return value; return this.value;
} }
private int hash;
/** /**
* Get the hash value * Get the hash value.
* *
* @return has value * @return has value
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
if (value == null) { if (this.value == null) {
return 0; return 0;
} }
if (hash == 0) { if (this.hash == 0) {
hash = value.toLowerCase().hashCode(); this.hash = this.value.toLowerCase().hashCode();
} }
return hash; return this.hash;
} }
} }

View File

@ -1,21 +1,21 @@
package com.intellectualcrafters.plot.object.comment; package com.intellectualcrafters.plot.object.comment;
import java.util.List;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import java.util.List;
public abstract class CommentInbox { public abstract class CommentInbox {
@Override @Override
public abstract String toString(); public abstract String toString();
public abstract boolean canRead(final Plot plot, final PlotPlayer player); public abstract boolean canRead(Plot plot, PlotPlayer player);
public abstract boolean canWrite(final Plot plot, final PlotPlayer player); public abstract boolean canWrite(Plot plot, PlotPlayer player);
public abstract boolean canModify(final Plot plot, final PlotPlayer player); public abstract boolean canModify(Plot plot, PlotPlayer player);
/** /**
* The plot may be null if the user is not standing in a plot. Return false if this is not a plot-less inbox. * The plot may be null if the user is not standing in a plot. Return false if this is not a plot-less inbox.
@ -27,11 +27,11 @@ public abstract class CommentInbox {
* @param whenDone * @param whenDone
* @return * @return
*/ */
public abstract boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone); public abstract boolean getComments(Plot plot, RunnableVal<List<PlotComment>> whenDone);
public abstract boolean addComment(final Plot plot, final PlotComment comment); public abstract boolean addComment(Plot plot, PlotComment comment);
public abstract boolean removeComment(final Plot plot, final PlotComment comment); public abstract boolean removeComment(Plot plot, PlotComment comment);
public abstract boolean clearInbox(final Plot plot); public abstract boolean clearInbox(Plot plot);
} }

View File

@ -13,7 +13,7 @@ import java.util.List;
public class InboxOwner extends CommentInbox { public class InboxOwner extends CommentInbox {
@Override @Override
public boolean canRead(final Plot plot, final PlotPlayer player) { public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString()); return Permissions.hasPermission(player, "plots.inbox.read." + toString());
} }
@ -24,7 +24,7 @@ public class InboxOwner extends CommentInbox {
} }
@Override @Override
public boolean canWrite(final Plot plot, final PlotPlayer player) { public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString()); return Permissions.hasPermission(player, "plots.inbox.write." + toString());
} }
@ -35,7 +35,7 @@ public class InboxOwner extends CommentInbox {
} }
@Override @Override
public boolean canModify(final Plot plot, final PlotPlayer player) { public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
} }
@ -50,7 +50,7 @@ public class InboxOwner extends CommentInbox {
if ((plot == null) || (plot.owner == null)) { if ((plot == null) || (plot.owner == null)) {
return false; return false;
} }
final ArrayList<PlotComment> comments = plot.getSettings().getComments(toString()); ArrayList<PlotComment> comments = plot.getSettings().getComments(toString());
if (comments != null) { if (comments != null) {
whenDone.value = comments; whenDone.value = comments;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
@ -61,7 +61,7 @@ public class InboxOwner extends CommentInbox {
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
whenDone.value = value; whenDone.value = value;
if (value != null) { if (value != null) {
for (final PlotComment comment : value) { for (PlotComment comment : value) {
plot.getSettings().addComment(comment); plot.getSettings().addComment(comment);
} }
} else { } else {
@ -74,7 +74,7 @@ public class InboxOwner extends CommentInbox {
} }
@Override @Override
public boolean addComment(final Plot plot, final PlotComment comment) { public boolean addComment(Plot plot, PlotComment comment) {
if ((plot == null) || (plot.owner == null)) { if ((plot == null) || (plot.owner == null)) {
return false; return false;
} }
@ -89,7 +89,7 @@ public class InboxOwner extends CommentInbox {
} }
@Override @Override
public boolean removeComment(final Plot plot, final PlotComment comment) { public boolean removeComment(Plot plot, PlotComment comment) {
if ((plot == null) || (plot.owner == null)) { if ((plot == null) || (plot.owner == null)) {
return false; return false;
} }
@ -98,11 +98,11 @@ public class InboxOwner extends CommentInbox {
} }
@Override @Override
public boolean clearInbox(final Plot plot) { public boolean clearInbox(Plot plot) {
if ((plot == null) || (plot.owner == null)) { if (plot == null || plot.owner == null) {
return false; return false;
} }
DBFunc.clearInbox(plot, toString()); DBFunc.clearInbox(plot, this.toString());
return false; return false;
} }
} }

View File

@ -13,7 +13,7 @@ import java.util.List;
public class InboxPublic extends CommentInbox { public class InboxPublic extends CommentInbox {
@Override @Override
public boolean canRead(final Plot plot, final PlotPlayer player) { public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString()); return Permissions.hasPermission(player, "plots.inbox.read." + toString());
} }
@ -24,25 +24,21 @@ public class InboxPublic extends CommentInbox {
} }
@Override @Override
public boolean canWrite(final Plot plot, final PlotPlayer player) { public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString()); return Permissions.hasPermission(player, "plots.inbox.write." + toString());
} }
return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write." .hasPermission(player, "plots.inbox.write." + toString() + ".other"));
+ toString()
+ ".other"));
} }
@Override @Override
public boolean canModify(final Plot plot, final PlotPlayer player) { public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
} }
return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.modify." .hasPermission(player, "plots.inbox.modify." + toString() + ".other"));
+ toString()
+ ".other"));
} }
@Override @Override
@ -50,7 +46,7 @@ public class InboxPublic extends CommentInbox {
if ((plot == null) || (plot.owner == null)) { if ((plot == null) || (plot.owner == null)) {
return false; return false;
} }
final ArrayList<PlotComment> comments = plot.getSettings().getComments(toString()); ArrayList<PlotComment> comments = plot.getSettings().getComments(toString());
if (comments != null) { if (comments != null) {
whenDone.value = comments; whenDone.value = comments;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
@ -61,7 +57,7 @@ public class InboxPublic extends CommentInbox {
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
whenDone.value = value; whenDone.value = value;
if (value != null) { if (value != null) {
for (final PlotComment comment : value) { for (PlotComment comment : value) {
plot.getSettings().addComment(comment); plot.getSettings().addComment(comment);
} }
} }
@ -72,7 +68,7 @@ public class InboxPublic extends CommentInbox {
} }
@Override @Override
public boolean addComment(final Plot plot, final PlotComment comment) { public boolean addComment(Plot plot, PlotComment comment) {
if ((plot == null) || (plot.owner == null)) { if ((plot == null) || (plot.owner == null)) {
return false; return false;
} }
@ -87,7 +83,7 @@ public class InboxPublic extends CommentInbox {
} }
@Override @Override
public boolean removeComment(final Plot plot, final PlotComment comment) { public boolean removeComment(Plot plot, PlotComment comment) {
if ((plot == null) || (plot.owner == null)) { if ((plot == null) || (plot.owner == null)) {
return false; return false;
} }
@ -96,11 +92,11 @@ public class InboxPublic extends CommentInbox {
} }
@Override @Override
public boolean clearInbox(final Plot plot) { public boolean clearInbox(Plot plot) {
if ((plot == null) || (plot.owner == null)) { if (plot == null || plot.owner == null) {
return false; return false;
} }
DBFunc.clearInbox(plot, toString()); DBFunc.clearInbox(plot, this.toString());
return false; return false;
} }
} }

View File

@ -75,10 +75,10 @@ public class InboxReport extends CommentInbox {
@Override @Override
public boolean clearInbox(Plot plot) { public boolean clearInbox(Plot plot) {
if ((plot == null) || (plot.owner == null)) { if (plot == null || plot.owner == null) {
return false; return false;
} }
DBFunc.clearInbox(plot, toString()); DBFunc.clearInbox(plot, this.toString());
return false; return false;
} }
} }

View File

@ -22,8 +22,6 @@ package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
/**
*/
public class PlotComment { public class PlotComment {
public final String comment; public final String comment;
public final String inbox; public final String inbox;
@ -32,7 +30,7 @@ public class PlotComment {
public final String world; public final String world;
public final long timestamp; public final long timestamp;
public PlotComment(final String world, final PlotId id, final String comment, final String senderName, final String inbox, final long timestamp) { public PlotComment(String world, PlotId id, String comment, String senderName, String inbox, long timestamp) {
this.world = world; this.world = world;
this.id = id; this.id = id;
this.comment = comment; this.comment = comment;

View File

@ -8,7 +8,7 @@ public class PlotItem {
public byte[] data; public byte[] data;
public byte[] amount; public byte[] amount;
public PlotItem(final short x, final short y, final short z, final short[] id, final byte[] data, final byte[] amount) { public PlotItem(short x, short y, short z, short[] id, byte[] data, byte[] amount) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;

View File

@ -21,10 +21,7 @@ public class CommentManager {
public static HashMap<String, CommentInbox> inboxes = new HashMap<>(); public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
public static void sendTitle(final PlotPlayer player, final Plot plot) { public static void sendTitle(final PlotPlayer player, final Plot plot) {
if (!Settings.COMMENT_NOTIFICATIONS) { if (!Settings.COMMENT_NOTIFICATIONS || !plot.isOwner(player.getUUID())) {
return;
}
if (!plot.isOwner(player.getUUID())) {
return; return;
} }
TaskManager.runTaskLaterAsync(new Runnable() { TaskManager.runTaskLaterAsync(new Runnable() {

View File

@ -317,7 +317,7 @@ public class MainUtil {
} }
/** /**
* Get the name from a UUID<br> * Get the name from a UUID.
* @param owner * @param owner
* @return The player's name, None, Everyone or Unknown * @return The player's name, None, Everyone or Unknown
*/ */
@ -335,7 +335,7 @@ public class MainUtil {
} }
/** /**
* Get the corner locations for a list of regions<br> * Get the corner locations for a list of regions.
* @see Plot#getCorners() * @see Plot#getCorners()
* @param world * @param world
* @param regions * @param regions
@ -514,7 +514,7 @@ public class MainUtil {
} }
/** /**
* Resend the chunk at a location * Resend the chunk at a location.
* @param world * @param world
* @param loc * @param loc
*/ */
@ -530,7 +530,7 @@ public class MainUtil {
} }
/** /**
* Set a cuboid asynchronously to a set of blocks * Set a cuboid asynchronously to a set of blocks.
* @param world * @param world
* @param pos1 * @param pos1
* @param pos2 * @param pos2
@ -599,19 +599,19 @@ public class MainUtil {
} }
/** /**
* Send a message to the player * Send a message to the player.
* *
* @param plr Player to receive message * @param player Player to receive message
* @param msg Message to send * @param msg Message to send
* *
* @return true Can be used in things such as commands (return PlayerFunctions.sendMessage(...)) * @return true Can be used in things such as commands (return PlayerFunctions.sendMessage(...))
*/ */
public static boolean sendMessage(PlotPlayer plr, String msg) { public static boolean sendMessage(PlotPlayer player, String msg) {
return sendMessage(plr, msg, true); return sendMessage(player, msg, true);
} }
/** /**
* Send a message to console * Send a message to console.
* @param caption * @param caption
* @param args * @param args
*/ */
@ -621,17 +621,17 @@ public class MainUtil {
/** /**
* Send a message to a player. * Send a message to a player.
* @param plr Can be null to represent console, or use ConsolePlayer.getConsole() * @param player Can be null to represent console, or use ConsolePlayer.getConsole()
* @param msg * @param msg
* @param prefix If the message should be prefixed with the configured prefix * @param prefix If the message should be prefixed with the configured prefix
* @return * @return
*/ */
public static boolean sendMessage(PlotPlayer plr, String msg, boolean prefix) { public static boolean sendMessage(PlotPlayer player, String msg, boolean prefix) {
if (!msg.isEmpty()) { if (!msg.isEmpty()) {
if (plr == null) { if (player == null) {
ConsolePlayer.getConsole().sendMessage((prefix ? C.PREFIX.s() : "") + msg); ConsolePlayer.getConsole().sendMessage((prefix ? C.PREFIX.s() : "") + msg);
} else { } else {
plr.sendMessage((prefix ? C.PREFIX.s() : "") + C.color(msg)); player.sendMessage((prefix ? C.PREFIX.s() : "") + C.color(msg));
} }
} }
return true; return true;

View File

@ -55,24 +55,24 @@ public abstract class SchematicHandler {
private boolean exportAll = false; private boolean exportAll = false;
public boolean exportAll(final Collection<Plot> collection, final File outputDir, final String namingScheme, final Runnable ifSuccess) { public boolean exportAll(Collection<Plot> collection, final File outputDir, final String namingScheme, final Runnable ifSuccess) {
if (exportAll) { if (this.exportAll) {
return false; return false;
} }
if (collection.isEmpty()) { if (collection.isEmpty()) {
return false; return false;
} }
exportAll = true; this.exportAll = true;
final ArrayList<Plot> plots = new ArrayList<>(collection); final ArrayList<Plot> plots = new ArrayList<>(collection);
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
if (plots.isEmpty()) { if (plots.isEmpty()) {
exportAll = false; SchematicHandler.this.exportAll = false;
TaskManager.runTask(ifSuccess); TaskManager.runTask(ifSuccess);
return; return;
} }
final Iterator<Plot> i = plots.iterator(); Iterator<Plot> i = plots.iterator();
final Plot plot = i.next(); final Plot plot = i.next();
i.remove(); i.remove();
String o = UUIDHandler.getName(plot.owner); String o = UUIDHandler.getName(plot.owner);
@ -103,7 +103,7 @@ public abstract class SchematicHandler {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(null, "&6ID: " + plot.getId()); MainUtil.sendMessage(null, "&6ID: " + plot.getId());
final boolean result = SchematicHandler.manager.save(value, directory + File.separator + name + ".schematic"); boolean result = SchematicHandler.manager.save(value, directory + File.separator + name + ".schematic");
if (!result) { if (!result) {
MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.getId()); MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.getId());
} else { } else {
@ -128,16 +128,17 @@ public abstract class SchematicHandler {
/** /**
* Paste a schematic * Paste a schematic.
* *
* @param schematic the schematic object to paste * @param schematic the schematic object to paste
* @param plot plot to paste in * @param plot plot to paste in
* @param x_offset offset x to paste it from plot origin * @param xOffset offset x to paste it from plot origin
* @param z_offset offset z to paste it from plot origin * @param zOffset offset z to paste it from plot origin
* *
* @return boolean true if succeeded * @return boolean true if succeeded
*/ */
public void paste(final Schematic schematic, final Plot plot, final int x_offset, final int y_offset, final int z_offset, final boolean autoHeight, final RunnableVal<Boolean> whenDone) { public void paste(final Schematic schematic, final Plot plot, final int xOffset, final int yOffset, final int zOffset, final boolean autoHeight,
final RunnableVal<Boolean> whenDone) {
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -161,13 +162,13 @@ public abstract class SchematicHandler {
} }
} }
final Dimension demensions = schematic.getSchematicDimension(); Dimension demensions = schematic.getSchematicDimension();
final int WIDTH = demensions.getX(); final int WIDTH = demensions.getX();
final int LENGTH = demensions.getZ(); final int LENGTH = demensions.getZ();
final int HEIGHT = demensions.getY(); final int HEIGHT = demensions.getY();
// Validate dimensions // Validate dimensions
RegionWrapper region = plot.getLargestRegion(); RegionWrapper region = plot.getLargestRegion();
if (((region.maxX - region.minX + x_offset + 1) < WIDTH) || ((region.maxZ - region.minZ + z_offset + 1) < LENGTH) || (HEIGHT if (((region.maxX - region.minX + xOffset + 1) < WIDTH) || ((region.maxZ - region.minZ + zOffset + 1) < LENGTH) || (HEIGHT
> 256)) { > 256)) {
PS.debug("Schematic is too large"); PS.debug("Schematic is too large");
PS.debug("(" + WIDTH + "," + LENGTH + "," + HEIGHT + ") is bigger than (" + (region.maxX - region.minX) + "," + (region.maxZ - region.minZ) + ",256)"); PS.debug("(" + WIDTH + "," + LENGTH + "," + HEIGHT + ") is bigger than (" + (region.maxX - region.minX) + "," + (region.maxZ - region.minZ) + ",256)");
@ -181,21 +182,21 @@ public abstract class SchematicHandler {
final int y_offset_actual; final int y_offset_actual;
if (autoHeight) { if (autoHeight) {
if (HEIGHT >= 256) { if (HEIGHT >= 256) {
y_offset_actual = y_offset; y_offset_actual = yOffset;
} else { } else {
PlotArea pw = plot.getArea(); PlotArea pw = plot.getArea();
if (pw instanceof ClassicPlotWorld) { if (pw instanceof ClassicPlotWorld) {
y_offset_actual = y_offset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT;
} else { } else {
y_offset_actual = y_offset + MainUtil.getHeighestBlock(plot.getArea().worldname, region.minX + 1, region.minZ + 1); y_offset_actual = yOffset + MainUtil.getHeighestBlock(plot.getArea().worldname, region.minX + 1, region.minZ + 1);
} }
} }
} }
else { else {
y_offset_actual = y_offset; y_offset_actual = yOffset;
} }
final Location pos1 = new Location(plot.getArea().worldname, region.minX + x_offset, y_offset_actual, region.minZ + z_offset); Location pos1 = new Location(plot.getArea().worldname, region.minX + xOffset, y_offset_actual, region.minZ + zOffset);
final Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1); Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1);
// TODO switch to ChunkManager.chunkTask(pos1, pos2, task, whenDone, allocate); // TODO switch to ChunkManager.chunkTask(pos1, pos2, task, whenDone, allocate);
final int p1x = pos1.getX(); final int p1x = pos1.getX();
final int p1z = pos1.getZ(); final int p1z = pos1.getZ();
@ -217,9 +218,9 @@ public abstract class SchematicHandler {
int count = 0; int count = 0;
while (!chunks.isEmpty() && count < 256) { while (!chunks.isEmpty() && count < 256) {
count++; count++;
final ChunkLoc chunk = chunks.remove(0); ChunkLoc chunk = chunks.remove(0);
final int x = chunk.x; int x = chunk.x;
final int z = chunk.z; int z = chunk.z;
int xxb = x << 4; int xxb = x << 4;
int zzb = z << 4; int zzb = z << 4;
int xxt = xxb + 15; int xxt = xxb + 15;
@ -239,18 +240,18 @@ public abstract class SchematicHandler {
// Paste schematic here // Paste schematic here
for (int ry = 0; ry < Math.min(256, HEIGHT); ry++) { for (int ry = 0; ry < Math.min(256, HEIGHT); ry++) {
final int yy = y_offset_actual + ry; int yy = y_offset_actual + ry;
if (yy > 255) { if (yy > 255) {
continue; continue;
} }
final int i1 = ry * WIDTH * LENGTH; int i1 = ry * WIDTH * LENGTH;
for (int rz = zzb - p1z; rz <= (zzt - p1z); rz++) { for (int rz = zzb - p1z; rz <= (zzt - p1z); rz++) {
final int i2 = (rz * WIDTH) + i1; int i2 = (rz * WIDTH) + i1;
for (int rx = xxb - p1x; rx <= (xxt - p1x); rx++) { for (int rx = xxb - p1x; rx <= (xxt - p1x); rx++) {
final int i = i2 + rx; int i = i2 + rx;
final int xx = p1x + rx; int xx = p1x + rx;
final int zz = p1z + rz; int zz = p1z + rz;
int id = ids[i]; int id = ids[i];
@ -348,7 +349,7 @@ public abstract class SchematicHandler {
SetQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
pasteStates(schematic, plot, x_offset, z_offset); pasteStates(schematic, plot, xOffset, zOffset);
if (whenDone != null) { if (whenDone != null) {
whenDone.value = true; whenDone.value = true;
whenDone.run(); whenDone.run();
@ -358,7 +359,7 @@ public abstract class SchematicHandler {
} }
} }
}); });
} catch (final Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
} }
@ -366,38 +367,37 @@ public abstract class SchematicHandler {
}); });
} }
public boolean pasteStates(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) { public boolean pasteStates(Schematic schematic, Plot plot, int xOffset, int zOffset) {
if (schematic == null) { if (schematic == null) {
PS.debug("Schematic == null :|"); PS.debug("Schematic == null :|");
return false; return false;
} }
final HashSet<PlotItem> items = schematic.getItems(); HashSet<PlotItem> items = schematic.getItems();
if (items == null) { if (items == null) {
return false; return false;
} }
RegionWrapper region = plot.getLargestRegion(); RegionWrapper region = plot.getLargestRegion();
Location l1 = new Location(plot.getArea().worldname, region.minX + x_offset, 1, region.minZ + z_offset); Location location = new Location(plot.getArea().worldname, region.minX + xOffset, 1, region.minZ + zOffset);
// Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId()); int sy = MainUtil.getHeighestBlock(plot.getArea().worldname, location.getX() + 1, location.getZ() + 1);
final int sy = MainUtil.getHeighestBlock(plot.getArea().worldname, l1.getX() + 1, l1.getZ() + 1); Dimension demensions = schematic.getSchematicDimension();
final Dimension demensions = schematic.getSchematicDimension(); int height = demensions.getY();
final int HEIGHT = demensions.getY(); if (height < 255) {
if (HEIGHT < 255) { location = location.add(0, sy - 1, 0);
l1 = l1.add(0, sy - 1, 0);
} }
final int X = l1.getX() + x_offset; int x = location.getX() + xOffset;
final int Y = l1.getY(); int y = location.getY();
final int Z = l1.getZ() + z_offset; int z = location.getZ() + zOffset;
for (final PlotItem item : items) { for (PlotItem item : items) {
item.x += X; item.x += x;
item.y += Y; item.y += y;
item.z += Z; item.z += z;
WorldUtil.IMP.addItems(plot.getArea().worldname, item); WorldUtil.IMP.addItems(plot.getArea().worldname, item);
} }
return true; return true;
} }
public Schematic getSchematic(final CompoundTag tag) { public Schematic getSchematic(CompoundTag tag) {
final Map<String, Tag> tagMap = tag.getValue(); Map<String, Tag> tagMap = tag.getValue();
// Slow // Slow
// byte[] addId = new byte[0]; // byte[] addId = new byte[0];
// if (tagMap.containsKey("AddBlocks")) { // if (tagMap.containsKey("AddBlocks")) {
@ -405,19 +405,19 @@ public abstract class SchematicHandler {
// } // }
// end slow // end slow
final short width = ShortTag.class.cast(tagMap.get("Width")).getValue(); short width = ShortTag.class.cast(tagMap.get("Width")).getValue();
final short length = ShortTag.class.cast(tagMap.get("Length")).getValue(); short length = ShortTag.class.cast(tagMap.get("Length")).getValue();
final short height = ShortTag.class.cast(tagMap.get("Height")).getValue(); short height = ShortTag.class.cast(tagMap.get("Height")).getValue();
final byte[] block_sml = ByteArrayTag.class.cast(tagMap.get("Blocks")).getValue(); byte[] block_sml = ByteArrayTag.class.cast(tagMap.get("Blocks")).getValue();
final byte[] data = ByteArrayTag.class.cast(tagMap.get("Data")).getValue(); byte[] data = ByteArrayTag.class.cast(tagMap.get("Data")).getValue();
final Map<String, Tag> flags; Map<String, Tag> flags;
if (tagMap.containsKey("Flags")) { if (tagMap.containsKey("Flags")) {
flags = CompoundTag.class.cast(tagMap.get("Flags")).getValue(); flags = CompoundTag.class.cast(tagMap.get("Flags")).getValue();
} else { } else {
flags = null; flags = null;
} }
final short[] block = new short[block_sml.length]; short[] block = new short[block_sml.length];
for (int i = 0; i < block.length; i++) { for (int i = 0; i < block.length; i++) {
short id = block_sml[i]; short id = block_sml[i];
if (id < 0) { if (id < 0) {
@ -445,25 +445,25 @@ public abstract class SchematicHandler {
// } // }
// Schematic schem = new Schematic(collection, dimension, file); // Schematic schem = new Schematic(collection, dimension, file);
final Dimension dimensions = new Dimension(width, height, length); Dimension dimensions = new Dimension(width, height, length);
final Schematic schem = new Schematic(block, data, dimensions, flags); Schematic schem = new Schematic(block, data, dimensions, flags);
// Slow // Slow
try { try {
final List<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue(); List<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue();
for (final Tag stateTag : blockStates) { for (Tag stateTag : blockStates) {
try { try {
final CompoundTag ct = (CompoundTag) stateTag; CompoundTag ct = (CompoundTag) stateTag;
final Map<String, Tag> state = ct.getValue(); Map<String, Tag> state = ct.getValue();
final short x = IntTag.class.cast(state.get("x")).getValue().shortValue(); short x = IntTag.class.cast(state.get("x")).getValue().shortValue();
final short y = IntTag.class.cast(state.get("y")).getValue().shortValue(); short y = IntTag.class.cast(state.get("y")).getValue().shortValue();
final short z = IntTag.class.cast(state.get("z")).getValue().shortValue(); short z = IntTag.class.cast(state.get("z")).getValue().shortValue();
manager.restoreTag(ct, x, y, z, schem); manager.restoreTag(ct, x, y, z, schem);
} catch (final Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} catch (final Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return schem; return schem;
@ -478,14 +478,15 @@ public abstract class SchematicHandler {
* *
* @return schematic if found, else null * @return schematic if found, else null
*/ */
public Schematic getSchematic(final String name) { public Schematic getSchematic(String name) {
final File parent = MainUtil.getFile(PS.get().IMP.getDirectory(), Settings.SCHEMATIC_SAVE_PATH); File parent = MainUtil.getFile(PS.get().IMP.getDirectory(), Settings.SCHEMATIC_SAVE_PATH);
if (!parent.exists()) { if (!parent.exists()) {
if (!parent.mkdir()) { if (!parent.mkdir()) {
throw new RuntimeException("Could not create schematic parent directory"); throw new RuntimeException("Could not create schematic parent directory");
} }
} }
final File file = MainUtil.getFile(PS.get().IMP.getDirectory(), Settings.SCHEMATIC_SAVE_PATH + File.separator + name + (name.endsWith(".schematic") ? "" : ".schematic")); File file = MainUtil.getFile(PS.get().IMP.getDirectory(),
Settings.SCHEMATIC_SAVE_PATH + File.separator + name + (name.endsWith(".schematic") ? "" : ".schematic"));
return getSchematic(file); return getSchematic(file);
} }
@ -496,7 +497,7 @@ public abstract class SchematicHandler {
* *
* @return schematic if found, else null * @return schematic if found, else null
*/ */
public Schematic getSchematic(final File file) { public Schematic getSchematic(File file) {
if (!file.exists()) { if (!file.exists()) {
return null; return null;
} }
@ -508,10 +509,10 @@ public abstract class SchematicHandler {
return null; return null;
} }
public Schematic getSchematic(final URL url) { public Schematic getSchematic(URL url) {
try { try {
final ReadableByteChannel rbc = Channels.newChannel(url.openStream()); ReadableByteChannel rbc = Channels.newChannel(url.openStream());
final InputStream is = Channels.newInputStream(rbc); InputStream is = Channels.newInputStream(rbc);
return getSchematic(is); return getSchematic(is);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -519,13 +520,13 @@ public abstract class SchematicHandler {
return null; return null;
} }
public Schematic getSchematic(final InputStream is) { public Schematic getSchematic(InputStream is) {
if (is == null) { if (is == null) {
return null; return null;
} }
try { try {
final NBTInputStream stream = new NBTInputStream(new GZIPInputStream(is)); NBTInputStream stream = new NBTInputStream(new GZIPInputStream(is));
final CompoundTag tag = (CompoundTag) stream.readTag(1073741824); CompoundTag tag = (CompoundTag) stream.readTag(1073741824);
is.close(); is.close();
stream.close(); stream.close();
return getSchematic(tag); return getSchematic(tag);
@ -536,23 +537,23 @@ public abstract class SchematicHandler {
return null; return null;
} }
public List<String> getSaves(final UUID uuid) { public List<String> getSaves(UUID uuid) {
final StringBuilder rawJSON = new StringBuilder(); StringBuilder rawJSON = new StringBuilder();
try { try {
final String website = Settings.WEB_URL + "list.php?" + uuid.toString(); String website = Settings.WEB_URL + "list.php?" + uuid.toString();
final URL url = new URL(website); URL url = new URL(website);
final URLConnection connection = new URL(url.toString()).openConnection(); URLConnection connection = new URL(url.toString()).openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0"); connection.setRequestProperty("User-Agent", "Mozilla/5.0");
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
rawJSON.append(line); rawJSON.append(line);
} }
reader.close(); reader.close();
final JSONArray array = new JSONArray(rawJSON.toString()); JSONArray array = new JSONArray(rawJSON.toString());
final List<String> schematics = new ArrayList<>(); List<String> schematics = new ArrayList<>();
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
final String schematic = array.getString(i); String schematic = array.getString(i);
schematics.add(schematic); schematics.add(schematic);
} }
return Lists.reverse(schematics); return Lists.reverse(schematics);
@ -586,25 +587,25 @@ public abstract class SchematicHandler {
} }
/** /**
* Saves a schematic to a file path * Saves a schematic to a file path.
* *
* @param tag to save * @param tag to save
* @param path to save in * @param path to save in
* *
* @return true if succeeded * @return true if succeeded
*/ */
public boolean save(final CompoundTag tag, final String path) { public boolean save(CompoundTag tag, String path) {
if (tag == null) { if (tag == null) {
PS.debug("&cCannot save empty tag"); PS.debug("&cCannot save empty tag");
return false; return false;
} }
try { try {
final File tmp = MainUtil.getFile(PS.get().IMP.getDirectory(), path); File tmp = MainUtil.getFile(PS.get().IMP.getDirectory(), path);
tmp.getParentFile().mkdirs(); tmp.getParentFile().mkdirs();
try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream))) { try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream))) {
output.writeTag(tag); output.writeTag(tag);
} }
} catch (final IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
@ -616,14 +617,14 @@ public abstract class SchematicHandler {
* - Untested * - Untested
* @param blocks * @param blocks
* @param blockdata * @param blockdata
* @param d * @param dimension
* @return * @return
*/ */
public CompoundTag createTag(final byte[] blocks, final byte[] blockdata, final Dimension d) { public CompoundTag createTag(byte[] blocks, byte[] blockdata, Dimension dimension) {
final HashMap<String, Tag> schematic = new HashMap<>(); HashMap<String, Tag> schematic = new HashMap<>();
schematic.put("Width", new ShortTag("Width", (short) d.getX())); schematic.put("Width", new ShortTag("Width", (short) dimension.getX()));
schematic.put("Length", new ShortTag("Length", (short) d.getZ())); schematic.put("Length", new ShortTag("Length", (short) dimension.getZ()));
schematic.put("Height", new ShortTag("Height", (short) d.getY())); schematic.put("Height", new ShortTag("Height", (short) dimension.getY()));
schematic.put("Materials", new StringTag("Materials", "Alpha")); schematic.put("Materials", new StringTag("Materials", "Alpha"));
schematic.put("WEOriginX", new IntTag("WEOriginX", 0)); schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
schematic.put("WEOriginY", new IntTag("WEOriginY", 0)); schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
@ -638,7 +639,7 @@ public abstract class SchematicHandler {
return new CompoundTag("Schematic", schematic); return new CompoundTag("Schematic", schematic);
} }
public abstract void getCompoundTag(final String world, Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone); public abstract void getCompoundTag(String world, Set<RegionWrapper> regions, RunnableVal<CompoundTag> whenDone);
public void getCompoundTag(final Plot plot, final RunnableVal<CompoundTag> whenDone) { public void getCompoundTag(final Plot plot, final RunnableVal<CompoundTag> whenDone) {
getCompoundTag(plot.getArea().worldname, plot.getRegions(), new RunnableVal<CompoundTag>() { getCompoundTag(plot.getArea().worldname, plot.getRegions(), new RunnableVal<CompoundTag>() {
@ -661,9 +662,7 @@ public abstract class SchematicHandler {
} }
/** /**
* Schematic Dimensions * Schematic Dimensions.
*
*/ */
public static class Dimension { public static class Dimension {
@ -671,22 +670,22 @@ public abstract class SchematicHandler {
private final int y; private final int y;
private final int z; private final int z;
public Dimension(final int x, final int y, final int z) { public Dimension(int x, int y, int z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
public int getX() { public int getX() {
return x; return this.x;
} }
public int getY() { public int getY() {
return y; return this.y;
} }
public int getZ() { public int getZ() {
return z; return this.z;
} }
} }
@ -703,15 +702,15 @@ public abstract class SchematicHandler {
private Map<String, Tag> flags; private Map<String, Tag> flags;
private HashSet<PlotItem> items; private HashSet<PlotItem> items;
public Schematic(final short[] i, final byte[] b, final Dimension d, Map<String, Tag> flags) { public Schematic(short[] i, byte[] b, Dimension d, Map<String, Tag> flags) {
ids = i; this.ids = i;
datas = b; this.datas = b;
schematicDimension = d; this.schematicDimension = d;
setFlags(flags); setFlags(flags);
} }
public Map<String, Tag> getFlags() { public Map<String, Tag> getFlags() {
return flags; return this.flags;
} }
public void setFlags(Map<String, Tag> flags) { public void setFlags(Map<String, Tag> flags) {
@ -722,43 +721,43 @@ public abstract class SchematicHandler {
* Add an item to the schematic * Add an item to the schematic
* @param item * @param item
*/ */
public void addItem(final PlotItem item) { public void addItem(PlotItem item) {
if (items == null) { if (this.items == null) {
items = new HashSet<>(); this.items = new HashSet<>();
} }
items.add(item); this.items.add(item);
} }
/** /**
* Get any items associated with this schematic * Get any items associated with this schematic.
* @return * @return
*/ */
public HashSet<PlotItem> getItems() { public HashSet<PlotItem> getItems() {
return items; return this.items;
} }
/** /**
* Get the schematic dimensions * Get the schematic dimensions.
* @return * @return
*/ */
public Dimension getSchematicDimension() { public Dimension getSchematicDimension() {
return schematicDimension; return this.schematicDimension;
} }
/** /**
* Get the block type array * Get the block type array.
* @return * @return
*/ */
public short[] getIds() { public short[] getIds() {
return ids; return this.ids;
} }
/** /**
* Get the block data array * Get the block data array.
* @return * @return
*/ */
public byte[] getDatas() { public byte[] getDatas() {
return datas; return this.datas;
} }
public Schematic copySection(RegionWrapper region) { public Schematic copySection(RegionWrapper region) {
@ -779,9 +778,9 @@ public abstract class SchematicHandler {
short[] ids2 = new short[width * length * height]; short[] ids2 = new short[width * length * height];
byte[] datas2 = new byte[width * length * height]; byte[] datas2 = new byte[width * length * height];
int dx = schematicDimension.getX(); int dx = this.schematicDimension.getX();
int dy = schematicDimension.getY(); int dy = this.schematicDimension.getY();
int dz = schematicDimension.getZ(); int dz = this.schematicDimension.getZ();
for (int y = y1; y <= y2; y++) { for (int y = y1; y <= y2; y++) {
int yy = y >= 0 ? y < dy ? y : y - dy : y + dy; int yy = y >= 0 ? y < dy ? y : y - dy : y + dy;
@ -795,20 +794,20 @@ public abstract class SchematicHandler {
int xx = x >= 0 ? x < dx ? x : x - dx : x + dx; int xx = x >= 0 ? x < dx ? x : x - dx : x + dx;
int i3 = i2 + xx; int i3 = i2 + xx;
int j3 = j2 + (x - x1); int j3 = j2 + (x - x1);
ids2[j3] = ids[i3]; ids2[j3] = this.ids[i3];
datas2[j3] = datas[i3]; datas2[j3] = this.datas[i3];
} }
} }
} }
return new Schematic(ids2, datas2, new Dimension(width, height, length), null); return new Schematic(ids2, datas2, new Dimension(width, height, length), null);
} }
public void save(final File file) { public void save(File file) {
byte[] ids2 = new byte[ids.length]; byte[] ids2 = new byte[this.ids.length];
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < this.ids.length; i++) {
ids2[i] = (byte) ids[i]; ids2[i] = (byte) this.ids[i];
} }
CompoundTag tag = createTag(ids2, datas, schematicDimension); CompoundTag tag = createTag(ids2, this.datas, this.schematicDimension);
SchematicHandler.this.save(tag, file.getAbsolutePath()); SchematicHandler.this.save(tag, file.getAbsolutePath());
} }
} }

View File

@ -19,42 +19,43 @@ public class SetQueue {
TaskManager.runTaskRepeat(new Runnable() { TaskManager.runTaskRepeat(new Runnable() {
@Override @Override
public void run() { public void run() {
long free = 50 + Math.min(50 + last - (last = System.currentTimeMillis()), last2 - System.currentTimeMillis()); long free = 50 + Math.min(50 + SetQueue.this.last - (SetQueue.this.last = System.currentTimeMillis()),
time_current.incrementAndGet(); SetQueue.this.last2 - System.currentTimeMillis());
SetQueue.this.time_current.incrementAndGet();
do { do {
if (isWaiting()) { if (isWaiting()) {
return; return;
} }
final PlotChunk<?> current = queue.next(); PlotChunk<?> current = SetQueue.this.queue.next();
if (current == null) { if (current == null) {
time_waiting.set(Math.max(time_waiting.get(), time_current.get() - 2)); SetQueue.this.time_waiting.set(Math.max(SetQueue.this.time_waiting.get(), SetQueue.this.time_current.get() - 2));
tasks(); tasks();
return; return;
} }
} while ((last2 = System.currentTimeMillis()) - last < free); } while ((SetQueue.this.last2 = System.currentTimeMillis()) - SetQueue.this.last < free);
time_waiting.set(time_current.get() - 1); SetQueue.this.time_waiting.set(SetQueue.this.time_current.get() - 1);
} }
}, 1); }, 1);
} }
public boolean forceChunkSet() { public boolean forceChunkSet() {
final PlotChunk<?> set = queue.next(); PlotChunk<?> set = this.queue.next();
return set != null; return set != null;
} }
public boolean isWaiting() { public boolean isWaiting() {
return time_waiting.get() >= time_current.get(); return this.time_waiting.get() >= this.time_current.get();
} }
public boolean isDone() { public boolean isDone() {
return (time_waiting.get() + 1) < time_current.get(); return (this.time_waiting.get() + 1) < this.time_current.get();
} }
public void setWaiting() { public void setWaiting() {
time_waiting.set(time_current.get() + 1); this.time_waiting.set(this.time_current.get() + 1);
} }
public boolean addTask(final Runnable whenDone) { public boolean addTask(Runnable whenDone) {
if (isDone()) { if (isDone()) {
// Run // Run
tasks(); tasks();
@ -64,18 +65,18 @@ public class SetQueue {
return true; return true;
} }
if (whenDone != null) { if (whenDone != null) {
runnables.add(whenDone); this.runnables.add(whenDone);
} }
return false; return false;
} }
public boolean tasks() { public boolean tasks() {
if (runnables.isEmpty()) { if (this.runnables.isEmpty()) {
return false; return false;
} }
final ArrayDeque<Runnable> tmp = runnables.clone(); ArrayDeque<Runnable> tmp = this.runnables.clone();
runnables.clear(); this.runnables.clear();
for (final Runnable runnable : tmp) { for (Runnable runnable : tmp) {
runnable.run(); runnable.run();
} }
return true; return true;
@ -90,12 +91,12 @@ public class SetQueue {
* @param data * @param data
* @return * @return
*/ */
public boolean setBlock(final String world, final int x, final int y, final int z, final short id, final byte data) { public boolean setBlock(String world, int x, int y, int z, short id, byte data) {
if ((y > 255) || (y < 0)) { if ((y > 255) || (y < 0)) {
return false; return false;
} }
SetQueue.IMP.setWaiting(); SetQueue.IMP.setWaiting();
return queue.setBlock(world, x, y, z, id, data); return this.queue.setBlock(world, x, y, z, id, data);
} }
/** /**
@ -107,53 +108,54 @@ public class SetQueue {
* @param block * @param block
* @return * @return
*/ */
public boolean setBlock(final String world, final int x, final int y, final int z, PlotBlock block) { public boolean setBlock(String world, int x, int y, int z, PlotBlock block) {
if ((y > 255) || (y < 0)) { if ((y > 255) || (y < 0)) {
return false; return false;
} }
SetQueue.IMP.setWaiting(); SetQueue.IMP.setWaiting();
return queue.setBlock(world, x, y, z, block.id, block.data); return this.queue.setBlock(world, x, y, z, block.id, block.data);
} }
/** /**
* @param world * @param world The world
* @param x * @param x The x coordinate
* @param y * @param y The y coordinate
* @param z * @param z The z coordinate
* @param id * @param id
* @return * @return
*/ */
public boolean setBlock(final String world, final int x, final int y, final int z, final short id) { public boolean setBlock(String world, int x, int y, int z, short id) {
if ((y > 255) || (y < 0)) { if ((y > 255) || (y < 0)) {
return false; return false;
} }
SetQueue.IMP.setWaiting(); SetQueue.IMP.setWaiting();
return queue.setBlock(world, x, y, z, id, (byte) 0); return this.queue.setBlock(world, x, y, z, id, (byte) 0);
} }
/** /**
* *
* @param world * @param world The world
* @param x * @param x The x coordinate
* @param y * @param y The y coordinate
* @param z * @param z The z coordinate
* @param id * @param id
* @return * @return
*/ */
public boolean setBlock(final String world, final int x, final int y, final int z, final int id) { public boolean setBlock(String world, int x, int y, int z, int id) {
if ((y > 255) || (y < 0)) { if (y > 255 || y < 0) {
return false; return false;
} }
SetQueue.IMP.setWaiting(); SetQueue.IMP.setWaiting();
return queue.setBlock(world, x, y, z, (short) id, (byte) 0); return this.queue.setBlock(world, x, y, z, (short) id, (byte) 0);
} }
public class ChunkWrapper { public class ChunkWrapper {
public final int x; public final int x;
public final int z; public final int z;
public final String world; public final String world;
public ChunkWrapper(final String world, final int x, final int z) { public ChunkWrapper(String world, int x, int z) {
this.world = world; this.world = world;
this.x = x; this.x = x;
this.z = z; this.z = z;
@ -161,11 +163,11 @@ public class SetQueue {
@Override @Override
public int hashCode() { public int hashCode() {
return (x << 16) | (z & 0xFFFF); return (this.x << 16) | (this.z & 0xFFFF);
} }
@Override @Override
public boolean equals(final Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@ -178,13 +180,13 @@ public class SetQueue {
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
return false; return false;
} }
final ChunkWrapper other = (ChunkWrapper) obj; ChunkWrapper other = (ChunkWrapper) obj;
return (x == other.x) && (z == other.z) && StringMan.isEqual(world, other.world); return (this.x == other.x) && (this.z == other.z) && StringMan.isEqual(this.world, other.world);
} }
@Override @Override
public String toString() { public String toString() {
return world + ":" + x + "," + z; return this.world + ":" + this.x + "," + this.z;
} }
} }
} }

View File

@ -1,101 +1,88 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.RunnableVal;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.RunnableVal;
public abstract class TaskManager { public abstract class TaskManager {
public static HashSet<String> TELEPORT_QUEUE = new HashSet<>(); public static HashSet<String> TELEPORT_QUEUE = new HashSet<>();
public static AtomicInteger index = new AtomicInteger(0); public static AtomicInteger index = new AtomicInteger(0);
public static HashMap<Integer, Integer> tasks = new HashMap<>(); public static HashMap<Integer, Integer> tasks = new HashMap<>();
public static int runTaskRepeat(final Runnable r, final int interval) { public static int runTaskRepeat(Runnable runnable, int interval) {
if (r != null) { if (runnable != null) {
if (PS.get().TASK == null) { if (PS.get().TASK == null) {
throw new IllegalArgumentException("disabled"); throw new IllegalArgumentException("disabled");
} }
return PS.get().TASK.taskRepeat(r, interval); return PS.get().TASK.taskRepeat(runnable, interval);
} }
return -1; return -1;
} }
public static int runTaskRepeatAsync(final Runnable r, final int interval) { public static int runTaskRepeatAsync(Runnable runnable, int interval) {
if (r != null) { if (runnable != null) {
if (PS.get().TASK == null) { if (PS.get().TASK == null) {
throw new IllegalArgumentException("disabled"); throw new IllegalArgumentException("disabled");
} }
return PS.get().TASK.taskRepeat(r, interval); return PS.get().TASK.taskRepeat(runnable, interval);
} }
return -1; return -1;
} }
public static void runTaskAsync(final Runnable r) { public static void runTaskAsync(Runnable runnable) {
if (r != null) { if (runnable != null) {
if (PS.get().TASK == null) { if (PS.get().TASK == null) {
r.run(); runnable.run();
return; return;
} }
PS.get().TASK.taskAsync(r); PS.get().TASK.taskAsync(runnable);
} }
} }
public static void runTask(final Runnable r) { public static void runTask(Runnable runnable) {
if (r != null) { if (runnable != null) {
if (PS.get().TASK == null) { if (PS.get().TASK == null) {
r.run(); runnable.run();
return; return;
} }
PS.get().TASK.task(r); PS.get().TASK.task(runnable);
} }
} }
/** /**
* Run task later (delay in ticks) * Run task later.
* @param r * @param runnable The task
* @param delay * @param delay The delay in ticks
*/ */
public static void runTaskLater(final Runnable r, final int delay) { public static void runTaskLater(Runnable runnable, int delay) {
if (r != null) { if (runnable != null) {
if (PS.get().TASK == null) { if (PS.get().TASK == null) {
r.run(); runnable.run();
return; return;
} }
PS.get().TASK.taskLater(r, delay); PS.get().TASK.taskLater(runnable, delay);
} }
} }
public static void runTaskLaterAsync(final Runnable r, final int delay) { public static void runTaskLaterAsync(Runnable runnable, int delay) {
if (r != null) { if (runnable != null) {
if (PS.get().TASK == null) { if (PS.get().TASK == null) {
r.run(); runnable.run();
return; return;
} }
PS.get().TASK.taskLaterAsync(r, delay); PS.get().TASK.taskLaterAsync(runnable, delay);
} }
} }
public abstract int taskRepeat(final Runnable r, final int interval);
public abstract int taskRepeatAsync(final Runnable r, final int interval);
public abstract void taskAsync(final Runnable r);
public abstract void task(final Runnable r);
public abstract void taskLater(final Runnable r, final int delay);
public abstract void taskLaterAsync(final Runnable r, final int delay);
public abstract void cancelTask(final int task);
/** /**
* Break up a series of tasks so that they can run without lagging the server * Break up a series of tasks so that they can run without lagging the server.
* @param objects * @param objects
* @param task * @param task
* @param whenDone * @param whenDone
@ -119,4 +106,18 @@ public abstract class TaskManager {
} }
}); });
} }
public abstract int taskRepeat(Runnable runnable, int interval);
public abstract int taskRepeatAsync(Runnable runnable, int interval);
public abstract void taskAsync(Runnable runnable);
public abstract void task(Runnable runnable);
public abstract void taskLater(Runnable runnable, int delay);
public abstract void taskLaterAsync(Runnable runnable, int delay);
public abstract void cancelTask(int task);
} }

View File

@ -1,12 +1,11 @@
package com.plotsquared.sponge.util; package com.plotsquared.sponge.util;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.spongepowered.api.scheduler.Task;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.SpongeMain;
import org.spongepowered.api.scheduler.Task;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
public class SpongeTaskManager extends TaskManager { public class SpongeTaskManager extends TaskManager {
@ -15,52 +14,52 @@ public class SpongeTaskManager extends TaskManager {
private final HashMap<Integer, Task> tasks = new HashMap<>(); private final HashMap<Integer, Task> tasks = new HashMap<>();
@Override @Override
public int taskRepeat(final Runnable r, final int interval) { public int taskRepeat(Runnable runnable, int interval) {
final int val = i.incrementAndGet(); int val = this.i.incrementAndGet();
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
final Task.Builder built = builder.delayTicks(interval).intervalTicks(interval).execute(r); Task.Builder built = builder.delayTicks(interval).intervalTicks(interval).execute(runnable);
final Task task = built.submit(SpongeMain.THIS.getPlugin()); Task task = built.submit(SpongeMain.THIS.getPlugin());
tasks.put(val, task); this.tasks.put(val, task);
return val; return val;
} }
@Override @Override
public int taskRepeatAsync(final Runnable r, final int interval) { public int taskRepeatAsync(Runnable runnable, int interval) {
final int val = i.incrementAndGet(); int val = this.i.incrementAndGet();
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
final Task.Builder built = builder.delayTicks(interval).async().intervalTicks(interval).execute(r); Task.Builder built = builder.delayTicks(interval).async().intervalTicks(interval).execute(runnable);
final Task task = built.submit(SpongeMain.THIS.getPlugin()); Task task = built.submit(SpongeMain.THIS.getPlugin());
tasks.put(val, task); this.tasks.put(val, task);
return val; return val;
} }
@Override @Override
public void taskAsync(final Runnable r) { public void taskAsync(Runnable runnable) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.async().execute(r).submit(SpongeMain.THIS.getPlugin()); builder.async().execute(runnable).submit(SpongeMain.THIS.getPlugin());
} }
@Override @Override
public void task(final Runnable r) { public void task(Runnable runnable) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.execute(r).submit(SpongeMain.THIS.getPlugin()); builder.execute(runnable).submit(SpongeMain.THIS.getPlugin());
} }
@Override @Override
public void taskLater(final Runnable r, final int delay) { public void taskLater(Runnable runnable, int delay) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin()); builder.delayTicks(delay).execute(runnable).submit(SpongeMain.THIS.getPlugin());
} }
@Override @Override
public void taskLaterAsync(final Runnable r, final int delay) { public void taskLaterAsync(Runnable runnable, int delay) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.async().delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin()); builder.async().delayTicks(delay).execute(runnable).submit(SpongeMain.THIS.getPlugin());
} }
@Override @Override
public void cancelTask(final int i) { public void cancelTask(int i) {
final Task task = tasks.remove(i); Task task = this.tasks.remove(i);
if (task != null) { if (task != null) {
task.cancel(); task.cancel();
} }