diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 4db8d5303..ded0e19a7 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -90,7 +90,7 @@ import com.sk89q.worldedit.WorldEdit; public class PS { // protected static: - public static PS instance; + private static PS instance; // private final: private final HashMap plotworlds = new HashMap<>(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java b/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java index 1d2c84e9d..54c24a1d5 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java @@ -20,7 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.List; import java.util.Set; import com.intellectualcrafters.plot.PS; @@ -32,23 +31,18 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; -import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( command = "regenallroads", description = "Regenerate all roads in the map using the set road schematic", aliases = { "rgar" }, -usage = "/plot regenallroads ", +usage = "/plot regenallroads [height]", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE, permission = "plots.regenallroads") public class RegenAllRoads extends SubCommand { - public RegenAllRoads() { - requiredArguments = new Argument[] { Argument.String }; - } - @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { int height = 0; @@ -60,6 +54,9 @@ public class RegenAllRoads extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot regenallroads [height]"); return false; } + } else { + MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot regenallroads [height]"); + return false; } final String name = args[0]; final PlotManager manager = PS.get().getPlotManager(name); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Update.java b/src/main/java/com/intellectualcrafters/plot/commands/Update.java index f52f26f52..1192fa221 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Update.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Update.java @@ -31,7 +31,7 @@ import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( command = "update", -permission = "plots.admin", +permission = "plots.admin.command.update", description = "Update PlotSquared", usage = "/plot update", requiredType = RequiredType.NONE, diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index 2f64e35e3..2e8518734 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -90,6 +90,7 @@ public enum C { PERMISSION_ADMIN_INTERACT_UNOWNED("plots.admin.interact.unowned", "static.permissions"), PERMISSION_ADMIN_INTERACT_OTHER("plots.admin.interact.other", "static.permissions"), PERMISSION_ADMIN_BUILD_HEIGHTLIMIT("plots.admin.build.heightlimit", "static.permissions"), + PERMISSION_ADMIN_UPDATE("plots.admin.command.update", "static.permissions"), /* * Static console */ diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 208298ce0..486ddde06 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -575,9 +575,9 @@ public class SQLManager implements AbstractDB { stmt.setInt((i * 5) + 1, plot.id.x); stmt.setInt((i * 5) + 2, plot.id.y); try { - stmt.setString((i * 4) + 3, plot.owner.toString()); + stmt.setString((i * 5) + 3, plot.owner.toString()); } catch (final Exception e) { - stmt.setString((i * 4) + 3, everyone.toString()); + stmt.setString((i * 5) + 3, everyone.toString()); } stmt.setString((i * 5) + 4, plot.world); stmt.setTimestamp((i * 5) + 5, new Timestamp(plot.getTimestamp())); diff --git a/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index 7db5fc771..938aea5de 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -11,7 +11,6 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.StringMan; /** * A plot manager with a square grid layout, with square shaped plots @@ -93,83 +92,87 @@ public abstract class SquarePlotManager extends GridPlotManager { @Override public PlotId getPlotId(final PlotWorld plotworld, int x, final int y, int z) { - final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); - if (plotworld == null) { - return null; - } - x -= dpw.ROAD_OFFSET_X; - z -= dpw.ROAD_OFFSET_Z; - final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; - int pathWidthLower; - final int end; - if (dpw.ROAD_WIDTH == 0) { - pathWidthLower = -1; - end = dpw.PLOT_WIDTH; - } else { - if ((dpw.ROAD_WIDTH % 2) == 0) { - pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; - } else { - pathWidthLower = dpw.ROAD_WIDTH / 2; + try { + final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); + if (plotworld == null) { + return null; } - end = pathWidthLower + dpw.PLOT_WIDTH; + x -= dpw.ROAD_OFFSET_X; + z -= dpw.ROAD_OFFSET_Z; + final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; + int pathWidthLower; + final int end; + if (dpw.ROAD_WIDTH == 0) { + pathWidthLower = -1; + end = dpw.PLOT_WIDTH; + } else { + if ((dpw.ROAD_WIDTH % 2) == 0) { + pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; + } else { + pathWidthLower = dpw.ROAD_WIDTH / 2; + } + end = pathWidthLower + dpw.PLOT_WIDTH; + } + int dx; + int dz; + int rx; + int rz; + if (x < 0) { + dx = (x / size); + rx = size + (x % size); + } else { + dx = (x / size) + 1; + rx = (x % size); + } + if (z < 0) { + dz = (z / size); + rz = size + (z % size); + } else { + dz = (z / size) + 1; + rz = (z % size); + } + PlotId id = new PlotId(dx, dz); + boolean[] merged = new boolean[] { (rz <= pathWidthLower), (rx > end), (rz > end), (rx <= pathWidthLower) }; + int hash = MainUtil.hash(merged); + // Not merged, and no need to check if it is + if (hash == 0) { + return id; + } + Plot plot = PS.get().getPlot(plotworld.worldname, id); + // Not merged, and standing on road + if (plot == null) { + return null; + } + switch (hash) { + case 8: + // north + return plot.getMerged(0) ? id : null; + case 4: + // east + return plot.getMerged(1) ? id : null; + case 2: + // south + return plot.getMerged(2) ? id : null; + case 1: + // west + return plot.getMerged(3) ? id : null; + case 12: + // northest + return plot.getMerged(4) ? id : null; + case 6: + // southeast + return plot.getMerged(5) ? id : null; + case 3: + // southwest + return plot.getMerged(6) ? id : null; + case 9: + // northwest + return plot.getMerged(7) ? id : null; + } + PS.debug("invalid location: " + merged); + } catch (Exception e) { + PS.debug("Invalid plot / road width in settings.yml for world: " + plotworld.worldname); } - int dx; - int dz; - int rx; - int rz; - if (x < 0) { - dx = (x / size); - rx = size + (x % size); - } else { - dx = (x / size) + 1; - rx = (x % size); - } - if (z < 0) { - dz = (z / size); - rz = size + (z % size); - } else { - dz = (z / size) + 1; - rz = (z % size); - } - PlotId id = new PlotId(dx, dz); - boolean[] merged = new boolean[] {(rz <= pathWidthLower), (rx > end), (rz > end), (rx <= pathWidthLower)}; - int hash = MainUtil.hash(merged); - // Not merged, and no need to check if it is - if (hash == 0) { - return id; - } - Plot plot = PS.get().getPlot(plotworld.worldname, id); - // Not merged, and standing on road - if (plot == null) { - return null; - } - switch (hash) { - case 8: - // north - return plot.getMerged(0) ? id : null; - case 4: - // east - return plot.getMerged(1) ? id : null; - case 2: - // south - return plot.getMerged(2) ? id : null; - case 1: - // west - return plot.getMerged(3) ? id : null; - case 12: - // northest - return plot.getMerged(4) ? id : null; - case 6: - // southeast - return plot.getMerged(5) ? id : null; - case 3: - // southwest - return plot.getMerged(6) ? id : null; - case 9: - // northwest - return plot.getMerged(7) ? id : null; - } - PS.debug("invalid location: " + merged); return null; } diff --git a/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java b/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java index b24515c78..140b73f10 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java @@ -129,8 +129,8 @@ public class ConsolePlayer extends PlotPlayer { } @Override - public void deleteMeta(final String key) { - meta.remove(key); + public Object deleteMeta(final String key) { + return meta.remove(key); } @Override diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 9ac9d13d0..17e54da2a 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -1013,7 +1013,7 @@ public class Plot { public boolean removeDenied(final UUID uuid) { if (uuid == DBFunc.everyone) { boolean result = false; - for (UUID other : getDenied()) { + for (UUID other : new HashSet<>(getDenied())) { result = result || PlotHandler.removeDenied(this, other); } return result; @@ -1029,7 +1029,7 @@ public class Plot { public boolean removeTrusted(final UUID uuid) { if (uuid == DBFunc.everyone) { boolean result = false; - for (UUID other : getTrusted()) { + for (UUID other : new HashSet<>(getTrusted())) { result = result || PlotHandler.removeTrusted(this, other); } return result; @@ -1045,7 +1045,7 @@ public class Plot { public boolean removeMember(final UUID uuid) { if (uuid == DBFunc.everyone) { boolean result = false; - for (UUID other : getMembers()) { + for (UUID other : new HashSet<>(getMembers())) { result = result || PlotHandler.removeMember(this, other); } return result; diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 51e21c44c..8ac62a051 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -80,10 +80,8 @@ public abstract class PlotPlayer implements CommandCaller { * - deleting other plugin's metadata may cause issues * @param key */ - public void deleteMeta(final String key) { - if (meta != null) { - meta.remove(key); - } + public Object deleteMeta(final String key) { + return meta.remove(key); } /** diff --git a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index d90e429be..119c5f7c8 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -107,12 +107,11 @@ public abstract class ChunkManager { public abstract void unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe); public Set getChunkChunks(final String world) { - final String directory = PS.get().IMP.getWorldContainer() + File.separator + world + File.separator + "region"; - final File folder = new File(directory); + final File folder = new File(PS.get().IMP.getWorldContainer(), world + File.separator + "region"); final File[] regionFiles = folder.listFiles(); final HashSet chunks = new HashSet<>(); if (regionFiles == null) { - throw new RuntimeException("Could not find worlds folder."); + throw new RuntimeException("Could not find worlds folder: " + folder + " ? (no read access?)"); } for (final File file : regionFiles) { final String name = file.getName(); diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index fe993580b..258603e46 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -563,6 +563,9 @@ public class MainUtil { } public static boolean isPlotAreaAbs(final Location location) { + if (!Settings.ENABLE_CLUSTERS) { + return true; + } final PlotWorld plotworld = PS.get().getPlotWorld(location.getWorld()); if (plotworld == null) { return false; @@ -586,6 +589,9 @@ public class MainUtil { } public static boolean isPlotArea(final Plot plot) { + if (!Settings.ENABLE_CLUSTERS) { + return true; + } final PlotWorld plotworld = PS.get().getPlotWorld(plot.world); if (plotworld.TYPE == 2) { return plot.getCluster() != null; diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 06324918d..a4d95479a 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -3,6 +3,7 @@ package com.plotsquared.bukkit; import java.io.File; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.UUID; @@ -122,7 +123,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public void onEnable() { THIS = this; - PS.instance = new PS(this, "Bukkit"); + new PS(this, "Bukkit"); } @Override @@ -191,23 +192,19 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public void runEntityTask() { log(C.PREFIX.s() + "KillAllEntities started."); TaskManager.runTaskRepeat(new Runnable() { - long ticked = 0l; - long error = 0l; - @Override public void run() { - if (ticked > 36_000L) { - ticked = 0l; - if (error > 0) { - log(C.PREFIX.s() + "KillAllEntities has been running for 6 hours. Errors: " + error); - } - error = 0l; - } World world; for (final PlotWorld pw : PS.get().getPlotWorldObjects()) { world = Bukkit.getWorld(pw.worldname); try { - for (final Entity entity : world.getEntities()) { + if (world == null) { + continue; + } + List entities = world.getEntities(); + Iterator iter = entities.iterator(); + while (iter.hasNext()) { + Entity entity = iter.next(); switch (entity.getType()) { case EGG: case ENDER_CRYSTAL: @@ -251,19 +248,21 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { Plot plot = loc.getPlot(); if (plot == null) { if (MainUtil.isPlotAreaAbs(loc)) { + iter.remove(); entity.remove(); } - return; + continue; } List meta = entity.getMetadata("plot"); if (meta.size() == 0) { - return; + continue; } Plot origin = (Plot) meta.get(0).value(); if (!plot.equals(origin.getBasePlot(false))) { + iter.remove(); entity.remove(); } - break; + continue; } case SMALL_FIREBALL: case FIREBALL: @@ -317,18 +316,17 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { final Entity passenger = entity.getPassenger(); if (!(passenger instanceof Player)) { if (entity.getMetadata("keep").size() == 0) { + iter.remove(); entity.remove(); } } } - break; + continue; } } } } catch (final Throwable e) { - ++error; - } finally { - ++ticked; + e.printStackTrace(); } } } diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java b/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java index 43e7a578e..a18b7f2e5 100644 --- a/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java +++ b/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java @@ -55,8 +55,17 @@ public class PlotMeConnector_017 extends APlotMeConnector { final HashMap roadWidth = new HashMap<>(); final HashMap plots = new HashMap<>(); final HashMap> merges = new HashMap<>(); - stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_plots`"); - r = stmt.executeQuery(); + try { + stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_plots`"); + r = stmt.executeQuery(); + } catch (Exception e) { + PS.debug("========= Table does not exist ========="); + e.printStackTrace(); + PS.debug("======================================="); + PS.debug("&8 - &7The database does not match the version specified in the PlotMe config"); + PS.debug("&8 - &7Please correct this, or if you are unsure, the most common is 0.16.3"); + return null; + } final boolean checkUUID = DBFunc.hasColumn(r, "ownerID"); final boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME; while (r.next()) { diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 619ac2d9f..c4aeb30e4 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -92,7 +92,6 @@ import org.bukkit.plugin.Plugin; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -import org.spongepowered.api.entity.living.animal.Animal; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; @@ -284,18 +283,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen if (!MainUtil.isPlotArea(loc)) { return; } + // final ProjectileSource shooter = entity.getShooter(); - if (shooter instanceof BlockProjectileSource) { - if (plot == null) { - entity.remove(); - return; - } - final Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); - final Plot sPlot = MainUtil.getPlot(sLoc); - if ((sPlot == null) || !PlotHandler.sameOwners(plot, sPlot)) { - entity.remove(); - } - } else if ((shooter instanceof Player)) { + if ((shooter instanceof Player)) { final PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); if (plot == null) { if (!Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_UNOWNED)) { @@ -310,6 +300,16 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen return; } entity.remove(); + } else if (!(shooter instanceof Entity) && shooter != null) { + if (plot == null) { + entity.remove(); + return; + } + final Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); + final Plot sPlot = MainUtil.getPlot(sLoc); + if ((sPlot == null) || !PlotHandler.sameOwners(plot, sPlot)) { + entity.remove(); + } } } @@ -453,7 +453,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASSED); } } - if ((PS.get().update != null) && Permissions.hasPermission(pp, C.PERMISSION_ADMIN) && Settings.UPDATE_NOTIFICATIONS) { + if ((PS.get().update != null) && Permissions.hasPermission(pp, C.PERMISSION_ADMIN_UPDATE) && Settings.UPDATE_NOTIFICATIONS) { TaskManager.runTaskLater(new Runnable() { @Override public void run() { @@ -737,9 +737,13 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen final Player player = event.getPlayer(); final PlotPlayer pp = BukkitUtil.getPlayer(player); + // Delete last location pp.deleteMeta("location"); - pp.deleteMeta("lastplot"); + Plot plot = (Plot) pp.deleteMeta("lastplot"); + if (plot != null) { + plotExit(pp, plot); + } if (BukkitMain.worldEdit != null) { if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) { @@ -1025,13 +1029,16 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen if (blocks.size() == 0) { return; } - final Plot origin = MainUtil.getPlot(BukkitUtil.getLocation(blocks.get(0).getLocation())); - if (origin == null) { - e.setCancelled(true); - return; + Location loc = BukkitUtil.getLocation(blocks.get(0).getLocation()); + final Plot origin = MainUtil.getPlot(loc); + if (origin == null) { + if (MainUtil.isPlotAreaAbs(null)) { + e.setCancelled(true); + return; + } } for (int i = blocks.size() - 1; i >= 0; i--) { - final Location loc = BukkitUtil.getLocation(blocks.get(i).getLocation()); + loc = BukkitUtil.getLocation(blocks.get(i).getLocation()); final Plot plot = MainUtil.getPlot(loc); if (!Objects.equals(plot, origin)) { e.getBlocks().remove(i); @@ -1438,7 +1445,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen default: { String[] types; if (entity instanceof LivingEntity) { - if (entity instanceof Animal) { + if (entity instanceof Animals) { types = new String[] { "entity-cap", "mob-cap", "animal-cap" }; } else if (entity instanceof Monster) { types = new String[] { "entity-cap", "mob-cap", "hostile-cap" }; diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java index 3d8a7f575..f8628e6d1 100644 --- a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java +++ b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java @@ -262,7 +262,11 @@ public class BukkitPlayer extends PlotPlayer { @Override public void setTime(final long time) { - player.setPlayerTime(time, false); + if (time != Long.MAX_VALUE) { + player.setPlayerTime(time, false); + } else { + player.resetPlayerTime(); + } } @Override diff --git a/src/main/java/com/plotsquared/listener/PlotListener.java b/src/main/java/com/plotsquared/listener/PlotListener.java index 652c9e133..d84f29e2c 100644 --- a/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/src/main/java/com/plotsquared/listener/PlotListener.java @@ -20,7 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.plotsquared.listener; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -228,7 +227,9 @@ public class PlotListener { pp.setFlight(false); } } + System.out.print("CHECKING TIME"); if (FlagManager.getPlotFlagRaw(plot, "time") != null) { + System.out.print("RESETTING TIEM"); pp.setTime(Long.MAX_VALUE); } if (FlagManager.getPlotFlagRaw(plot, "weather") != null) { @@ -242,8 +243,4 @@ public class PlotListener { } return true; } - - public boolean getFlagValue(final String value) { - return Arrays.asList("true", "on", "enabled", "yes").contains(value.toLowerCase()); - } } diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index 3b1b66829..7f93dfbb6 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -236,7 +236,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { server = game.getServer(); // - PS.instance = new PS(this, "Sponge"); + new PS(this, "Sponge"); registerBlocks(); diff --git a/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 41b347100..e9aee2cdb 100644 --- a/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -12,7 +12,7 @@ import java.util.function.Predicate; import org.spongepowered.api.GameProfile; import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockState; -import org.spongepowered.api.block.BlockTransaction; +import org.spongepowered.api.data.Transaction; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.Transform; @@ -159,7 +159,7 @@ public class MainListener { } return null; } - + @Listener public void onCommand(final BreedEntityEvent.Breed event) { final Location loc = SpongeUtil.getLocation(event.getTargetEntity()); @@ -182,131 +182,126 @@ public class MainListener { @Listener public void onMobSpawn(final SpawnEntityEvent event) { - final Entity entity = event.getTargetEntity(); - if (entity instanceof Player) { - return; - } - final Location loc = SpongeUtil.getLocation(entity); - final String world = loc.getWorld(); - final PlotWorld plotworld = PS.get().getPlotWorld(world); + World world = event.getTargetWorld(); + final PlotWorld plotworld = PS.get().getPlotWorld(world.getName()); if (plotworld == null) { return; } - final Plot plot = MainUtil.getPlot(loc); - if (plot == null) { - if (MainUtil.isPlotRoad(loc)) { - event.setCancelled(true); - } - return; - } - PS.get().getPlotWorld(world); - // Player player = this. getCause(event.getCause()); - // TODO selectively cancel depending on spawn reason - // - Not sure if possible to get spawn reason (since there are no callbacks) - // if (player != null && !plotworld.SPAWN_EGGS) { - // event.setCancelled(true); - // return; - // } - - if (entity.getType() == EntityTypes.ITEM) { - if (FlagManager.isPlotFlagFalse(plot, "item-drop")) { - event.setCancelled(true); - } - return; - } - int[] mobs = null; - if (entity instanceof Living) { - if (!plotworld.MOB_SPAWNING) { - event.setCancelled(true); - return; - } - final Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap"); - if (mobCap != null) { - final Integer cap = (Integer) mobCap.getValue(); - if (cap == 0) { - event.setCancelled(true); - return; + List entities = event.getEntities(); + event.filterEntities(new Predicate() { + + @Override + public boolean test(Entity entity) { + if (entity instanceof Player) { + return true; } - if (mobs == null) { - mobs = MainUtil.countEntities(plot); + final Location loc = SpongeUtil.getLocation(entity); + final Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + if (MainUtil.isPlotRoad(loc)) { + return false; + } + return true; } - if (mobs[3] >= cap) { - event.setCancelled(true); - return; + // Player player = this. getCause(event.getCause()); + // TODO selectively cancel depending on spawn reason + // - Not sure if possible to get spawn reason (since there are no callbacks) + // if (player != null && !plotworld.SPAWN_EGGS) { + // return false; + // return true; + // } + + if (entity.getType() == EntityTypes.ITEM) { + if (FlagManager.isPlotFlagFalse(plot, "item-drop")) { + return false; + } + return true; } - } - if ((entity instanceof Ambient) || (entity instanceof Animal)) { - final Flag animalFlag = FlagManager.getPlotFlagRaw(plot, "animal-cap"); - if (animalFlag != null) { - final int cap = ((Integer) animalFlag.getValue()); + int[] mobs = null; + if (entity instanceof Living) { + if (!plotworld.MOB_SPAWNING) { + return false; + } + final Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap"); + if (mobCap != null) { + final Integer cap = (Integer) mobCap.getValue(); + if (cap == 0) { + return false; + } + if (mobs == null) { + mobs = MainUtil.countEntities(plot); + } + if (mobs[3] >= cap) { + return false; + } + } + if ((entity instanceof Ambient) || (entity instanceof Animal)) { + final Flag animalFlag = FlagManager.getPlotFlagRaw(plot, "animal-cap"); + if (animalFlag != null) { + final int cap = ((Integer) animalFlag.getValue()); + if (cap == 0) { + return false; + } + if (mobs == null) { + mobs = MainUtil.countEntities(plot); + } + if (mobs[1] >= cap) { + return false; + } + } + } + if (entity instanceof Monster) { + final Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap"); + if (monsterFlag != null) { + final int cap = ((Integer) monsterFlag.getValue()); + if (cap == 0) { + return false; + } + if (mobs == null) { + mobs = MainUtil.countEntities(plot); + } + if (mobs[2] >= cap) { + return false; + } + } + } + return true; + } + if ((entity instanceof Minecart) || (entity instanceof Boat)) { + final Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap"); + if (vehicleFlag != null) { + final int cap = ((Integer) vehicleFlag.getValue()); + if (cap == 0) { + return false; + } + if (mobs == null) { + mobs = MainUtil.countEntities(plot); + } + if (mobs[4] >= cap) { + return false; + } + } + } + final Flag entityCap = FlagManager.getPlotFlagRaw(plot, "entity-cap"); + if (entityCap != null) { + final Integer cap = (Integer) entityCap.getValue(); if (cap == 0) { - event.setCancelled(true); - return; + return false; } if (mobs == null) { mobs = MainUtil.countEntities(plot); } - if (mobs[1] >= cap) { - event.setCancelled(true); - return; + if (mobs[0] >= cap) { + return false; } } - } - if (entity instanceof Monster) { - final Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap"); - if (monsterFlag != null) { - final int cap = ((Integer) monsterFlag.getValue()); - if (cap == 0) { - event.setCancelled(true); - return; - } - if (mobs == null) { - mobs = MainUtil.countEntities(plot); - } - if (mobs[2] >= cap) { - event.setCancelled(true); - return; - } + if (entity instanceof PrimedTNT) { + Vector3d pos = entity.getLocation().getPosition(); + entity.setRotation(new Vector3d(MathMan.roundInt(pos.getX()), MathMan.roundInt(pos.getY()), MathMan.roundInt(pos.getZ()))); } + return true; } - return; - } - if ((entity instanceof Minecart) || (entity instanceof Boat)) { - final Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap"); - if (vehicleFlag != null) { - final int cap = ((Integer) vehicleFlag.getValue()); - if (cap == 0) { - event.setCancelled(true); - return; - } - if (mobs == null) { - mobs = MainUtil.countEntities(plot); - } - if (mobs[4] >= cap) { - event.setCancelled(true); - return; - } - } - } - final Flag entityCap = FlagManager.getPlotFlagRaw(plot, "entity-cap"); - if (entityCap != null) { - final Integer cap = (Integer) entityCap.getValue(); - if (cap == 0) { - event.setCancelled(true); - return; - } - if (mobs == null) { - mobs = MainUtil.countEntities(plot); - } - if (mobs[0] >= cap) { - event.setCancelled(true); - return; - } - } - if (entity instanceof PrimedTNT) { - Vector3d pos = entity.getLocation().getPosition(); - entity.setRotation(new Vector3d(MathMan.roundInt(pos.getX()), MathMan.roundInt(pos.getY()), MathMan.roundInt(pos.getZ()))); - } + }); } @Listener @@ -333,8 +328,8 @@ public class MainListener { if (!PS.get().isPlotWorld(worldname)) { return; } - List transactions = event.getTransactions(); - BlockTransaction first = transactions.get(0); + List> transactions = event.getTransactions(); + Transaction first = transactions.get(0); Location loc = SpongeUtil.getLocation(worldname, first.getOriginal().getPosition()); Plot plot = MainUtil.getPlot(loc); if (plot == null) { @@ -370,14 +365,13 @@ public class MainListener { public void onLightning(final LightningEvent.Strike event) { onBlockChange(event); } - - + public void printCause(String method, Cause cause) { System.out.println(method + ": " + cause.toString()); System.out.println(method + ": " + cause.getClass()); System.out.println(method + ": " + (cause.root().isPresent() ? cause.root().get() : null)); } - + @Listener public void onChat(final MessageEvent event) { // TODO @@ -433,8 +427,7 @@ public class MainListener { } ((SpongePlayer) user).player.sendMessage(Texts.join(components)); } - event.setMessage(Texts.of()); - event.setCancelled(true); + event.setMessage(null); } @Listener @@ -529,8 +522,8 @@ public class MainListener { if (!PS.get().isPlotWorld(worldname)) { return; } - List transactions = event.getTransactions(); - BlockTransaction first = transactions.get(0); + List> transactions = event.getTransactions(); + Transaction first = transactions.get(0); BlockSnapshot pos = first.getOriginal(); Location loc = SpongeUtil.getLocation(worldname, pos.getPosition()); Plot plot = MainUtil.getPlot(loc); @@ -613,8 +606,8 @@ public class MainListener { if (!PS.get().isPlotWorld(worldname)) { return; } - List transactions = event.getTransactions(); - BlockTransaction first = transactions.get(0); + List> transactions = event.getTransactions(); + Transaction first = transactions.get(0); BlockSnapshot pos = first.getOriginal(); Location loc = SpongeUtil.getLocation(worldname, pos.getPosition()); Plot plot = MainUtil.getPlot(loc); @@ -683,7 +676,7 @@ public class MainListener { } }); } - + @Listener public void onBlockInteract(final InteractBlockEvent.Secondary event) { final Player player = this. getCause(event.getCause(), Player.class); diff --git a/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java b/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java index 425c539ad..d012eb860 100644 --- a/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java +++ b/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java @@ -225,6 +225,7 @@ public class SpongePlayer extends PlotPlayer { @Override public void setTime(final long time) { // TODO Auto-generated method stub + if (time != Long.MAX_VALUE) {} else {} throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java index 8ab2db6fd..197f9d873 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java @@ -1,7 +1,6 @@ package com.plotsquared.sponge.util; import java.util.ArrayList; -import java.util.Locale; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.item.ItemType; @@ -105,7 +104,7 @@ public class SpongeInventoryUtil extends InventoryUtil { final Player player = sp.player; if (player.isViewingInventory()) { final CarriedInventory inventory = player.getInventory(); - return inv.getTitle().equals(inventory.getName().getTranslation().get(Locale.ENGLISH)); + return inv.getTitle().equals(inventory.getName().getId()); // TODO getId() } return false; } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeMetrics.java b/src/main/java/com/plotsquared/sponge/util/SpongeMetrics.java index 569c161fa..6a2a23c62 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeMetrics.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeMetrics.java @@ -185,7 +185,7 @@ public class SpongeMetrics { // Begin hitting the server with glorious data final TaskBuilder builder = game.getScheduler().createTaskBuilder(); - builder.async().interval(TimeUnit.MINUTES.toMillis(PING_INTERVAL)).execute(new Runnable() { + builder.async().interval(PING_INTERVAL, TimeUnit.MINUTES).execute(new Runnable() { private boolean firstPost = true; diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java index df3774109..0581b57a0 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java @@ -19,7 +19,7 @@ public class SpongeTaskManager extends TaskManager { public int taskRepeat(final Runnable r, final int interval) { final int val = i.incrementAndGet(); final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - final TaskBuilder built = builder.delay(interval).interval(interval).execute(r); + final TaskBuilder built = builder.delayTicks(interval).intervalTicks(interval).execute(r); final Task task = built.submit(SpongeMain.THIS.getPlugin()); tasks.put(val, task); return val; @@ -29,7 +29,7 @@ public class SpongeTaskManager extends TaskManager { public int taskRepeatAsync(final Runnable r, final int interval) { final int val = i.incrementAndGet(); final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - final TaskBuilder built = builder.delay(interval).async().interval(interval).execute(r); + final TaskBuilder built = builder.delayTicks(interval).async().intervalTicks(interval).execute(r); final Task task = built.submit(SpongeMain.THIS.getPlugin()); tasks.put(val, task); return val; @@ -50,13 +50,13 @@ public class SpongeTaskManager extends TaskManager { @Override public void taskLater(final Runnable r, final int delay) { final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - builder.delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin()); + builder.delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin()); } @Override public void taskLaterAsync(final Runnable r, final int delay) { final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - builder.async().delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin()); + builder.async().delayTicks(delay).execute(r).submit(SpongeMain.THIS.getPlugin()); } @Override diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index 16bbd3672..03b51a917 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ