Fixes #556
Fixes #540
Fixed plot analysis being slow
Fixed auto updating
This commit is contained in:
boy0001 2015-08-20 14:56:25 +10:00
parent be94aa53d3
commit d0605b9b55
23 changed files with 412 additions and 328 deletions

8
.gitignore vendored
View file

@ -3,7 +3,8 @@
*.bat
### Maven template
target/
target/classes
target/maven-archiver
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
@ -123,7 +124,7 @@ local.properties
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
*.zip
@ -132,3 +133,6 @@ local.properties
hs_err_pid*
*.java
target/PlotSquared-Null.jar
target/PlotSquared-Uber.jar

View file

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>PlotSquared</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View file

@ -109,6 +109,7 @@ public class PS {
private File storageFile;
private File FILE = null; // This file
private int[] VERSION = null;
private String PLATFORM = null;
private String LAST_VERSION;
private boolean LOADING_WORLD = false;
private ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> plots;
@ -120,7 +121,7 @@ public class PS {
* Initialize PlotSquared with the desired Implementation class
* @param imp_class
*/
public PS(final IPlotMain imp_class) {
public PS(final IPlotMain imp_class, String platform) {
try {
instance = this;
this.thread = Thread.currentThread();
@ -135,13 +136,11 @@ public class PS {
e.printStackTrace();
FILE = new File(IMP.getDirectory().getParentFile(), "PlotSquared.jar");
if (!FILE.exists()) {
FILE = new File(IMP.getDirectory().getParentFile(), "PlotSquared-Bukkit.jar");
if (!FILE.exists()) {
FILE = new File(IMP.getDirectory().getParentFile(), "PlotSquared-Sponge.jar");
}
FILE = new File(IMP.getDirectory().getParentFile(), "PlotSquared-" + platform + ".jar");
}
}
VERSION = IMP.getPluginVersion();
PLATFORM = platform;
EconHandler.manager = IMP.getEconomyHandler();
if (getJavaVersion() < 1.7) {
log(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7.");
@ -220,9 +219,6 @@ public class PS {
URL url = getUpdate();
if (url != null) {
update = url;
log("&6You are running an older version of PlotSquared...");
log("&8 - &3Use: &7/plot update");
log("&8 - &3Or: &7" + url);
}
else if (LAST_VERSION != null && !StringMan.join(VERSION,".").equals(LAST_VERSION)) {
log("&aThanks for updating from: " + LAST_VERSION + " to " + StringMan.join(VERSION, "."));
@ -325,6 +321,14 @@ public class PS {
return VERSION;
}
/**
* Get the platform this is running on (Bukkit, Sponge)
* @return
*/
public String getPlatform() {
return PLATFORM;
}
/**
* Log a message to the IPlotMain logger
*
@ -1412,48 +1416,38 @@ public class PS {
* @return
*/
public URL getUpdate() {
String resource = "plotsquared.1177";
String url = "https://www.spigotmc.org/resources/" + resource + "/history";
String download = "<a href=\"resources/" + resource + "/download?version=";
String version = "<td class=\"version\">";
String pom = "https://raw.githubusercontent.com/IntellectualSites/PlotSquared/master/pom.xml";
String dl = "https://raw.githubusercontent.com/IntellectualSites/PlotSquared/master/target/PlotSquared-${PLATFORM}.jar";
String agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1";
try {
URL history = new URL(url);
URLConnection con = history.openConnection();
con.addRequestProperty("User-Agent", "Mozilla/5.0");
InputStream stream = con.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
String l;
URL link = null;
String cur_ver = config.getString("version");
String new_ver = null;
while ((l = in.readLine()) != null) {
if (l.length() > version.length() && l.startsWith(version)) {
new_ver = l.substring(version.length(), l.length() - 5);
URL page = new URL(pom);
URLConnection con = page.openConnection();
con.addRequestProperty("User-Agent", agent);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
line = line.trim();
if (line.startsWith("<version>")) {
line = line.replaceAll("[^\\d.]", "");
break;
}
if (link == null && l.length() > download.length() && l.startsWith(download)) {
String subString = l.substring(download.length());
link = new URL("https://www.spigotmc.org/resources/" + resource + "/download?version=" + subString.substring(0, subString.indexOf("\"")));
continue;
}
}
stream.close();
in.close();
if (new_ver == null || !canUpdate(cur_ver, new_ver)) {
if (!canUpdate(config.getString("version"), line) ) {
PS.debug("&7PlotSquared is already up to date!");
return null;
}
if (link == null) {
PS.debug("&dCould not check for updates (1)");
PS.debug("&7 - Manually check for updates: " + url);
return null;
}
return link;
dl = dl.replaceAll("${PLATFORM}", getPlatform());
log("&6PlotSquared v" + line + " is available:");
log("&8 - &3Use: &7/plot update");
log("&8 - &3Or: &7" + dl);
return new URL(dl);
} catch (Exception e) {
PS.debug("&dCould not check for updates (2)");
PS.debug("&7 - Manually check for updates: " + url);
return null;
e.printStackTrace();
log("&dCould not check for updates (0)");
log("&7 - Manually check for updates: " + pom);
}
return null;
}
public boolean update(PlotPlayer sender, URL url) {
@ -1505,7 +1499,6 @@ public class PS {
*/
public void copyFile(String file, String folder) {
try {
byte[] buffer = new byte[2048];
File output = IMP.getDirectory();
if (!output.exists()) {
output.mkdirs();
@ -1514,6 +1507,9 @@ public class PS {
if (newFile.exists()) {
return;
}
InputStream stream = IMP.getClass().getResourceAsStream(file);
byte[] buffer = new byte[2048];
if (stream == null) {
ZipInputStream zis = new ZipInputStream(new FileInputStream(FILE));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
@ -1534,6 +1530,16 @@ public class PS {
}
zis.closeEntry();
zis.close();
return;
}
newFile.createNewFile();
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = stream.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
stream.close();
}
catch (Exception e) {
e.printStackTrace();
@ -1726,6 +1732,7 @@ public class PS {
public void setupConfig() {
LAST_VERSION = config.getString("version");
config.set("version", StringMan.join(VERSION,"."));
config.set("platform", PLATFORM);
final Map<String, Object> options = new HashMap<>();
// Command confirmation

View file

@ -88,7 +88,7 @@ public class Clear extends SubCommand {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
if (Settings.DONE_RESTRICTS_BUILDING && FlagManager.isPlotFlagTrue(plot, "done" ) && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))) {
if (FlagManager.isPlotFlagTrue(plot, "done" ) && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))) {
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
return false;
}

View file

@ -60,6 +60,10 @@ public class Continue extends SubCommand {
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
return false;
}
if (FlagManager.isPlotFlagTrue(plot, "done" ) && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))) {
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;

View file

@ -124,11 +124,11 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase()) && !Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase())) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false;
}
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed = af.parseValueRaw(value);
if (parsed == null) {
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
@ -157,11 +157,15 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false;
}
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
}
}
if (flag == null) {
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
return false;
@ -195,9 +199,13 @@ public class FlagCmd extends SubCommand {
return false;
}
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false;
}
}
}
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed = af.parseValueRaw(value);
if (parsed == null) {

View file

@ -34,7 +34,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
permission = "plots.admin",
description = "Update PlotSquared",
usage = "/plot update",
requiredType = RequiredType.PLAYER,
requiredType = RequiredType.NONE,
aliases = {"updateplugin"},
category = CommandCategory.DEBUG
)

View file

@ -213,7 +213,7 @@ public enum C {
/*
* Done
*/
DONE_ALREADY_DONE("$2This plot is already marked as done.","Done"),
DONE_ALREADY_DONE("$2This plot is already marked as done, and you are not allowed to claim more plots","Done"),
DONE_NOT_DONE("$2This plot is not marked as done.","Done"),
DONE_INSUFFICIENT_COMPLEXITY("$2This plot is too simple. Please add more detail before using this command.","Done"),
DONE_SUCCESS("$1Successfully marked this plot as done.","Done"),

View file

@ -181,6 +181,7 @@ public class SQLManager implements AbstractDB {
last = System.currentTimeMillis();
try {
close();
CLOSED = false;
connection = database.forceConnection();
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
@ -2419,6 +2420,15 @@ public class SQLManager implements AbstractDB {
@Override
public void validateAllPlots(Set<Plot> toValidate) {
try {
if (connection.isClosed() || CLOSED) {
CLOSED = false;
connection = database.forceConnection();
}
}
catch (Exception e) {
e.printStackTrace();
}
PS.debug("$1All DB transactions during this session are being validated (This may take a while if corrections need to be made)");
commit();
while (true) {

View file

@ -37,6 +37,7 @@ import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.BO3Handler;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
@ -118,12 +119,16 @@ public class Plot {
public int temp;
/**
* Session only plot metadata (session is until the server stops)
* Session only plot metadata (session is until the server stops)<br>
* <br>
* For persistent metadata use the flag system
* @see FlagManager
*/
private ConcurrentHashMap<String, Object> meta;
/**
* Constructor for a new plot
* Constructor for a new plot<br>
* (Only changes after plot.create() will be properly set in the database)
*
* @param world
* @param id
@ -136,7 +141,9 @@ public class Plot {
}
/**
* Constructor for a temporary plot
* Constructor for a temporary plot (use -1 for temp)<br>
* The database will ignore any queries regarding temporary plots.
* Please note that some bulk plot management functions may still affect temporary plots (TODO: fix this)
*
* @param world
* @param id
@ -151,7 +158,7 @@ public class Plot {
}
/**
* Constructor for a saved plots
* Constructor for a saved plots (Used by the database manager when plots are fetched)
*
* @param id
* @param owner
@ -180,7 +187,10 @@ public class Plot {
}
/**
* Set some session only metadata for the plot
* Session only plot metadata (session is until the server stops)<br>
* <br>
* For persistent metadata use the flag system
* @see FlagManager
* @param key
* @param value
*/
@ -245,18 +255,18 @@ public class Plot {
}
/**
* Check if the player is either the owner or on the trusted list
* Check if the player is either the owner or on the trusted/added list
*
* @param uuid
*
* @return true if the player is added as a helper or is the owner
* @return true if the player is added/trusted or is the owner
*/
public boolean isAdded(final UUID uuid) {
return PlotHandler.isAdded(this, uuid);
}
/**
* Should the player be allowed to enter?
* Should the player be denied from entering?
*
* @param uuid
*
@ -303,6 +313,10 @@ public class Plot {
return !settings.getMerged(0) && !settings.getMerged(3);
}
/**
* Check if the plot is merged
* @return
*/
public boolean isMerged() {
if (settings == null) {
return false;
@ -310,6 +324,10 @@ public class Plot {
return settings.getMerged(0) || settings.getMerged(2) || settings.getMerged(1) || settings.getMerged(3);
}
/**
* Get the timestamp in milliseconds of when the plot was created (unreliable)
* @return
*/
public long getTimestamp() {
if (timestamp == 0) {
timestamp = System.currentTimeMillis();
@ -363,7 +381,7 @@ public class Plot {
}
/**
* Deny someone (use DBFunc.addDenied() as well)
* Deny someone (updates database as well)
*
* @param uuid
*/
@ -372,7 +390,7 @@ public class Plot {
}
/**
* Add someone as a helper (use DBFunc as well)
* Add someone as a helper (updates database as well)
*
* @param uuid
*/
@ -381,7 +399,7 @@ public class Plot {
}
/**
* Add someone as a trusted user (use DBFunc as well)
* Add someone as a trusted user (updates database as well)
*
* @param uuid
*/
@ -390,7 +408,7 @@ public class Plot {
}
/**
* Set the plot owner
* Set the plot owner (and update the database)
* @param owner
*/
public void setOwner(final UUID owner) {
@ -811,8 +829,7 @@ public class Plot {
/**
* Get the plot hashcode
*
* @return integer. You can easily make this a character array <br> xI = c[0] x = c[1 -&gt; xI...] yI = c[xI ... + 1] y
* = c[xI ... + 2 -&gt; yI ...]
* @return integer.
*/
@Override
public int hashCode() {

View file

@ -66,7 +66,7 @@ public class ExpireManager {
}
public static void runTask() {
ExpireManager.task = TaskManager.runTaskRepeat(new Runnable() {
ExpireManager.task = TaskManager.runTaskRepeatAsync(new Runnable() {
@Override
public void run() {
try {

View file

@ -526,8 +526,13 @@ public class MainUtil {
public static int getBorder(final String worldname) {
if (worldBorder.containsKey(worldname)) {
PS.get().getPlotWorld(worldname);
return worldBorder.get(worldname) + 16;
int border = worldBorder.get(worldname) + 16;
if (border == 0) {
return Integer.MAX_VALUE;
}
else {
return border;
}
}
return Integer.MAX_VALUE;
}

View file

@ -20,14 +20,6 @@ public class Permissions {
if (player.hasPermission(perm)) {
return true;
}
final String[] nodes = perm.split("\\.");
final StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i] + ("."));
if (player.hasPermission(n + C.PERMISSION_STAR.s())) {
return true;
}
}
return false;
}

View file

@ -121,7 +121,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
public void onEnable() {
THIS = this;
PS.instance = new PS(this);
PS.instance = new PS(this, "Bukkit");
}
@Override

View file

@ -105,6 +105,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
@ -877,11 +878,20 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFade(final BlockFadeEvent e) {
final Block b = e.getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PS.get().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true);
String world = b.getWorld().getName();
PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) {
return;
}
PlotManager manager = PS.get().getPlotManager(world);
PlotId id = manager.getPlotId(plotworld, b.getX(), b.getY(), b.getZ());
if (id == null) {
if (plotworld.TYPE == 2) {
if (ClusterManager.getClusterAbs(BukkitUtil.getLocation(b.getLocation())) != null) {
return;
}
}
e.setCancelled(true);
}
}

View file

@ -171,8 +171,9 @@ public class PlotPlusListener extends PlotListener implements Listener {
public void onPlotEnter(final PlayerEnterPlotEvent event) {
Player player = event.getPlayer();
final Plot plot = event.getPlot();
if (FlagManager.getPlotFlag(plot, "greeting") != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_GREETING.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "greeting").getValueString()));
Flag greeting = FlagManager.getPlotFlag(plot, "greeting");
if (greeting != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_GREETING.s().replaceAll("%id%", plot.id + "") + greeting.getValueString()));
}
Flag feed = FlagManager.getPlotFlag(plot, "feed");
if (feed != null) {
@ -222,8 +223,9 @@ public class PlotPlusListener extends PlotListener implements Listener {
if (!plot.hasOwner()) {
return;
}
if (FlagManager.getPlotFlag(plot, "farewell") != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_FAREWELL.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "farewell").getValueString()));
Flag farewell = FlagManager.getPlotFlag(plot, "farewell");
if (farewell != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_FAREWELL.s().replaceAll("%id%", plot.id + "") + farewell.getValueString()));
}
final PlotPlayer pl = BukkitUtil.getPlayer(leaver);
String name = leaver.getName();

View file

@ -28,14 +28,15 @@ public class WEManager {
HashSet<RegionWrapper> regions = new HashSet<>();
UUID uuid = player.getUUID();
for (Plot plot : PS.get().getPlotsInWorld(player.getLocation().getWorld())) {
if (Settings.DONE_RESTRICTS_BUILDING && plot.isBasePlot() && FlagManager.getPlotFlag(plot, "done") == null) {
if (!plot.isBasePlot() || Settings.DONE_RESTRICTS_BUILDING && FlagManager.getPlotFlag(plot, "done") != null) {
continue;
}
if (Settings.WE_ALLOW_HELPER ? plot.isAdded(uuid) : (plot.isOwner(uuid) || plot.getTrusted().contains(uuid))) {
Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
regions.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()));
}
}
}
return regions;
}

View file

@ -1,6 +1,7 @@
package com.plotsquared.bukkit.object;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -68,26 +69,45 @@ public class BukkitPlayer extends PlotPlayer {
}
@Override
public boolean hasPermission(final String perm) {
public boolean hasPermission(final String node) {
if (Settings.PERMISSION_CACHING) {
if (this.noPerm.contains(perm)) {
if (this.noPerm.contains(node)) {
return false;
}
if (this.hasPerm.contains(perm)) {
if (this.hasPerm.contains(node)) {
return true;
}
final boolean result = this.player.hasPermission(perm);
if (!result) {
this.noPerm.add(perm);
return false;
}
this.hasPerm.add(perm);
return true;
}
if (offline && EconHandler.manager != null) {
return EconHandler.manager.hasPermission(getName(), perm);
return EconHandler.manager.hasPermission(getName(), node);
}
return this.player.hasPermission(perm);
boolean value = this.player.hasPermission(node);
if (!value) {
Permission perm = Bukkit.getServer().getPluginManager().getPermission(node);
if (perm == null) {
perm = new Permission(node, PermissionDefault.FALSE);
Map<String, Boolean> children = perm.getChildren();
final String[] nodes = node.split("\\.");
final StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i] + ("."));
children.put(n + C.PERMISSION_STAR.s(), true);
}
Bukkit.getServer().getPluginManager().addPermission(perm);
Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm);
value = this.player.hasPermission(node);
}
}
if (Settings.PERMISSION_CACHING) {
if (value) {
this.hasPerm.add(node);
}
else {
this.noPerm.add(node);
}
}
return value;
}
@Override

View file

@ -25,6 +25,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager;
@ -34,7 +35,6 @@ public class BukkitHybridUtils extends HybridUtils {
@Override
public void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone) {
// int diff, int variety, int verticies, int rotation, int height_sd
/*
* diff: compare to base by looping through all blocks
* variety: add to hashset for each plotblock
@ -46,14 +46,17 @@ public class BukkitHybridUtils extends HybridUtils {
* - recheck each block
*
*/
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
final World world = Bukkit.getWorld(plot.world);
final ChunkGenerator gen = world.getGenerator();
if (gen == null) {
return;
}
final BiomeGrid base = new BiomeGrid() { @Override public void setBiome(int a, int b, Biome c) {} @Override public Biome getBiome(int a, int b) {return null;}};
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
final int bx = bot.getX();
final int bz = bot.getZ();
final int tx = top.getX();
@ -72,22 +75,16 @@ public class BukkitHybridUtils extends HybridUtils {
final short[][][] oldblocks = new short[256][width][length];
final short[][][] newblocks = new short[256][width][length];
final List<ChunkLoc> chunks = new ArrayList<>();
final List<ChunkLoc> processed_chunks = new ArrayList<>();
for (int X = cbx; X <= ctx; X++) {
for (int Z = cbz; Z <= ctz; Z++) {
// Chunk chunk = world.getChunkAt(X, Z);
chunks.add(new ChunkLoc(X, Z));
}
}
final Runnable run = new Runnable() {
@Override
public void run() {
for (ChunkLoc chunk : processed_chunks) {
short[][] result = gen.generateExtBlockSections(world, r, chunk.x, chunk.z, base);
int X = chunk.x;
int Z = chunk.z;
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
@Override
public void run() {
// TODO [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
int X = value[0];
int Z = value[1];
short[][] result = gen.generateExtBlockSections(world, r, X, Z, base);
int xb = ((X) << 4) - bx;
int zb = ((Z) << 4) - bz;
for (int i = 0; i < result.length; i++) {
@ -111,14 +108,20 @@ public class BukkitHybridUtils extends HybridUtils {
oldblocks[y][x][z] = result[i][j];
}
}
}
}, new Runnable() {
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
int size = width * length;
int[] changes = new int[size];
int[] faces = new int[size];
int[] data = new int[size];
int[] air = new int[size];
int[] variety = new int[size];
int i = 0;
for (int x = 0; x < width;x++) {
for (int z = 0; z < length;z++) {
@ -195,36 +198,32 @@ public class BukkitHybridUtils extends HybridUtils {
whenDone.value = analysis;
whenDone.run();
}
});
}
}, 5);
}
};
System.gc();
MainUtil.initCache();
TaskManager.index.incrementAndGet();
final Integer currentIndex = TaskManager.index.get();
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
@Override
public void run() {
int index = chunks.size() - 1;
if (index == -1) {
PS.get().TASK.cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.runTaskAsync(run);
return;
}
ChunkLoc chunk = chunks.remove(0);
world.loadChunk(chunk.x, chunk.z);
processed_chunks.add(chunk);
int X = chunk.x;
int Z = chunk.z;
int X = value[0];
int Z = value[1];
world.loadChunk(X, Z);
int minX;
int minZ;
int maxX;
int maxZ;
if (X == cbx) minX = bx & 0x0f;
if (X == cbx) minX = bx & 15;
else minX = 0;
if (Z == cbz) minZ = bz & 0x0f;
if (Z == cbz) minZ = bz & 15;
else minZ = 0;
if (X == ctx) maxX = tx & 0x0f;
if (X == ctx) maxX = tx & 15;
else maxX = 16;
if (Z == ctz) maxZ = tz & 0x0f;
if (Z == ctz) maxZ = tz & 15;
else maxZ = 16;
int cbx = X << 4;
@ -233,7 +232,7 @@ public class BukkitHybridUtils extends HybridUtils {
int xb = (cbx) - bx;
int zb = (cbz) - bz;
for (int x = minX; x <= maxX; x++) {
int xx = cbx + cbz;
int xx = cbx + x;
for (int z = minZ; z <= maxZ; z++) {
int zz = cbz + z;
for (int y = 0; y < 256; y++) {
@ -244,10 +243,16 @@ public class BukkitHybridUtils extends HybridUtils {
}
}
}
world.unloadChunkRequest(chunk.x, chunk.z, true);
world.unloadChunkRequest(X, Z, true);
}
}, 1);
TaskManager.tasks.put(currentIndex, task);
}, new Runnable() {
@Override
public void run() {
TaskManager.runTaskAsync(run);
}
}, 5);
}
});
}
@Override

View file

@ -229,7 +229,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
server = game.getServer();
//
PS.instance = new PS(this);
PS.instance = new PS(this, "Sponge");
// TODO Until P^2 has json chat stuff for sponge, disable this
Settings.FANCY_CHAT = false;

View file

@ -2,13 +2,8 @@ package com.plotsquared.sponge.object;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.TargetedLocationData;
import org.spongepowered.api.data.manipulator.mutable.entity.GameModeData;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.entity.player.gamemode.GameMode;
import org.spongepowered.api.entity.player.gamemode.GameModes;
@ -96,7 +91,11 @@ public class SpongePlayer extends PlotPlayer {
this.hasPerm.add(perm);
return true;
}
return this.player.hasPermission(perm);
boolean value = this.player.hasPermission(perm);
// TODO check children
return value;
}
@Override

Binary file not shown.

Binary file not shown.