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 {
@Override
public int taskRepeat(Runnable r, int interval) {
return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
public int taskRepeat(Runnable runnable, int interval) {
return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval);
}
@SuppressWarnings("deprecation")
@Override
public int taskRepeatAsync(Runnable r, int interval) {
return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
public int taskRepeatAsync(Runnable runnable, int interval) {
return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval);
}
@Override
public void taskAsync(Runnable r) {
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r).getTaskId();
public void taskAsync(Runnable runnable) {
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, runnable).getTaskId();
}
@Override
public void task(Runnable r) {
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r).getTaskId();
public void task(Runnable runnable) {
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, runnable).getTaskId();
}
@Override
public void taskLater(Runnable r, int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, r, delay).getTaskId();
public void taskLater(Runnable runnable, int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, runnable, delay).getTaskId();
}
@Override
public void taskLaterAsync(Runnable r, int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, r, delay);
public void taskLaterAsync(Runnable runnable, int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, runnable, delay);
}
@Override

View File

@ -1,34 +1,35 @@
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.serialization.ConfigurationSerializable;
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 YamlRepresenter() {
multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
}
private class RepresentConfigurationSection extends RepresentMap {
@Override
public Node representData(final Object data) {
public Node representData(Object data) {
return super.representData(((ConfigurationSection) data).getValues(false));
}
}
private class RepresentConfigurationSerializable extends RepresentMap {
@Override
public Node representData(final Object data) {
final ConfigurationSerializable serializable = (ConfigurationSerializable) data;
final Map<String, Object> values = new LinkedHashMap<>();
public Node representData(Object data) {
ConfigurationSerializable serializable = (ConfigurationSerializable) data;
Map<String, Object> values = new LinkedHashMap<>();
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
values.putAll(serializable.serialize());

View File

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

View File

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

View File

@ -70,14 +70,16 @@ public class Inbox extends SubCommand {
// This might work xD
for (int x = page * 12; x < max; x++) {
PlotComment c = comments[x];
PlotComment comment = comments[x];
String color;
if (player.getName().equals(c.senderName)) {
if (player.getName().equals(comment.senderName)) {
color = "&a";
} else {
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());
}

View File

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

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.InvalidConfigurationException;
import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
@ -158,7 +159,7 @@ public class Template extends SubCommand {
try {
PS.get().config.save(PS.get().configFile);
PS.get().config.load(PS.get().configFile);
} catch (Exception e) {
} catch (InvalidConfigurationException | IOException e) {
e.printStackTrace();
}
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>
* @param world
* Runs the result task with the parameters (viable, nonViable).
* @param world The world
* @param result (viable = .mcr to trim, nonViable = .mcr keep)
* @return
*/

View File

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

View File

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

View File

@ -44,7 +44,7 @@ import java.util.UUID;
description = "Visit someones plot",
usage = "/plot visit [player|alias|world|id] [#]",
aliases = {"v", "tp", "teleport", "goto", "home", "h"},
requiredType = RequiredType.NONE,
requiredType = RequiredType.PLAYER,
category = CommandCategory.TELEPORT)
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
*/
public static abstract class SettingValue<T> {
public abstract static class SettingValue<T> {
private final String type;

View File

@ -20,81 +20,81 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
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.object.PlotBlock;
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 {
private final String constant;
private final Object default_value;
private final Object defaultValue;
private final String description;
private final SettingValue type;
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.default_value = default_value;
this.defaultValue = defaultValue;
this.description = description;
value = default_value;
this.value = defaultValue;
this.type = type;
}
public SettingValue getType() {
return type;
return this.type;
}
public boolean isValid(final String string) {
public boolean isValid(String string) {
try {
final Object result = type.parseString(string);
Object result = this.type.parseString(string);
return result != null;
} catch (final Exception e) {
} catch (Exception e) {
return false;
}
}
public boolean setValue(final String string) {
if (!type.validateValue(string)) {
public boolean setValue(String string) {
if (!this.type.validateValue(string)) {
return false;
}
value = type.parseString(string);
this.value = this.type.parseString(string);
return true;
}
public Object getValue() {
if (value instanceof String[]) {
return Arrays.asList((String[]) value);
} else if (value instanceof Object[]) {
final List<String> values = new ArrayList<String>();
for (final Object value : (Object[]) this.value) {
if (this.value instanceof String[]) {
return Arrays.asList((String[]) this.value);
} else if (this.value instanceof Object[]) {
List<String> values = new ArrayList<String>();
for (Object value : (Object[]) this.value) {
values.add(value.toString());
}
return values;
} else if (value instanceof PlotBlock) {
return value.toString();
} else if (this.value instanceof PlotBlock) {
return this.value.toString();
}
return value;
return this.value;
}
public String getConstant() {
return constant;
return this.constant;
}
public Object getDefaultValue() {
if (default_value instanceof Object[]) {
return StringMan.join((Object[]) default_value, ",");
if (this.defaultValue instanceof Object[]) {
return StringMan.join((Object[]) this.defaultValue, ",");
}
return default_value;
return this.defaultValue;
}
public String getDescription() {
return description;
return this.description;
}
}

View File

@ -44,7 +44,7 @@ import java.util.UUID;
*/
public class DBFunc {
/**
* The "global" uuid
* The "global" uuid.
*/
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
public boolean createRoadEast(PlotArea plotworld, Plot plot) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId());
Location pos2 = getPlotTopLocAbs(plotworld, plot.getId());
public boolean createRoadEast(PlotArea plotArea, Plot plot) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
Location pos1 = getPlotBottomLocAbs(plotArea, plot.getId());
Location pos2 = getPlotTopLocAbs(plotArea, plot.getId());
int sx = pos2.getX() + 1;
int ex = sx + dpw.ROAD_WIDTH - 1;
int sz = pos1.getZ() - 2;
int ez = pos2.getZ() + 2;
MainUtil.setSimpleCuboidAsync(plotworld.worldname,
new Location(plotworld.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));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 0, sz + 1),
new Location(plotworld.worldname, ex, 0, ez - 1), new PlotBlock((short) 7,
MainUtil.setSimpleCuboidAsync(plotArea.worldname,
new Location(plotArea.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1),
new Location(plotArea.worldname, ex, 255, ez - 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx, 0, sz + 1),
new Location(plotArea.worldname, ex, 0, ez - 1), new PlotBlock((short) 7,
(byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1),
new Location(plotworld.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),
new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, ez - 1),
MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx, 1, sz + 1),
new Location(plotArea.worldname, sx, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1),
new Location(plotArea.worldname, sx, dpw.WALL_HEIGHT + 1, ez - 1),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, 1, sz + 1),
new Location(plotworld.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),
new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, ez - 1),
MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, ex, 1, sz + 1),
new Location(plotArea.worldname, ex, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1),
new Location(plotArea.worldname, ex, dpw.WALL_HEIGHT + 1, ez - 1),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1),
new Location(plotworld.worldname, ex - 1, dpw.ROAD_HEIGHT, ez - 1), dpw.ROAD_BLOCK);
MainUtil.setSimpleCuboidAsync(plotArea.worldname, new Location(plotArea.worldname, sx + 1, 1, sz + 1),
new Location(plotArea.worldname, ex - 1, dpw.ROAD_HEIGHT, ez - 1), dpw.ROAD_BLOCK);
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
public boolean finishPlotMerge(PlotArea plotworld, ArrayList<PlotId> plotIds) {

View File

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

View File

@ -47,8 +47,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public HashMap<Integer, HashMap<Integer, PlotBlock>> G_SCH;
public HashMap<Integer, HashSet<PlotItem>> G_SCH_STATE;
public HybridPlotWorld(String worldname, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
super(worldname, id, generator, min, max);
public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
super(worldName, id, generator, min, max);
}
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;
public abstract class PlotGenerator<T> {
public 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
public Location getPlotBottomLocAbs(PlotArea plotworld, PlotId plotid) {
SquarePlotWorld dpw = (SquarePlotWorld) plotworld;
int px = plotid.x;
int pz = plotid.y;
public Location getPlotBottomLocAbs(PlotArea plotArea, PlotId plotId) {
SquarePlotWorld dpw = (SquarePlotWorld) plotArea;
int px = plotId.x;
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 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
*/
public String getLeaveMessage(PlotArea area) {
Flag farewell = FlagManager.getSettingFlag(area, this, "farewell");
public String getLeaveMessage(PlotArea plotArea) {
Flag farewell = FlagManager.getSettingFlag(plotArea, this, "farewell");
if (farewell != null) {
return farewell.getValueString();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,8 +22,6 @@ package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.object.PlotId;
/**
*/
public class PlotComment {
public final String comment;
public final String inbox;
@ -32,7 +30,7 @@ public class PlotComment {
public final String world;
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.id = id;
this.comment = comment;

View File

@ -8,7 +8,7 @@ public class PlotItem {
public byte[] data;
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.y = y;
this.z = z;

View File

@ -21,10 +21,7 @@ public class CommentManager {
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
public static void sendTitle(final PlotPlayer player, final Plot plot) {
if (!Settings.COMMENT_NOTIFICATIONS) {
return;
}
if (!plot.isOwner(player.getUUID())) {
if (!Settings.COMMENT_NOTIFICATIONS || !plot.isOwner(player.getUUID())) {
return;
}
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
* @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()
* @param world
* @param regions
@ -514,7 +514,7 @@ public class MainUtil {
}
/**
* Resend the chunk at a location
* Resend the chunk at a location.
* @param world
* @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 pos1
* @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
*
* @return true Can be used in things such as commands (return PlayerFunctions.sendMessage(...))
*/
public static boolean sendMessage(PlotPlayer plr, String msg) {
return sendMessage(plr, msg, true);
public static boolean sendMessage(PlotPlayer player, String msg) {
return sendMessage(player, msg, true);
}
/**
* Send a message to console
* Send a message to console.
* @param caption
* @param args
*/
@ -621,17 +621,17 @@ public class MainUtil {
/**
* 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 prefix If the message should be prefixed with the configured prefix
* @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 (plr == null) {
if (player == null) {
ConsolePlayer.getConsole().sendMessage((prefix ? C.PREFIX.s() : "") + msg);
} else {
plr.sendMessage((prefix ? C.PREFIX.s() : "") + C.color(msg));
player.sendMessage((prefix ? C.PREFIX.s() : "") + C.color(msg));
}
}
return true;

View File

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

View File

@ -19,42 +19,43 @@ public class SetQueue {
TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
long free = 50 + Math.min(50 + last - (last = System.currentTimeMillis()), last2 - System.currentTimeMillis());
time_current.incrementAndGet();
long free = 50 + Math.min(50 + SetQueue.this.last - (SetQueue.this.last = System.currentTimeMillis()),
SetQueue.this.last2 - System.currentTimeMillis());
SetQueue.this.time_current.incrementAndGet();
do {
if (isWaiting()) {
return;
}
final PlotChunk<?> current = queue.next();
PlotChunk<?> current = SetQueue.this.queue.next();
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();
return;
}
} while ((last2 = System.currentTimeMillis()) - last < free);
time_waiting.set(time_current.get() - 1);
} while ((SetQueue.this.last2 = System.currentTimeMillis()) - SetQueue.this.last < free);
SetQueue.this.time_waiting.set(SetQueue.this.time_current.get() - 1);
}
}, 1);
}
public boolean forceChunkSet() {
final PlotChunk<?> set = queue.next();
PlotChunk<?> set = this.queue.next();
return set != null;
}
public boolean isWaiting() {
return time_waiting.get() >= time_current.get();
return this.time_waiting.get() >= this.time_current.get();
}
public boolean isDone() {
return (time_waiting.get() + 1) < time_current.get();
return (this.time_waiting.get() + 1) < this.time_current.get();
}
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()) {
// Run
tasks();
@ -64,18 +65,18 @@ public class SetQueue {
return true;
}
if (whenDone != null) {
runnables.add(whenDone);
this.runnables.add(whenDone);
}
return false;
}
public boolean tasks() {
if (runnables.isEmpty()) {
if (this.runnables.isEmpty()) {
return false;
}
final ArrayDeque<Runnable> tmp = runnables.clone();
runnables.clear();
for (final Runnable runnable : tmp) {
ArrayDeque<Runnable> tmp = this.runnables.clone();
this.runnables.clear();
for (Runnable runnable : tmp) {
runnable.run();
}
return true;
@ -90,12 +91,12 @@ public class SetQueue {
* @param data
* @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)) {
return false;
}
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
* @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)) {
return false;
}
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 x
* @param y
* @param z
* @param world The world
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
* @param id
* @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)) {
return false;
}
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 x
* @param y
* @param z
* @param world The world
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
* @param id
* @return
*/
public boolean setBlock(final String world, final int x, final int y, final int z, final int id) {
if ((y > 255) || (y < 0)) {
public boolean setBlock(String world, int x, int y, int z, int id) {
if (y > 255 || y < 0) {
return false;
}
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 final int x;
public final int z;
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.x = x;
this.z = z;
@ -161,11 +163,11 @@ public class SetQueue {
@Override
public int hashCode() {
return (x << 16) | (z & 0xFFFF);
return (this.x << 16) | (this.z & 0xFFFF);
}
@Override
public boolean equals(final Object obj) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
@ -178,13 +180,13 @@ public class SetQueue {
if (getClass() != obj.getClass()) {
return false;
}
final ChunkWrapper other = (ChunkWrapper) obj;
return (x == other.x) && (z == other.z) && StringMan.isEqual(world, other.world);
ChunkWrapper other = (ChunkWrapper) obj;
return (this.x == other.x) && (this.z == other.z) && StringMan.isEqual(this.world, other.world);
}
@Override
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;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.RunnableVal;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.RunnableVal;
public abstract class TaskManager {
public static HashSet<String> TELEPORT_QUEUE = new HashSet<>();
public static AtomicInteger index = new AtomicInteger(0);
public static HashMap<Integer, Integer> tasks = new HashMap<>();
public static int runTaskRepeat(final Runnable r, final int interval) {
if (r != null) {
public static int runTaskRepeat(Runnable runnable, int interval) {
if (runnable != null) {
if (PS.get().TASK == null) {
throw new IllegalArgumentException("disabled");
}
return PS.get().TASK.taskRepeat(r, interval);
return PS.get().TASK.taskRepeat(runnable, interval);
}
return -1;
}
public static int runTaskRepeatAsync(final Runnable r, final int interval) {
if (r != null) {
public static int runTaskRepeatAsync(Runnable runnable, int interval) {
if (runnable != null) {
if (PS.get().TASK == null) {
throw new IllegalArgumentException("disabled");
}
return PS.get().TASK.taskRepeat(r, interval);
return PS.get().TASK.taskRepeat(runnable, interval);
}
return -1;
}
public static void runTaskAsync(final Runnable r) {
if (r != null) {
public static void runTaskAsync(Runnable runnable) {
if (runnable != null) {
if (PS.get().TASK == null) {
r.run();
runnable.run();
return;
}
PS.get().TASK.taskAsync(r);
PS.get().TASK.taskAsync(runnable);
}
}
public static void runTask(final Runnable r) {
if (r != null) {
public static void runTask(Runnable runnable) {
if (runnable != null) {
if (PS.get().TASK == null) {
r.run();
runnable.run();
return;
}
PS.get().TASK.task(r);
PS.get().TASK.task(runnable);
}
}
/**
* Run task later (delay in ticks)
* @param r
* @param delay
* Run task later.
* @param runnable The task
* @param delay The delay in ticks
*/
public static void runTaskLater(final Runnable r, final int delay) {
if (r != null) {
public static void runTaskLater(Runnable runnable, int delay) {
if (runnable != null) {
if (PS.get().TASK == null) {
r.run();
runnable.run();
return;
}
PS.get().TASK.taskLater(r, delay);
PS.get().TASK.taskLater(runnable, delay);
}
}
public static void runTaskLaterAsync(final Runnable r, final int delay) {
if (r != null) {
public static void runTaskLaterAsync(Runnable runnable, int delay) {
if (runnable != null) {
if (PS.get().TASK == null) {
r.run();
runnable.run();
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 task
* @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;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.spongepowered.api.scheduler.Task;
import com.intellectualcrafters.plot.util.TaskManager;
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 {
@ -15,52 +14,52 @@ public class SpongeTaskManager extends TaskManager {
private final HashMap<Integer, Task> tasks = new HashMap<>();
@Override
public int taskRepeat(final Runnable r, final int interval) {
final int val = i.incrementAndGet();
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
final Task.Builder built = builder.delayTicks(interval).intervalTicks(interval).execute(r);
final Task task = built.submit(SpongeMain.THIS.getPlugin());
tasks.put(val, task);
public int taskRepeat(Runnable runnable, int interval) {
int val = this.i.incrementAndGet();
Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
Task.Builder built = builder.delayTicks(interval).intervalTicks(interval).execute(runnable);
Task task = built.submit(SpongeMain.THIS.getPlugin());
this.tasks.put(val, task);
return val;
}
@Override
public int taskRepeatAsync(final Runnable r, final int interval) {
final int val = i.incrementAndGet();
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
final Task.Builder built = builder.delayTicks(interval).async().intervalTicks(interval).execute(r);
final Task task = built.submit(SpongeMain.THIS.getPlugin());
tasks.put(val, task);
public int taskRepeatAsync(Runnable runnable, int interval) {
int val = this.i.incrementAndGet();
Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
Task.Builder built = builder.delayTicks(interval).async().intervalTicks(interval).execute(runnable);
Task task = built.submit(SpongeMain.THIS.getPlugin());
this.tasks.put(val, task);
return val;
}
@Override
public void taskAsync(final Runnable r) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.async().execute(r).submit(SpongeMain.THIS.getPlugin());
public void taskAsync(Runnable runnable) {
Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.async().execute(runnable).submit(SpongeMain.THIS.getPlugin());
}
@Override
public void task(final Runnable r) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.execute(r).submit(SpongeMain.THIS.getPlugin());
public void task(Runnable runnable) {
Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.execute(runnable).submit(SpongeMain.THIS.getPlugin());
}
@Override
public void taskLater(final Runnable r, final int delay) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
public void taskLater(Runnable runnable, int delay) {
Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.delayTicks(delay).execute(runnable).submit(SpongeMain.THIS.getPlugin());
}
@Override
public void taskLaterAsync(final Runnable r, final int delay) {
final Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.async().delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
public void taskLaterAsync(Runnable runnable, int delay) {
Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
builder.async().delayTicks(delay).execute(runnable).submit(SpongeMain.THIS.getPlugin());
}
@Override
public void cancelTask(final int i) {
final Task task = tasks.remove(i);
public void cancelTask(int i) {
Task task = this.tasks.remove(i);
if (task != null) {
task.cancel();
}