From 710b62fbf599b623d95ec27af7d632f78b208bbe Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 14 May 2015 01:49:57 +1000 Subject: [PATCH] Various fixes + pick block restriction Block picking in other plots will now limit block contents ( @xion87 you may be interested in this) Fixes - Cluster regeneration - world creation + cauldron - armor stand interaction in 1.8.0/1 --- PlotSquared/pom.xml | 2 +- .../intellectualcrafters/plot/BukkitMain.java | 4 + .../plot/commands/Cluster.java | 17 ++- .../plot/generator/HybridGen.java | 3 + .../plot/listeners/PlayerEvents_1_8.java | 131 +++++++++++++----- .../plot/listeners/PlayerEvents_1_8_3.java | 52 +++++++ .../plot/util/bukkit/UUIDHandler.java | 4 +- 7 files changed, 172 insertions(+), 41 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8_3.java diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 24a2aab2e..3ae0c7c3a 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.10.9 + 2.10.10 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 7b3c22874..af0fa85e2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -89,6 +89,7 @@ import com.intellectualcrafters.plot.listeners.ForceFieldListener; import com.intellectualcrafters.plot.listeners.InventoryListener; import com.intellectualcrafters.plot.listeners.PlayerEvents; import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8; +import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8_3; import com.intellectualcrafters.plot.listeners.PlotListener; import com.intellectualcrafters.plot.listeners.PlotPlusListener; import com.intellectualcrafters.plot.listeners.TNTListener; @@ -346,6 +347,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { if (checkVersion(1, 8, 0)) { getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this); } + if (checkVersion(1, 8, 3)) { + getServer().getPluginManager().registerEvents(new PlayerEvents_1_8_3(), this); + } } @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 5aad2d0d9..0a335f242 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -28,11 +28,13 @@ import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.generator.AugmentedPopulator; +import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotClusterId; +import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; @@ -134,10 +136,21 @@ public class Cluster extends SubCommand { DBFunc.setInvited(world, cluster, plot.owner); } } - if (!PlotSquared.isPlotWorld(world)) { + PlotWorld plotworld = PlotSquared.getPlotWorld(world); + if (plotworld == null) { PlotSquared.config.createSection("worlds." + world); PlotSquared.loadWorld(world, null); } + else { + final String gen_string = PlotSquared.config.getString("worlds." + world + "." + "generator.plugin"); + PlotGenerator generator; + if (gen_string == null) { + generator = new HybridGen(world); + } else { + generator = (PlotGenerator) PlotSquared.IMP.getGenerator(world, gen_string); + } + new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2); + } MainUtil.sendMessage(plr, C.CLUSTER_ADDED); return true; } @@ -189,8 +202,6 @@ public class Cluster extends SubCommand { if (plotworld.TYPE == 2) { AugmentedPopulator.removePopulator(plr.getLocation().getWorld(), cluster); } - for (final String set : ClusterManager.clusters.keySet()) { - } ClusterManager.last = null; ClusterManager.clusters.get(cluster.world).remove(cluster); ClusterManager.regenCluster(cluster); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 3c57d5918..f0881b794 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -83,6 +83,9 @@ public class HybridGen extends PlotGenerator { * Initialize variables, and create plotworld object used in calculations */ public void init(PlotWorld plotworld) { + if (plotworld != null) { + this.plotworld = (HybridPlotWorld) plotworld; + } this.plotsize = this.plotworld.PLOT_WIDTH; this.pathsize = this.plotworld.ROAD_WIDTH; this.roadblock = this.plotworld.ROAD_BLOCK.id; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java index df491fda0..d84f6fc1d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java @@ -1,16 +1,28 @@ package com.intellectualcrafters.plot.listeners; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.UUID; +import org.apache.commons.lang.StringUtils; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockExplodeEvent; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; @@ -24,6 +36,91 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public class PlayerEvents_1_8 extends PlotListener implements Listener { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onInventoryClick(InventoryClickEvent event) { + if (!event.isLeftClick() || event.getAction() != InventoryAction.PLACE_ALL || event.isShiftClick()) { + return; + } + HumanEntity entity = event.getWhoClicked(); + if (!(entity instanceof Player) || !PlotSquared.isPlotWorld(entity.getWorld().getName())) { + return; + } + Player player = (Player) entity; + PlayerInventory inv = player.getInventory(); + int slot = inv.getHeldItemSlot(); + if (slot != event.getSlot() || slot > 8 || !event.getEventName().equals("InventoryCreativeEvent")) { + return; + } + ItemStack current = inv.getItemInHand(); + ItemStack newItem = event.getCursor(); + ItemMeta newMeta = newItem.getItemMeta(); + ItemMeta oldMeta = newItem.getItemMeta(); + String newLore = ""; + if (newMeta != null) { + List lore = newMeta.getLore(); + if (lore != null) { + newLore = lore.toString(); + } + } + String oldLore = ""; + if (oldMeta != null) { + List lore = oldMeta.getLore(); + if (lore != null) { + oldLore = lore.toString(); + } + } + if (!newLore.equals("[(+NBT)]") || (current.equals(newItem) && newLore.equals(oldLore))) { + return; + } + HashSet blocks = null; + Block block = player.getTargetBlock(blocks, 7); + BlockState state = block.getState(); + if (state == null) { + return; + } + if (state.getType() != newItem.getType()) { + return; + } + final Location l = BukkitUtil.getLocation(state.getLocation()); + Plot plot = MainUtil.getPlot(l); + PlotPlayer pp = BukkitUtil.getPlayer(player); + boolean cancelled = false; + if (plot == null) { + if (!MainUtil.isPlotArea(l)) { + return; + } + if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road"); + cancelled = true; + } + } + else { + if (!plot.hasOwner()) { + if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.unowned"); + cancelled = true; + } + } + else { + final UUID uuid = pp.getUUID(); + if (!plot.isAdded(uuid)) { + if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.other"); + cancelled = true; + } + } + } + } + if (cancelled) { + if (current.getTypeId() == newItem.getTypeId() && current.getDurability() == newItem.getDurability()) { + event.setCursor(new ItemStack(newItem.getTypeId(), newItem.getAmount(), newItem.getDurability())); + event.setCancelled(true); + return; + } + event.setCursor(new ItemStack(newItem.getTypeId(), newItem.getAmount(), newItem.getDurability())); + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInteract(final PlayerInteractAtEntityEvent e) { Entity entity = e.getRightClicked(); @@ -64,38 +161,4 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener { } } } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBigBoom(final BlockExplodeEvent event) { - Block block = event.getBlock(); - Location loc = BukkitUtil.getLocation(block.getLocation()); - final String world = loc.getWorld(); - if (!PlotSquared.isPlotWorld(world)) { - return; - } - final Plot plot = MainUtil.getPlot(loc); - if ((plot != null) && plot.hasOwner()) { - if (FlagManager.isPlotFlagTrue(plot, "explosion")) { - final Iterator iter = event.blockList().iterator(); - while (iter.hasNext()) { - final Block b = iter.next(); - if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(b.getLocation())))) { - iter.remove(); - } - } - return; - } - } - if (MainUtil.isPlotArea(loc)) { - event.setCancelled(true); - } else { - final Iterator iter = event.blockList().iterator(); - while (iter.hasNext()) { - iter.next(); - if (MainUtil.isPlotArea(loc)) { - iter.remove(); - } - } - } - } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8_3.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8_3.java new file mode 100644 index 000000000..4f831df54 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8_3.java @@ -0,0 +1,52 @@ +package com.intellectualcrafters.plot.listeners; + +import java.util.Iterator; + +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockExplodeEvent; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; + +public class PlayerEvents_1_8_3 implements Listener { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBigBoom(final BlockExplodeEvent event) { + Block block = event.getBlock(); + Location loc = BukkitUtil.getLocation(block.getLocation()); + final String world = loc.getWorld(); + if (!PlotSquared.isPlotWorld(world)) { + return; + } + final Plot plot = MainUtil.getPlot(loc); + if ((plot != null) && plot.hasOwner()) { + if (FlagManager.isPlotFlagTrue(plot, "explosion")) { + final Iterator iter = event.blockList().iterator(); + while (iter.hasNext()) { + final Block b = iter.next(); + if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(b.getLocation())))) { + iter.remove(); + } + } + return; + } + } + if (MainUtil.isPlotArea(loc)) { + event.setCancelled(true); + } else { + final Iterator iter = event.blockList().iterator(); + while (iter.hasNext()) { + iter.next(); + if (MainUtil.isPlotArea(loc)) { + iter.remove(); + } + } + } + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java index 9cc2bcebc..d56b5fbe7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java @@ -112,6 +112,7 @@ public class UUIDHandler { } PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching: " + world); UUIDHandler.CACHED = true; + add(new StringWrapper("*"), DBFunc.everyone); if (Settings.TWIN_MODE_UUID) { HashSet all = getAllUUIDS(); final File playerdataFolder = new File(Bukkit.getWorldContainer(), world + File.separator + "playerdata"); @@ -136,7 +137,6 @@ public class UUIDHandler { } } } - add(new StringWrapper("*"), DBFunc.everyone); PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); return; } @@ -207,8 +207,6 @@ public class UUIDHandler { } } } - // add the Everyone '*' UUID - add(new StringWrapper("*"), DBFunc.everyone); PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); }