From 05de6143ece8bff88c84b29c42fadf491afa7111 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 21 Nov 2017 20:57:57 +0000 Subject: [PATCH] Prevent deploy platform abuse --- .../arcade/game/games/cakewars/CakeWars.java | 27 +++++++++++++++++-- .../cakewars/general/CakePlayerModule.java | 13 ++++++++- .../cakewars/general/CakeSpawnerModule.java | 24 ++++++++++++----- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java index bef729185..c9d2af14c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java @@ -19,6 +19,7 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.Managers; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.leaderboard.DynamicLeaderboard; @@ -101,6 +102,7 @@ public class CakeWars extends TeamGame private final CakeTeamModule _cakeTeamModule; private final CakePlayerModule _cakePlayerModule; + private final CakeSpawnerModule _cakeSpawnerModule; private final CakeShopModule _cakeShopModule; private final ChestLootModule _chestLootModule; private final CustomScoreboardModule _customScoreboardModule; @@ -186,8 +188,8 @@ public class CakeWars extends TeamGame _cakePlayerModule = new CakePlayerModule(this); _cakePlayerModule.register(); - new CakeSpawnerModule(this) - .register(); + _cakeSpawnerModule = new CakeSpawnerModule(this); + _cakeSpawnerModule.register(); _cakeShopModule = new CakeShopModule(this); _cakeShopModule.register(); @@ -546,6 +548,22 @@ public class CakeWars extends TeamGame return _averages.get(team); } + public boolean isNearSpawn(Location location) + { + for (List locations : WorldData.SpawnLocs.values()) + { + for (Location spawn : locations) + { + if (UtilMath.offsetSquared(location, spawn) < 9) + { + return true; + } + } + } + + return false; + } + public ChestLootModule getChestLootModule() { return _chestLootModule; @@ -575,4 +593,9 @@ public class CakeWars extends TeamGame { return _cakeShopModule; } + + public CakeSpawnerModule getCakeSpawnerModule() + { + return _cakeSpawnerModule; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java index 3282bb790..9bf396826 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java @@ -153,6 +153,11 @@ public class CakePlayerModule extends CakeModule event.setCancelled(true); player.sendMessage(F.main("Game", "You cannot place a " + F.name(RUNE_OF_HOLDING.getItemMeta().getDisplayName()) + ".")); } + else if (_game.isNearSpawn(event.getBlock().getLocation())) + { + event.setCancelled(true); + player.sendMessage(F.main("Game", "You cannot place blocks that near ot a player spawn.")); + } } @EventHandler @@ -300,7 +305,13 @@ public class CakePlayerModule extends CakeModule Location nearbyLocation = nearby.getLocation(); - if (!UtilBlock.airFoliage(nearby) || _game.getCapturePointModule().isOnPoint(nearbyLocation) || _game.getCakeShopModule().isNearShop(nearbyLocation)) + if ( + !UtilBlock.airFoliage(nearby) || + _game.getCapturePointModule().isOnPoint(nearbyLocation) || + _game.getCakeShopModule().isNearShop(nearbyLocation) || + _game.getCakeSpawnerModule().isNearSpawner(nearbyLocation) || + _game.isNearSpawn(nearbyLocation) + ) { continue; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakeSpawnerModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakeSpawnerModule.java index 9f6fdd65c..e358d3a08 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakeSpawnerModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakeSpawnerModule.java @@ -48,14 +48,11 @@ public class CakeSpawnerModule extends CakeModule Location block = event.getBlock().getLocation(); - _game.getCakeTeamModule().getCakeTeams().forEach((team, cakeTeam) -> + if (isNearSpawner(block)) { - if (UtilMath.offsetSquared(block, cakeTeam.getGenerator()) < MIN_BLOCK_PLACE_DIST_SQUARED) - { - event.setCancelled(true); - event.getPlayer().sendMessage(F.main("Game", "You cannot place blocks that close to a generator.")); - } - }); + event.setCancelled(true); + event.getPlayer().sendMessage(F.main("Game", "You cannot place blocks that close to a generator.")); + } } @EventHandler @@ -200,4 +197,17 @@ public class CakeSpawnerModule extends CakeModule } } } + + public boolean isNearSpawner(Location location) + { + for (CakeTeam team : _game.getCakeTeamModule().getCakeTeams().values()) + { + if (UtilMath.offsetSquared(location, team.getGenerator()) < MIN_BLOCK_PLACE_DIST_SQUARED) + { + return true; + } + } + + return false; + } }