From f471a05dcd47a6a8f67fdc2c1ca5d2f1840ce5d7 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 17 Jul 2015 13:48:23 +1000 Subject: [PATCH] Fixes #405 --- pom.xml | 35 +-- .../intellectualcrafters/plot/BukkitMain.java | 3 + .../plot/commands/DebugUUID.java | 6 +- .../plot/database/SQLManager.java | 2 +- .../plot/listeners/PlayerEvents.java | 279 ++++++++++-------- .../plot/object/Plot.java | 20 +- .../plot/util/SetBlockQueue.java | 10 +- 7 files changed, 182 insertions(+), 173 deletions(-) diff --git a/pom.xml b/pom.xml index 3e3d9f048..2952f421c 100644 --- a/pom.xml +++ b/pom.xml @@ -45,33 +45,14 @@ 1.7 - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - -Xdoclint:none - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + -Xdoclint:none + + diff --git a/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index be30bc267..18a19eae7 100644 --- a/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -13,6 +13,8 @@ import java.util.Stack; import java.util.UUID; import com.intellectualcrafters.plot.commands.*; + +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; @@ -108,6 +110,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { version[2] = Integer.parseInt(split[2]); } } catch (Exception e) { + e.printStackTrace(); return false; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java index 7d95dc9ef..83e17426f 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java @@ -221,9 +221,9 @@ public class DebugUUID extends SubCommand { if (value != null) { plot.owner = value; } - plot.trusted = new ArrayList<>(); - plot.members = new ArrayList<>(); - plot.denied = new ArrayList<>(); + plot.trusted = new HashSet<>(); + plot.members = new HashSet<>(); + plot.denied = new HashSet<>(); } MainUtil.sendConsoleMessage("&7 - Deleting database"); diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 32d8f5e5b..d3764a754 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -935,7 +935,7 @@ public class SQLManager implements AbstractDB { user = UUID.fromString(o); uuids.put(o, user); } - p = new Plot(plot_id, user, new ArrayList(), new ArrayList(), new ArrayList(), "", null, null, worldname, new boolean[]{false, false, false, false}); + p = new Plot(plot_id, user, new HashSet(), new HashSet(), new HashSet(), "", null, null, worldname, new boolean[]{false, false, false, false}); plots.put(id, p); } if (Settings.CACHE_RATINGS) { diff --git a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 6d0492a35..9000a91ff 100644 --- a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -19,18 +19,18 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Animals; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Hanging; import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.Tameable; -import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.Vehicle; import org.bukkit.entity.minecart.RideableMinecart; import org.bukkit.event.EventHandler; @@ -60,7 +60,6 @@ import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.painting.PaintingBreakEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; @@ -73,15 +72,11 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerUnleashEntityEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; @@ -206,8 +201,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi case POWERED_RAIL: { return; } + default: { + event.setNewCurrent(0); + } } - event.setNewCurrent(0); } @EventHandler @@ -234,6 +231,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi event.setCancelled(true); return; } + default: { + break; + } } if (block.getType().hasGravity()) { Plot plot = MainUtil.getPlot(loc); @@ -358,8 +358,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi public void PlayerMove(final PlayerMoveEvent event) { org.bukkit.Location from = event.getFrom(); org.bukkit.Location to = event.getTo(); - int x1, x2; - if ((x1 = (int) from.getX()) != (x2 = (int) to.getX()) ) { + int x2; + if (from.getX() != (x2 = (int) to.getX()) ) { String worldname = to.getWorld().getName(); PlotWorld plotworld = PS.get().getPlotWorld(worldname); if (plotworld == null) { @@ -421,8 +421,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } return; } - int z1, z2; - if ((z1 = (int) from.getZ()) != (z2 = (int) to.getZ()) ) { + int z2; + if ((int) from.getZ() != (z2 = (int) to.getZ()) ) { String worldname = to.getWorld().getName(); PlotWorld plotworld = PS.get().getPlotWorld(worldname); if (plotworld == null) { @@ -980,6 +980,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi eventType = PlayerBlockEventType.TELEPORT_OBJECT; break; } + default: { + break; + } } lb = new BukkitLazyBlock(blockId, block); ItemStack hand = player.getItemInHand(); @@ -991,8 +994,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi lb = new BukkitLazyBlock(block); break; } - - // TODO calls both: // redstone ore @@ -1004,6 +1005,11 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi break; } + case ARMOR_STAND: { + eventType = PlayerBlockEventType.PLACE_MISC; + break; + } + case WRITTEN_BOOK: case BOOK_AND_QUILL: case BOOK: { @@ -1051,14 +1057,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi eventType = PlayerBlockEventType.PLACE_HANGING; break; } - - case ARMOR_STAND: { - eventType = PlayerBlockEventType.PLACE_MISC; - break; - } - default: { eventType = PlayerBlockEventType.INTERACT_BLOCK; + break; } } break; @@ -1641,122 +1642,144 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } } - + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityDamageByEntityEvent(final EntityDamageByEntityEvent e) { final Location l = BukkitUtil.getLocation(e.getEntity()); + if (!PS.get().isPlotWorld(l.getWorld())) { + return; + } final Entity damager = e.getDamager(); final Entity victim = e.getEntity(); - if ((Settings.TELEPORT_DELAY != 0) && (TaskManager.TELEPORT_QUEUE.size() > 0) && (victim instanceof Player)) { - final Player player = (Player) victim; - final String name = player.getName(); - if (TaskManager.TELEPORT_QUEUE.contains(name)) { - TaskManager.TELEPORT_QUEUE.remove(name); - } - } - if (PS.get().isPlotWorld(l.getWorld())) { - Player p = null; - Projectile projectile = null; - if (damager instanceof Player) { - p = (Player) damager; - } - else if (damager instanceof Projectile) { - projectile = (Projectile) damager; - //Arrow, Egg, EnderPearl, Fireball, Fish, FishHook, LargeFireball, SmallFireball, Snowball, ThrownExpBottle, ThrownPotion, WitherSkull - if (damager instanceof Projectile) { - if (damager instanceof ThrownPotion) { - ThrownPotion potion = (ThrownPotion) damager; - Collection effects = potion.getEffects(); - for (PotionEffect effect : effects) { - PotionEffectType type = effect.getType(); - if (type == PotionEffectType.BLINDNESS || type == PotionEffectType.CONFUSION || type == PotionEffectType.HARM || type == PotionEffectType.INVISIBILITY || type == PotionEffectType.POISON || type == PotionEffectType.SLOW || type == PotionEffectType.SLOW_DIGGING || type == PotionEffectType.WEAKNESS || type == PotionEffectType.WITHER) { - ProjectileSource shooter = ((Projectile) damager).getShooter(); - if (shooter == null || !(shooter instanceof Player)) { - return; - } - p = (Player) shooter; - break; - } - } - } - else { - ProjectileSource shooter = projectile.getShooter(); - if (shooter == null || !(shooter instanceof Player)) { - return; - } - p = (Player) shooter; - } - } - else { - return; - } - } - if (p != null) { - final boolean aPlr = victim instanceof Player; - final PlotWorld pW = PS.get().getPlotWorld(l.getWorld()); - if (!aPlr && pW.PVE && (!(victim instanceof ItemFrame) && !(victim.getType().getTypeId() == 30))) { - return; - } else if (aPlr && pW.PVP) { - return; - } - Plot plot = MainUtil.getPlot(l); - if (plot == null) { - if (!MainUtil.isPlotAreaAbs(l)) { - return; - } - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!Permissions.hasPermission(pp, "plots.admin.pve.road")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.road"); - e.setCancelled(true); - return; - } - } else { - if (!plot.hasOwner()) { - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!Permissions.hasPermission(pp, "plots.admin.pve.unowned")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.unowned"); - if (projectile != null) { - projectile.remove(); - } - e.setCancelled(true); - return; - } - return; - } else if (aPlr && FlagManager.isPlotFlagTrue(plot, "pvp")) { - return; - } - if (!aPlr && FlagManager.isPlotFlagTrue(plot, "pve")) { - return; - } - assert plot != null; - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!plot.isAdded(pp.getUUID())) { - if ((victim instanceof Monster) && FlagManager.isPlotFlagTrue(plot, "hostile-attack")) { - return; - } - if ((victim instanceof Animals) && FlagManager.isPlotFlagTrue(plot, "animal-attack")) { - return; - } - if ((victim instanceof Tameable) && ((Tameable) victim).isTamed() && FlagManager.isPlotFlagTrue(plot, "tamed-attack")) { - return; - } - if (!Permissions.hasPermission(pp, "plots.admin.pve.other")) { - if (MainUtil.isPlotArea(l)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.other"); - if (projectile != null) { - projectile.remove(); - } - e.setCancelled(true); - return; - } - } - } - } + + Location dloc = BukkitUtil.getLocation(damager); + Location vloc = BukkitUtil.getLocation(victim); + + Plot dplot = MainUtil.getPlot(dloc); + Plot vplot = MainUtil.getPlot(vloc); + + Plot plot; + String stub; + if (dplot == null && vplot == null) { + if (!MainUtil.isPlotAreaAbs(dloc)) { return; } - if ((damager instanceof Arrow) && MainUtil.isPlotArea(l) && (!(victim instanceof Creature))) { - e.setCancelled(true); + plot = null; + stub = "road"; + } + else { + // Priorize plots for close to seamless pvp zones + plot = vplot == null ? dplot : ((dplot == null || victim instanceof Player) ? vplot : (victim.getTicksLived() > damager.getTicksLived() ? dplot : vplot)); + stub = plot.hasOwner() ? "other" : "unowned"; + } + + Player player; + if (damager instanceof Player) { // attacker is player + player = (Player) damager; + } + else if (damager instanceof Projectile) { + Projectile projectile = (Projectile) damager; + ProjectileSource shooter = projectile.getShooter(); + if (shooter.getClass() == Player.class) { // shooter is player + player = (Player) shooter; } + else { // shooter is not player + player = null; + } + } + else { // Attacker is not player + player = null; + } + + if (player != null) { + PlotPlayer pp = BukkitUtil.getPlayer(player); + if (victim instanceof Hanging) { // hanging + if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hanging-break") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) { + return; + } + if (!Permissions.hasPermission(pp, "plots.admin.break." + stub)) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.break." + stub); + return; + } + } + else if (victim instanceof ArmorStand) { + if (plot != null && (FlagManager.isPlotFlagTrue(plot, "misc-break") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) { + return; + } + if (!Permissions.hasPermission(pp, "plots.admin.break." + stub)) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.break." + stub); + return; + } + } + else if (victim instanceof Monster) { // victim is monster + if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hostile-break") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) { + return; + } + if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve." + stub); + return; + } + } + else if (victim instanceof Tameable) { // victim is tameable + if (plot != null && (FlagManager.isPlotFlagTrue(plot, "tamed-break") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) { + return; + } + if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve." + stub); + return; + } + } + else if (victim instanceof Animals) { // victim is animal + if (plot != null && (FlagManager.isPlotFlagTrue(plot, "animal-break") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) { + return; + } + if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve." + stub); + return; + } + } + else if (victim instanceof Player) { + if (plot != null) { + Flag pvp = FlagManager.getPlotFlag(plot, "pvp"); + if (pvp == null) { + if (victim.getTicksLived() > damager.getTicksLived() ? plot.isAdded(BukkitUtil.getPlayer((Player) victim).getUUID()) : plot.isAdded(pp.getUUID())) { + return; + } + } else { + if ((Boolean) pvp.getValue()) { + return; + } + } + } + if (!Permissions.hasPermission(pp, "plots.admin.pvp." + stub)) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pvp." + stub); + return; + } + } + else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event + return; + } + else { // victim is something else + if (!Permissions.hasPermission(pp, "plots.admin.pvp." + stub)) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pvp." + stub); + return; + } + if (plot != null && FlagManager.isPlotFlagTrue(plot, "pvp")) { + return; + } + } + return; + } + // player is null + if ((damager instanceof Arrow) && (!(victim instanceof Creature))) { + e.setCancelled(true); } } diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index ed263f75c..4bf029e18 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -56,15 +56,15 @@ public class Plot implements Cloneable { /** * List of trusted (with plot permissions) */ - public ArrayList trusted; + public HashSet trusted; /** * List of members users (with plot permissions) */ - public ArrayList members; + public HashSet members; /** * List of denied players */ - public ArrayList denied; + public HashSet denied; /** * External settings class
* - Please favor the methods over direct access to this class
@@ -94,9 +94,9 @@ public class Plot implements Cloneable { this.id = id; this.owner = owner; this.settings = new PlotSettings(this); - this.trusted = new ArrayList<>(); - this.members = new ArrayList<>(); - this.denied = new ArrayList<>(); + this.trusted = new HashSet<>(); + this.members = new HashSet<>(); + this.denied = new HashSet<>(); this.temp = false; } @@ -113,9 +113,9 @@ public class Plot implements Cloneable { this.id = id; this.owner = owner; this.settings = new PlotSettings(this); - this.trusted = new ArrayList<>(); - this.members = new ArrayList<>(); - this.denied = new ArrayList<>(); + this.trusted = new HashSet<>(); + this.members = new HashSet<>(); + this.denied = new HashSet<>(); this.temp = temp; } @@ -128,7 +128,7 @@ public class Plot implements Cloneable { * @param denied * @param merged */ - public Plot(final PlotId id, final UUID owner, final ArrayList trusted, final ArrayList members, final ArrayList denied, final String alias, final BlockLoc position, final Collection flags, final String world, final boolean[] merged) { + public Plot(final PlotId id, final UUID owner, final HashSet trusted, final HashSet members, final HashSet denied, final String alias, final BlockLoc position, final Collection flags, final String world, final boolean[] merged) { this.id = id; this.settings = new PlotSettings(this); this.owner = owner; diff --git a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java index c1d92eaee..d73259a2d 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java +++ b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java @@ -61,13 +61,15 @@ public class SetBlockQueue { if (locked) { return; } - if (blocks.size() == 0) { + if (blocks == null || blocks.size() == 0) { PS.get().TASK.cancelTask(TaskManager.tasks.get(current)); - for (Runnable runnable : runnables) { - TaskManager.runTask(runnable); + if (runnables != null) { + for (Runnable runnable : runnables) { + TaskManager.runTask(runnable); + } } runnables = null; - blocks = null; + blocks = new HashMap<>(); running = false; slow = false; return;