Prevent deploy platform abuse

This commit is contained in:
Sam 2017-11-21 20:57:57 +00:00 committed by Alexander Meech
parent 3aee4dc1f7
commit 05de6143ec
3 changed files with 54 additions and 10 deletions

View File

@ -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<Location> 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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}