use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onSplashPotionSplash.
/**
* Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them.
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSplashPotionSplash(final PotionSplashEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info("splash entity = " + e.getEntity());
plugin.getLogger().info("splash entity type = " + e.getEntityType());
plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities());
// plugin.getLogger().info("splash hit entity = " + e.getHitEntity());
}
if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
return;
}
// Try to get the shooter
Projectile projectile = e.getEntity();
if (DEBUG)
plugin.getLogger().info("splash shooter = " + projectile.getShooter());
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
Player attacker = (Player) projectile.getShooter();
// Run through all the affected entities
for (LivingEntity entity : e.getAffectedEntities()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: affected splash entity = " + entity);
// Self damage
if (attacker.equals(entity)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Self damage from splash potion!");
continue;
}
Island island = plugin.getGrid().getIslandAt(entity.getLocation());
boolean inNether = false;
if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) {
inNether = true;
}
// Monsters being hurt
if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
// Normal island check
if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
// Members always allowed
continue;
}
if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) {
continue;
}
// Not allowed
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
// Mobs being hurt
if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) {
if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
continue;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
// Establish whether PVP is allowed or not.
boolean pvp = false;
if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) {
if (DEBUG)
plugin.getLogger().info("DEBUG: PVP allowed");
pvp = true;
}
// Players being hurt PvP
if (entity instanceof Player) {
if (pvp) {
if (DEBUG)
plugin.getLogger().info("DEBUG: PVP allowed");
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: PVP not allowed");
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
e.setCancelled(true);
return;
}
}
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onTNTPrimed.
/**
* Trap TNT being primed by flaming arrows
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTNTPrimed(final EntityChangeBlockEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info("DEBUG: block = " + e.getBlock().getType());
plugin.getLogger().info("DEBUG: entity = " + e.getEntityType());
plugin.getLogger().info("DEBUG: material changing to " + e.getTo());
}
if (actionAllowed(e.getEntity().getLocation(), SettingsFlag.FIRE)) {
return;
}
if (e.getBlock() == null) {
return;
}
// Check for TNT
if (!e.getBlock().getType().equals(Material.TNT)) {
// plugin.getLogger().info("DEBUG: not tnt");
return;
}
// 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;
}
// Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
if (e.getEntity() instanceof Projectile) {
// plugin.getLogger().info("DEBUG: projectile");
Projectile projectile = (Projectile) e.getEntity();
// Find out who fired it
if (projectile.getShooter() instanceof Player) {
// plugin.getLogger().info("DEBUG: player shot arrow. Fire ticks = " + projectile.getFireTicks());
if (projectile.getFireTicks() > 0) {
// plugin.getLogger().info("DEBUG: arrow on fire");
Player shooter = (Player) projectile.getShooter();
if (!plugin.getGrid().locationIsAtHome(shooter, true, e.getBlock().getLocation())) {
// Debounce event (it can be called twice for the same action)
if (!tntBlocks.contains(e.getBlock().getLocation())) {
Util.sendMessage(shooter, ChatColor.RED + plugin.myLocale(shooter.getUniqueId()).islandProtected);
tntBlocks.add(e.getBlock().getLocation());
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
tntBlocks.remove(e.getBlock().getLocation());
}
}, 20L);
}
// Remove the arrow
projectile.remove();
e.setCancelled(true);
}
}
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onPistonExtend.
@EventHandler(priority = EventPriority.LOW)
public void onPistonExtend(BlockPistonExtendEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
Location pistonLoc = e.getBlock().getLocation();
if (Settings.allowPistonPush || !inWorld(pistonLoc)) {
// plugin.getLogger().info("DEBUG: Not in world");
return;
}
Island island = plugin.getGrid().getProtectedIslandAt(pistonLoc);
if (island == null || !island.onIsland(pistonLoc)) {
// plugin.getLogger().info("DEBUG: Not on is island protection zone");
return;
}
// We need to check where the blocks are going to go, not where they are
for (Block b : e.getBlocks()) {
if (!island.onIsland(b.getRelative(e.getDirection()).getLocation())) {
// plugin.getLogger().info("DEBUG: Block is outside protected area");
e.setCancelled(true);
return;
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class SafeSpotTeleport method getChunksToScan.
/**
* Gets a set of chunk coords that will be scanned.
* @param entity
* @param location
* @return
*/
private List<Pair<Integer, Integer>> getChunksToScan() {
List<Pair<Integer, Integer>> result = new ArrayList<>();
// Get island if available
Island island = plugin.getGrid().getIslandAt(location);
int maxRadius = island == null ? Settings.islandProtectionRange / 2 : island.getProtectionSize() / 2;
maxRadius = maxRadius > MAX_RADIUS ? MAX_RADIUS : maxRadius;
int x = location.getBlockX();
int z = location.getBlockZ();
// Create ever increasing squares around the target location
int radius = 0;
do {
for (int i = x - radius; i <= x + radius; i += 16) {
for (int j = z - radius; j <= z + radius; j += 16) {
addChunk(result, island, new Pair<>(i, j), new Pair<>(i / 16, j / 16));
}
}
radius++;
} while (radius < maxRadius);
return result;
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard1_8 method placeArmorStandEvent.
// Armor stand events
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
void placeArmorStandEvent(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (DEBUG) {
plugin.getLogger().info("1.8 " + "Armor stand place " + e.getEventName());
}
if (!IslandGuard.inWorld(p)) {
return;
}
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
// You can do anything if you are Op
return;
}
// Check if they are holding armor stand
for (ItemStack inHand : Util.getPlayerInHandItems(e.getPlayer())) {
if (inHand.getType().equals(Material.ARMOR_STAND)) {
// Check island
Island island = plugin.getGrid().getIslandAt(e.getPlayer().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
return;
}
if (island != null && (island.getMembers().contains(p.getUniqueId()) || island.getIgsFlag(SettingsFlag.PLACE_BLOCKS))) {
// plugin.getLogger().info("1.8 " + "DEBUG: armor stand place check");
if (Settings.limitedBlocks.containsKey("ARMOR_STAND") && Settings.limitedBlocks.get("ARMOR_STAND") > -1) {
// plugin.getLogger().info("1.8 " + "DEBUG: count armor stands");
int count = island.getTileEntityCount(Material.ARMOR_STAND, e.getPlayer().getWorld());
// plugin.getLogger().info("1.8 " + "DEBUG: count is " + count + " limit is " + Settings.limitedBlocks.get("ARMOR_STAND"));
if (Settings.limitedBlocks.get("ARMOR_STAND") <= count) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]", Util.prettifyText(Material.ARMOR_STAND.toString()))).replace("[number]", String.valueOf(Settings.limitedBlocks.get("ARMOR_STAND"))));
e.setCancelled(true);
return;
}
}
return;
}
// plugin.getLogger().info("1.8 " + "DEBUG: stand place cancelled");
e.setCancelled(true);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.getPlayer().updateInventory();
}
}
}
Aggregations