From 98ec99cffc761b26663b71f4a12b3d7671288059 Mon Sep 17 00:00:00 2001 From: Ty Sayers Date: Wed, 14 Oct 2015 16:06:34 -0400 Subject: [PATCH] Fix bug where players could retrieve teleport items out of the Travel Hub shop and later use them in their inventory. Implement a safe zone region of one chunk around all administrative clans (excluding Wilderness), to prevent players from building/claiming next to admin clans. Disable pistons throughout the server to prevent griefing. Fix left-over merge issue with donation manager. --- .../core/donation/DonationManager.java | 2 +- .../game/clans/clans/ClansUtility.java | 23 ++++++++++ .../clans/clans/commands/ClansCommand.java | 8 +++- .../game/clans/gameplay/Gameplay.java | 46 +++++++++++++++++++ .../game/clans/items/GearManager.java | 2 +- .../game/clans/spawn/travel/TravelShop.java | 27 +++++++++++ 6 files changed, 105 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 2b124dbc3..94d288b5d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -394,7 +394,7 @@ public class DonationManager extends MiniDbClientPlugin { public void run() { - rewardGold(callback, caller, player.getName(), ClientManager.getCachedClientAccountId(player.getUniqueId()), total, false); + rewardGold(callback, caller, player.getName(), ClientManager.getAccountId(player), total, false); } }); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java index 7b74ca122..d61cef18e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java @@ -300,6 +300,29 @@ public class ClansUtility return null; } + public boolean isNearAdminClaim(Location location) + { + for (int xOffset = -1; xOffset <= 1; xOffset++) + { + for (int zOffset = -1; zOffset <= 1; zOffset++) + { + if (xOffset == 0 && zOffset == 0) continue; + + String other = UtilWorld.chunkToStr(location.getWorld().getChunkAt( + location.getChunk().getX()+xOffset, location.getChunk().getZ()+zOffset)); + + ClanInfo adjClan = getOwner(other); + + if (adjClan != null && adjClan.isAdmin() && !adjClan.getName().equalsIgnoreCase("Wilderness")) + { + return true; + } + } + } + + return false; + } + public ClanInfo getOwner(ClanTerritory claim) { return getClanByClanName(claim.Owner); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index d14530742..77abf86cf 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -946,7 +946,13 @@ public class ClansCommand extends CommandBase return; } } - + + if (Plugin.getClanUtility().isNearAdminClaim(caller.getLocation())) + { + UtilPlayer.message(caller, F.main("Clans", "You cannot claim so close to administrative territory!")); + return; + } + //Not Next to Self if (!selfAdj && !clan.getClaimSet().isEmpty()) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 50e06b0b0..764887b57 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -49,6 +49,8 @@ import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -225,6 +227,26 @@ public class Gameplay extends MiniPlugin } } + /** + * Disable all Piston related events in Clans + * @param event + */ + @EventHandler + public void onPistonExtend(BlockPistonExtendEvent event) + { + event.setCancelled(true); + } + + /** + * Disable all Piston related events in Clans + * @param event + */ + @EventHandler + public void onPistonRetract(BlockPistonRetractEvent event) + { + event.setCancelled(true); + } + @EventHandler(priority = EventPriority.LOWEST) public void DispenseLiquidCancel(BlockDispenseEvent event) { @@ -463,6 +485,30 @@ public class Gameplay extends MiniPlugin event.setCancelled(true); } + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) + { + Location location = event.getBlock().getLocation(); + + if (_clansManager.getClanUtility().isNearAdminClaim(location)) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot place blocks near admin territories!")); + } + } + + @EventHandler + public void onBlockPlace(BlockBreakEvent event) + { + Location location = event.getBlock().getLocation(); + + if (_clansManager.getClanUtility().isNearAdminClaim(location)) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot break blocks near admin territories!")); + } + } + /* @EventHandler (priority = EventPriority.HIGHEST) public void MoneyLossSteal(CombatDeathEvent event) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index 5c32e9b57..51a2c0f0e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -40,7 +40,7 @@ import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory; import mineplex.serverdata.servers.ServerManager; import net.minecraft.server.v1_7_R4.Packet; import net.minecraft.server.v1_7_R4.PacketPlayOutSetSlot; -import net.minecraft.server.v1_7_R4.PacketPlayOutWindowItems; +import net.minecraft.server.v1_7_R4.PacketPlayOutWindowItems; import net.minecraft.util.com.google.common.collect.Sets; import org.bukkit.Bukkit; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelShop.java index f8ca082aa..9004e143b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelShop.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/travel/TravelShop.java @@ -2,7 +2,11 @@ package mineplex.game.clans.spawn.travel; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.inventory.ItemStack; + +import com.google.common.collect.Sets; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; @@ -15,6 +19,8 @@ import mineplex.game.clans.spawn.Spawn; public class TravelShop extends ShopBase { + public static final String[] TRAVEL_LOCATIONS = {"East Shop", "West Shop", "North Spawn", "South Spawn"}; + public TravelShop(ClansManager plugin, CoreClientManager clientManager, mineplex.core.donation.DonationManager donationManager) { super(plugin, clientManager, donationManager, "Travel Hub"); @@ -38,6 +44,27 @@ public class TravelShop extends ShopBase return super.attemptShopOpen(player); } + /** + * Destroy lone instances of Travel buttons that are fetched into a non-shop inventory (via lag) + * @param event + */ + @EventHandler + public void onInventoryClickedd(InventoryClickEvent event) + { + ItemStack item = event.getCurrentItem(); + if (item.getItemMeta() == null || item.getItemMeta().getDisplayName() == null) return; + else if (isPlayerInShop(event.getWhoClicked())) return; + + String displayName = event.getCurrentItem().getItemMeta().getDisplayName(); + for (String travelLocation : TRAVEL_LOCATIONS) + { + if (displayName.contains(travelLocation)) + { + event.setCurrentItem(null); + } + } + } + private static void notify(Player player, String message) { UtilPlayer.message(player, F.main("Travel Hub", message));