use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onBucketFill.
@EventHandler(priority = EventPriority.LOW)
public void onBucketFill(final PlayerBucketFillEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (inWorld(e.getPlayer())) {
// This permission bypasses protection
if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
Island island = plugin.getGrid().getProtectedIslandAt(e.getBlockClicked().getLocation());
if (island != null) {
if (island.getMembers().contains(e.getPlayer().getUniqueId())) {
return;
}
if (island.getIgsFlag(SettingsFlag.COLLECT_LAVA) && e.getItemStack().getType().equals(Material.LAVA_BUCKET)) {
return;
}
if (island.getIgsFlag(SettingsFlag.COLLECT_WATER) && e.getItemStack().getType().equals(Material.WATER_BUCKET)) {
return;
}
if (island.getIgsFlag(SettingsFlag.MILKING) && e.getItemStack().getType().equals(Material.MILK_BUCKET)) {
return;
}
if (island.getIgsFlag(SettingsFlag.BUCKET)) {
return;
}
} else {
// Null
if (Settings.defaultWorldSettings.get(SettingsFlag.BUCKET)) {
return;
}
}
// Not allowed
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onBlockRedstone.
/**
* Stop redstone if team members are offline and disableOfflineRedstone is TRUE.
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockRedstone(final BlockRedstoneEvent e) {
if (Settings.disableOfflineRedstone) {
// Check world
if (!inWorld(e.getBlock())) {
return;
}
// Check if this is on an island
Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());
if (island == null || island.isSpawn()) {
return;
}
for (UUID member : island.getMembers()) {
if (plugin.getServer().getPlayer(member) != null)
return;
}
e.setNewCurrent(0);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onPlayerMove.
/**
* Adds island lock function
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent e) {
if (e.getPlayer().isDead()) {
return;
}
if (!inWorld(e.getPlayer())) {
return;
}
if (plugin.getGrid() == null) {
return;
}
// Only do something if there is a definite x or z movement
if (e.getTo().getBlockX() - e.getFrom().getBlockX() == 0 && e.getTo().getBlockZ() - e.getFrom().getBlockZ() == 0) {
return;
}
final Island islandTo = plugin.getGrid().getProtectedIslandAt(e.getTo());
// Announcement entering
final Island islandFrom = plugin.getGrid().getProtectedIslandAt(e.getFrom());
// plugin.getLogger().info("islandFrom = " + islandFrom);
if (islandTo != null && (islandTo.getOwner() != null || islandTo.isSpawn())) {
// Lock check
if (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), e.getPlayer().getUniqueId())) {
if (!islandTo.getMembers().contains(e.getPlayer().getUniqueId()) && !e.getPlayer().isOp() && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypasslock")) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).lockIslandLocked);
// Get the vector away from this island
if (e.getPlayer().isInsideVehicle()) {
if (e.getPlayer().getVehicle() instanceof LivingEntity) {
// Dismount
e.getPlayer().leaveVehicle();
e.setCancelled(true);
}
} else {
// Check if the player is within the border a lot
int minX = Math.max(islandTo.getMinProtectedX() - e.getTo().getBlockX(), e.getTo().getBlockX() - (islandTo.getMinProtectedX() + islandTo.getProtectionSize()));
int minZ = Math.max(islandTo.getMinProtectedZ() - e.getTo().getBlockZ(), e.getTo().getBlockZ() - (islandTo.getMinProtectedZ() + islandTo.getProtectionSize()));
int minMin = Math.max(minX, minZ);
// plugin.getLogger().info("DEBUG: " + minMin);
if (minMin < 1) {
Vector v = e.getPlayer().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2, 0, 1.2));
if (DEBUG)
plugin.getLogger().info("DEBUG: direction vector = " + v);
e.getPlayer().setVelocity(v);
}
if (minMin < -1) {
// Teleport player
plugin.getGrid().homeTeleport(e.getPlayer());
}
}
return;
}
}
}
if (islandTo != null && islandFrom == null) {
// Entering
if (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), e.getPlayer().getUniqueId())) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).lockIslandLocked);
}
if (islandTo.isSpawn()) {
if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn.isEmpty()) {
if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn);
}
}
} else {
if (islandTo.getOwner() != null && !plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.isEmpty()) {
if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
}
}
}
// Fire entry event
final IslandEnterEvent event = new IslandEnterEvent(e.getPlayer().getUniqueId(), islandTo, e.getTo());
plugin.getServer().getPluginManager().callEvent(event);
} else if (islandTo == null && islandFrom != null) {
// Leaving
if (islandFrom.isSpawn()) {
// Leaving
if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn.isEmpty()) {
if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn);
}
}
} else {
if (islandFrom.getOwner() != null && !plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.isEmpty()) {
if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
}
}
}
// Fire exit event
final IslandExitEvent event = new IslandExitEvent(e.getPlayer().getUniqueId(), islandFrom, e.getFrom());
plugin.getServer().getPluginManager().callEvent(event);
} else if (islandTo != null && !islandTo.equals(islandFrom)) {
// Adjacent islands or overlapping protections
if (islandFrom.isSpawn()) {
// Leaving
if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn);
}
} else if (islandFrom.getOwner() != null) {
if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
}
}
if (islandTo.isSpawn()) {
if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn);
}
} else if (islandTo.getOwner() != null) {
if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
}
}
// Fire exit event
final IslandExitEvent event = new IslandExitEvent(e.getPlayer().getUniqueId(), islandFrom, e.getFrom());
plugin.getServer().getPluginManager().callEvent(event);
// Fire entry event
final IslandEnterEvent event2 = new IslandEnterEvent(e.getPlayer().getUniqueId(), islandTo, e.getTo());
plugin.getServer().getPluginManager().callEvent(event2);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class EntityLimits method onMinecart.
/**
* Handles minecart placing
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onMinecart(VehicleCreateEvent e) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: " + e.getEventName());
plugin.getLogger().info("DEBUG: Vehicle type = " + e.getVehicle().getType());
}
if (!IslandGuard.inWorld(e.getVehicle())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Not in world");
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Checking entity types");
if (Settings.entityLimits.containsKey(e.getVehicle().getType())) {
// If someone in that area has the bypass permission, allow the spawning
for (Entity entity : e.getVehicle().getLocation().getWorld().getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) {
if (entity instanceof Player) {
Player player = (Player) entity;
Boolean bypass = false;
if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypass")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: op or bypass");
bypass = true;
}
// Check island
Island island = plugin.getGrid().getProtectedIslandAt(e.getVehicle().getLocation());
if (island == null) {
// Only count island entities
if (DEBUG)
plugin.getLogger().info("DEBUG: island is null");
return;
}
// Ignore spawn
if (island.isSpawn()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: ignore spawn");
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Checking entity limits");
// Check if the player is at the limit
if (atLimit(island, bypass, e.getVehicle())) {
e.setCancelled(true);
for (Entity ent : e.getVehicle().getLocation().getWorld().getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) {
if (ent instanceof Player) {
Util.sendMessage((Player) ent, ChatColor.RED + (plugin.myLocale(player.getUniqueId()).entityLimitReached.replace("[entity]", Util.prettifyText(e.getVehicle().getType().toString())).replace("[number]", String.valueOf(Settings.entityLimits.get(e.getVehicle().getType())))));
}
}
}
}
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class EntityLimits method onAnimalSpawn.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAnimalSpawn(final CreatureSpawnEvent e) {
// If not in the right world, return
if (!IslandGuard.inWorld(e.getEntity())) {
return;
}
// If not an animal
if (!(e.getEntity() instanceof Animals) && !e.getEntityType().equals(EntityType.SQUID)) {
return;
}
if (DEBUG2) {
plugin.getLogger().info("Animal spawn event! " + e.getEventName());
plugin.getLogger().info(e.getSpawnReason().toString());
plugin.getLogger().info(e.getEntityType().toString());
}
// If there's no limit - leave it
if (Settings.breedingLimit <= 0) {
if (DEBUG2)
plugin.getLogger().info("No limit on breeding or spawning");
return;
}
// We only care about spawning and breeding
if (e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.BREEDING && e.getSpawnReason() != SpawnReason.EGG && e.getSpawnReason() != SpawnReason.DISPENSE_EGG && e.getSpawnReason() != SpawnReason.SPAWNER_EGG && !e.getSpawnReason().name().contains("BABY")) {
if (DEBUG2)
plugin.getLogger().info("Not Spawner or breeding");
return;
}
LivingEntity animal = e.getEntity();
Island island = plugin.getGrid().getProtectedIslandAt(animal.getLocation());
if (island == null) {
// Animal is spawning outside of an island so ignore
if (DEBUG2)
plugin.getLogger().info("Outside island, so spawning is okay");
return;
}
// Count how many animals are there and who is the most likely spawner if it was a player
// This had to be reworked because the previous snowball approach doesn't work for large volumes
List<Player> culprits = new ArrayList<Player>();
boolean overLimit = false;
int animals = 0;
for (int x = island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
for (int z = island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
for (Entity entity : ASkyBlock.getIslandWorld().getChunkAt(x, z).getEntities()) {
if (entity instanceof Animals || entity.getType().equals(EntityType.SQUID)) {
if (DEBUG2)
plugin.getLogger().info("DEBUG: Animal count is " + animals);
animals++;
if (animals >= Settings.breedingLimit) {
// Delete any extra animals
overLimit = true;
animal.remove();
if (DEBUG2)
plugin.getLogger().info("Over limit! >=" + Settings.breedingLimit);
e.setCancelled(true);
}
} else if (entity instanceof Player && e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.DISPENSE_EGG) {
for (ItemStack itemInHand : Util.getPlayerInHandItems((Player) entity)) {
if (itemInHand != null) {
Material type = itemInHand.getType();
if (type == Material.EGG || type == Material.MONSTER_EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
if (DEBUG2)
plugin.getLogger().info("Player used egg or did breeding ");
if (!culprits.contains((Player) entity)) {
culprits.add(((Player) entity));
}
}
}
}
}
}
}
}
if (DEBUG2)
plugin.getLogger().info("Counting nether");
// Nether check
if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
for (int x = island.getMinProtectedX() / 16; x <= (island.getMinProtectedX() + island.getProtectionSize() - 1) / 16; x++) {
for (int z = island.getMinProtectedZ() / 16; z <= (island.getMinProtectedZ() + island.getProtectionSize() - 1) / 16; z++) {
for (Entity entity : ASkyBlock.getNetherWorld().getChunkAt(x, z).getEntities()) {
if (entity instanceof Animals || entity.getType().equals(EntityType.SQUID)) {
if (DEBUG2)
plugin.getLogger().info("DEBUG: Animal count is " + animals);
animals++;
if (animals >= Settings.breedingLimit) {
// Delete any extra animals
if (DEBUG2)
plugin.getLogger().info("Over limit! >=" + Settings.breedingLimit);
overLimit = true;
animal.remove();
e.setCancelled(true);
}
} else if (entity instanceof Player && e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.DISPENSE_EGG) {
for (ItemStack itemInHand : Util.getPlayerInHandItems(((Player) entity))) {
Material type = itemInHand.getType();
if (type == Material.EGG || type == Material.MONSTER_EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
if (!culprits.contains((Player) entity)) {
culprits.add(((Player) entity));
}
}
}
}
}
}
}
}
if (overLimit) {
if (e.getSpawnReason() != SpawnReason.SPAWNER) {
plugin.getLogger().warning("Island at " + island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ() + " hit the island animal breeding limit of " + Settings.breedingLimit);
for (Player player : culprits) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).moblimitsError.replace("[number]", String.valueOf(Settings.breedingLimit)));
plugin.getLogger().warning(player.getName() + " was trying to use " + Util.getPlayerInHandItems(player).toString());
}
}
}
// plugin.getLogger().info("DEBUG: Animal count is " + animals);
}
Aggregations