mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 12:15:12 +01:00
Added more protection listeners.
Flying mobs, visitor protection
This commit is contained in:
parent
87ab500706
commit
1635eee285
@ -224,5 +224,6 @@ public class Settings {
|
||||
public static HashMap<String,Integer> limitedBlocks;
|
||||
public static boolean allowTNTPushing;
|
||||
public static boolean showInActionBar;
|
||||
public static boolean allowVisitorKeepInvOnDeath;
|
||||
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ public class IslandsManager {
|
||||
return null;
|
||||
}
|
||||
// World check
|
||||
if (!inWorld(location)) {
|
||||
if (!Util.inWorld(location)) {
|
||||
//plugin.getLogger().info("DEBUG: not in right world");
|
||||
return null;
|
||||
}
|
||||
@ -455,28 +455,6 @@ public class IslandsManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if a location is in the island world or not or
|
||||
* in the new nether if it is activated
|
||||
* @param loc
|
||||
* @return true if in the island world
|
||||
*/
|
||||
protected boolean inWorld(Location loc) {
|
||||
if (loc != null) {
|
||||
if (loc.getWorld().equals(IslandWorld.getIslandWorld())) {
|
||||
return true;
|
||||
}
|
||||
if (Settings.netherIslands && loc.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
return true;
|
||||
}
|
||||
if (Settings.endIslands && loc.getWorld().equals(IslandWorld.getEndWorld())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerUUID
|
||||
* @return true if player has island
|
||||
@ -1305,4 +1283,14 @@ public class IslandsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the spawnPoint or null if spawn does not exist
|
||||
*/
|
||||
public Location getSpawnPoint() {
|
||||
//plugin.getLogger().info("DEBUG: getting spawn point : " + spawn.getSpawnPoint());
|
||||
if (spawn == null)
|
||||
return null;
|
||||
return spawn.getSpawnPoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.entity.Entity;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandLockEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandUnlockEvent;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* Stores all the info about an island
|
||||
@ -358,6 +359,8 @@ public class Island extends DataObject {
|
||||
|
||||
private int levelHandicap;
|
||||
|
||||
private Location spawnPoint;
|
||||
|
||||
public Island() {};
|
||||
|
||||
public Island(Location location, UUID owner, int protectionRange) {
|
||||
@ -912,4 +915,20 @@ public class Island extends DataObject {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean inIslandSpace(Location location) {
|
||||
if (Util.inWorld(location)) {
|
||||
return inIslandSpace(location.getBlockX(), location.getBlockZ());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSpawnPoint(Location location) {
|
||||
spawnPoint = location;
|
||||
|
||||
}
|
||||
|
||||
public Location getSpawnPoint() {
|
||||
return spawnPoint;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
package us.tastybento.bskyblock.listeners.protection;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Wither;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* This class manages flying mobs. If they exist the spawned island's limits they will be removed.
|
||||
*
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class FlyingMobEvents implements Listener {
|
||||
private final BSkyBlock plugin;
|
||||
private final static boolean DEBUG = false;
|
||||
private WeakHashMap<Entity, Island> mobSpawnInfo;
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
*/
|
||||
public FlyingMobEvents(BSkyBlock plugin) {
|
||||
this.plugin = plugin;
|
||||
this.mobSpawnInfo = new WeakHashMap<Entity, Island>();
|
||||
new BukkitRunnable() {
|
||||
|
||||
public void run() {
|
||||
//Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size());
|
||||
Iterator<Entry<Entity, Island>> it = mobSpawnInfo.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<Entity, Island> entry = it.next();
|
||||
if (entry.getKey() == null) {
|
||||
//Bukkit.getLogger().info("DEBUG: removing null entity");
|
||||
it.remove();
|
||||
} else {
|
||||
if (entry.getKey() instanceof LivingEntity) {
|
||||
if (!entry.getValue().inIslandSpace(entry.getKey().getLocation())) {
|
||||
//Bukkit.getLogger().info("DEBUG: removing entity outside of island");
|
||||
it.remove();
|
||||
// Kill mob
|
||||
LivingEntity mob = (LivingEntity)entry.getKey();
|
||||
mob.setHealth(0);
|
||||
entry.getKey().remove();
|
||||
} else {
|
||||
//Bukkit.getLogger().info("DEBUG: entity " + entry.getKey().getName() + " is in island space");
|
||||
}
|
||||
} else {
|
||||
// Not living entity
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}.runTaskTimer(plugin, 20L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Track where the mob was created. This will determine its allowable movement zone.
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void mobSpawn(CreatureSpawnEvent e) {
|
||||
// Only cover withers in the island world
|
||||
if (!Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
if (!e.getEntityType().equals(EntityType.WITHER) && !e.getEntityType().equals(EntityType.BLAZE) && !e.getEntityType().equals(EntityType.GHAST)) {
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("Flying mobs " + e.getEventName());
|
||||
}
|
||||
// Store where this mob originated
|
||||
Island island = plugin.getIslands().getIslandAt(e.getLocation());
|
||||
if (island != null) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: Mob spawned on known island - id = " + e.getEntity().getUniqueId());
|
||||
}
|
||||
mobSpawnInfo.put(e.getEntity(),island);
|
||||
} // Else do nothing - maybe an Op spawned it? If so, on their head be it!
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void MobExplosion(EntityExplodeEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
// Only cover in the island world
|
||||
if (e.getEntity() == null || !Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
if (mobSpawnInfo.containsKey(e.getEntity().getUniqueId())) {
|
||||
// We know about this mob
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: We know about this mob");
|
||||
}
|
||||
if (!mobSpawnInfo.get(e.getEntity().getUniqueId()).inIslandSpace(e.getLocation())) {
|
||||
// Cancel the explosion and block damage
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: cancel flying mob explosion");
|
||||
}
|
||||
e.blockList().clear();
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with pre-explosions
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void WitherExplode(ExplosionPrimeEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
// Only cover withers in the island world
|
||||
if (!Util.inWorld(e.getEntity()) || e.getEntity() == null) {
|
||||
return;
|
||||
}
|
||||
// The wither or wither skulls can both blow up
|
||||
if (e.getEntityType() == EntityType.WITHER) {
|
||||
//plugin.getLogger().info("DEBUG: Wither");
|
||||
// Check the location
|
||||
if (mobSpawnInfo.containsKey(e.getEntity().getUniqueId())) {
|
||||
// We know about this wither
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: We know about this wither");
|
||||
}
|
||||
if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) {
|
||||
// Cancel the explosion
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: cancelling wither pre-explosion");
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
// Testing only e.setCancelled(true);
|
||||
}
|
||||
if (e.getEntityType() == EntityType.WITHER_SKULL) {
|
||||
//plugin.getLogger().info("DEBUG: Wither skull");
|
||||
// Get shooter
|
||||
Projectile projectile = (Projectile)e.getEntity();
|
||||
if (projectile.getShooter() instanceof Wither) {
|
||||
//plugin.getLogger().info("DEBUG: shooter is wither");
|
||||
Wither wither = (Wither)projectile.getShooter();
|
||||
// Check the location
|
||||
if (mobSpawnInfo.containsKey(wither.getUniqueId())) {
|
||||
// We know about this wither
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: We know about this wither");
|
||||
}
|
||||
if (!mobSpawnInfo.get(wither.getUniqueId()).inIslandSpace(e.getEntity().getLocation())) {
|
||||
// Cancel the explosion
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: cancel wither skull explosion");
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Withers change blocks to air after they are hit (don't know why)
|
||||
* This prevents this when the wither has been spawned by a visitor
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void WitherChangeBlocks(EntityChangeBlockEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
// Only cover withers in the island world
|
||||
if (e.getEntityType() != EntityType.WITHER || !Util.inWorld(e.getEntity()) ) {
|
||||
return;
|
||||
}
|
||||
if (mobSpawnInfo.containsKey(e.getEntity())) {
|
||||
// We know about this wither
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: We know about this wither");
|
||||
}
|
||||
if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) {
|
||||
// Cancel the block changes
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: cancelled wither block change");
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the hashmap. It's probably not needed, but just in case.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void MobDeath(EntityDeathEvent e) {
|
||||
mobSpawnInfo.remove(e.getEntity());
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package us.tastybento.bskyblock.listeners.protection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
|
||||
/**
|
||||
* Stashes inventories when required for a player
|
||||
*
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class InventorySave {
|
||||
private static InventorySave instance = new InventorySave(BSkyBlock.getPlugin());
|
||||
private HashMap<UUID, InventoryStore> inventories;
|
||||
|
||||
/**
|
||||
* Saves the inventory of a player
|
||||
*/
|
||||
public InventorySave(BSkyBlock plugin) {
|
||||
inventories = new HashMap<UUID, InventoryStore>();
|
||||
}
|
||||
|
||||
/** Save player's inventory
|
||||
* @param player
|
||||
*/
|
||||
public void savePlayerInventory(Player player) {
|
||||
//plugin.getLogger().info("DEBUG: Saving inventory");
|
||||
// Save the player's armor and things
|
||||
inventories.put(player.getUniqueId(),new InventoryStore(player.getInventory().getContents(), player.getInventory().getArmorContents()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears any saved inventory
|
||||
* @param player
|
||||
*/
|
||||
public void clearSavedInventory(Player player) {
|
||||
//plugin.getLogger().info("DEBUG: Clearing inventory");
|
||||
inventories.remove(player.getUniqueId());
|
||||
}
|
||||
/**
|
||||
* Load the player's inventory
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void loadPlayerInventory(Player player) {
|
||||
//plugin.getLogger().info("DEBUG: Loading inventory");
|
||||
// Get the info for this player
|
||||
if (inventories.containsKey(player.getUniqueId())) {
|
||||
InventoryStore inv = inventories.get(player.getUniqueId());
|
||||
//plugin.getLogger().info("DEBUG: player is known");
|
||||
player.getInventory().setContents(inv.getInventory());
|
||||
player.getInventory().setArmorContents(inv.getArmor());
|
||||
inventories.remove(player.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static InventorySave getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package us.tastybento.bskyblock.listeners.protection;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Where the inventory data is stored
|
||||
*
|
||||
* @author tastybento
|
||||
*/
|
||||
public class InventoryStore {
|
||||
private ItemStack[] inventory;
|
||||
private ItemStack[] armor;
|
||||
|
||||
/**
|
||||
* @param inventory
|
||||
* @param armor
|
||||
*/
|
||||
public InventoryStore(ItemStack[] inventory, ItemStack[] armor) {
|
||||
this.inventory = inventory;
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inventory
|
||||
*/
|
||||
public ItemStack[] getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inventory
|
||||
* the inventory to set
|
||||
*/
|
||||
public void setInventory(ItemStack[] inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the armor
|
||||
*/
|
||||
public ItemStack[] getArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param armor
|
||||
* the armor to set
|
||||
*/
|
||||
public void setArmor(ItemStack[] armor) {
|
||||
this.armor = armor;
|
||||
}
|
||||
}
|
@ -105,40 +105,6 @@ public class IslandGuard implements Listener {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an entity is in the island world or not or
|
||||
* in the new nether if it is activated
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
protected static boolean inWorld(Entity entity) {
|
||||
return inWorld(entity.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a block is in the island world or not
|
||||
* @param block
|
||||
* @return true if in the island world
|
||||
*/
|
||||
protected static boolean inWorld(Block block) {
|
||||
return inWorld(block.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a location is in the island world or not or
|
||||
* in the new nether if it is activated
|
||||
* @param loc
|
||||
* @return true if in the island world
|
||||
*/
|
||||
protected static boolean inWorld(Location loc) {
|
||||
if (loc.getWorld().equals(IslandWorld.getIslandWorld())) {
|
||||
return true;
|
||||
}
|
||||
if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null && loc.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents visitors picking items from riding horses or other inventories
|
||||
@ -152,7 +118,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// World check
|
||||
if (!inWorld(event.getWhoClicked())) {
|
||||
if (!Util.inWorld(event.getWhoClicked())) {
|
||||
return;
|
||||
}
|
||||
if (event.getInventory().getHolder() instanceof Animals) {
|
||||
@ -228,7 +194,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
plugin.getLogger().info(e.getAttacker().getType().toString());
|
||||
}
|
||||
if (inWorld(e.getVehicle())) {
|
||||
if (Util.inWorld(e.getVehicle())) {
|
||||
if (!(e.getAttacker() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
@ -246,7 +212,7 @@ public class IslandGuard implements Listener {
|
||||
public void onVehicleMove(final VehicleMoveEvent e) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: vehicle move = " + e.getVehicle());
|
||||
if (!inWorld(e.getVehicle())) {
|
||||
if (!Util.inWorld(e.getVehicle())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -367,7 +333,7 @@ public class IslandGuard implements Listener {
|
||||
if (e.getPlayer().isDead()) {
|
||||
return;
|
||||
}
|
||||
if (!inWorld(e.getPlayer())) {
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (plugin.getIslands() == null) {
|
||||
@ -499,7 +465,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// If not in the right world, return
|
||||
if (!inWorld(e.getEntity())) {
|
||||
if (!Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
// Deal with natural spawning
|
||||
@ -530,7 +496,7 @@ public class IslandGuard implements Listener {
|
||||
//plugin.getLogger().info(e.getEventName());
|
||||
//plugin.getLogger().info("Entity exploding is " + e.getEntity());
|
||||
}
|
||||
if (!inWorld(e.getLocation())) {
|
||||
if (!Util.inWorld(e.getLocation())) {
|
||||
return;
|
||||
}
|
||||
// Find out what is exploding
|
||||
@ -669,7 +635,7 @@ public class IslandGuard implements Listener {
|
||||
if (!(e.getEntity() instanceof Enderman)) {
|
||||
return;
|
||||
}
|
||||
if (!inWorld(e.getEntity())) {
|
||||
if (!Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
// Prevent Enderman griefing at spawn
|
||||
@ -695,7 +661,7 @@ public class IslandGuard implements Listener {
|
||||
}
|
||||
if (!Settings.endermanDeathDrop)
|
||||
return;
|
||||
if (!inWorld(e.getEntity())) {
|
||||
if (!Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
if (!(e.getEntity() instanceof Enderman)) {
|
||||
@ -735,7 +701,7 @@ public class IslandGuard implements Listener {
|
||||
if (Settings.allowAutoActivator && e.getPlayer().getName().equals("[CoFH]")) {
|
||||
return;
|
||||
}
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
if (actionAllowed(e.getPlayer(), e.getBlock().getLocation(), SettingsFlag.BREAK_BLOCKS)) {
|
||||
return;
|
||||
}
|
||||
@ -748,7 +714,7 @@ public class IslandGuard implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onItemFrameDamage(final EntityDamageByEntityEvent e) {
|
||||
// Check world
|
||||
if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
|
||||
if (!Util.inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
|
||||
return;
|
||||
}
|
||||
if (e.getDamager() instanceof Projectile) {
|
||||
@ -779,7 +745,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info("DEBUG: remover = " + e.getRemover());
|
||||
}
|
||||
// Check world
|
||||
if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
|
||||
if (!Util.inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
|
||||
return;
|
||||
}
|
||||
if (e.getRemover() instanceof Skeleton || e.getRemover() instanceof Golem) {
|
||||
@ -807,7 +773,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info("DEBUG: Entity = " + e.getEntity());
|
||||
}
|
||||
// Check world
|
||||
if (!inWorld(e.getEntity())) {
|
||||
if (!Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
// Get the island where the damage is occurring
|
||||
@ -1012,7 +978,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// plugin.getLogger().info(e.getEventName());
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
// This permission bypasses protection
|
||||
if (e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
return;
|
||||
@ -1074,7 +1040,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// plugin.getLogger().info(e.getEventName());
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
// This permission bypasses protection
|
||||
if (e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
return;
|
||||
@ -1130,7 +1096,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// plugin.getLogger().info(e.getEventName());
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
if (e.getEntity() != null && e.getEntity().getType().equals(EntityType.LEASH_HITCH)) {
|
||||
if (!actionAllowed(e.getPlayer(), e.getBlock().getLocation(), SettingsFlag.LEASH)) {
|
||||
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected"));
|
||||
@ -1153,7 +1119,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// plugin.getLogger().info(e.getEventName());
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
// This permission bypasses protection
|
||||
if (e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
return;
|
||||
@ -1198,7 +1164,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
// Check world
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
if (actionAllowed(e.getPlayer(),e.getBed().getLocation(), SettingsFlag.BED)) {
|
||||
return;
|
||||
}
|
||||
@ -1219,7 +1185,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
plugin.getLogger().info(e.getRemover().toString());
|
||||
}
|
||||
if (inWorld(e.getEntity())) {
|
||||
if (Util.inWorld(e.getEntity())) {
|
||||
if ((e.getRemover() instanceof Creeper) && !Settings.allowCreeperDamage) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
@ -1272,7 +1238,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (inWorld(e.getEntity())) {
|
||||
if (Util.inWorld(e.getEntity())) {
|
||||
if (e.getPlayer() != null) {
|
||||
Player player = e.getPlayer();
|
||||
if (actionAllowed(player, e.getEntity().getLocation(),SettingsFlag.LEASH)) {
|
||||
@ -1295,7 +1261,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (inWorld(e.getEntity())) {
|
||||
if (Util.inWorld(e.getEntity())) {
|
||||
if (e.getPlayer() != null) {
|
||||
Player player = e.getPlayer();
|
||||
if (actionAllowed(player, e.getEntity().getLocation(),SettingsFlag.LEASH)) {
|
||||
@ -1311,7 +1277,7 @@ public class IslandGuard implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onLiquidFlow(final BlockFromToEvent e) {
|
||||
// Ignore non-island worlds
|
||||
if (!inWorld(e.getBlock())) {
|
||||
if (!Util.inWorld(e.getBlock())) {
|
||||
return;
|
||||
}
|
||||
// Only check lateral movement
|
||||
@ -1362,7 +1328,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
Player p = e.getPlayer();
|
||||
if (e.getBlockClicked() != null) {
|
||||
// This is where the water or lava actually will be dumped
|
||||
@ -1409,7 +1375,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (!inWorld(e.getBlock().getLocation()) || !e.getBlock().getBiome().equals(Biome.HELL)) {
|
||||
if (!Util.inWorld(e.getBlock().getLocation()) || !e.getBlock().getBiome().equals(Biome.HELL)) {
|
||||
return;
|
||||
}
|
||||
// plugin.getLogger().info("DEBUG: Item being dispensed is " +
|
||||
@ -1429,7 +1395,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
// This permission bypasses protection
|
||||
if (VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
return;
|
||||
@ -1469,7 +1435,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (inWorld(e.getPlayer())) {
|
||||
if (Util.inWorld(e.getPlayer())) {
|
||||
if (actionAllowed(e.getPlayer(), e.getEntity().getLocation(), SettingsFlag.SHEARING)) {
|
||||
return;
|
||||
}
|
||||
@ -1490,7 +1456,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (!inWorld(e.getPlayer())) {
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
@ -2025,7 +1991,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(event.getEventName());
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (inWorld(player) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
if (Util.inWorld(player) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
if (event.getRecipe().getResult().getType() == Material.ENDER_CHEST) {
|
||||
if (!(player.hasPermission(Settings.PERMPREFIX + "craft.enderchest"))) {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("general.errors.no-permission"));
|
||||
@ -2047,7 +2013,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info("Ender chest " + event.getEventName());
|
||||
}
|
||||
Player player = (Player) event.getPlayer();
|
||||
if (inWorld(player) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
if (Util.inWorld(player) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (event.getClickedBlock().getType() == Material.ENDER_CHEST) {
|
||||
if (!(event.getPlayer().hasPermission(Settings.PERMPREFIX + "craft.enderchest"))) {
|
||||
@ -2070,7 +2036,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("Hit entity event " + e.getEventName());
|
||||
}
|
||||
if (!inWorld(p)) {
|
||||
if (!Util.inWorld(p)) {
|
||||
return;
|
||||
}
|
||||
if (p.isOp() || VaultHelper.hasPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
@ -2218,7 +2184,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (!inWorld(e.getBlock())) {
|
||||
if (!Util.inWorld(e.getBlock())) {
|
||||
//plugin.getLogger().info("DEBUG: Not in world");
|
||||
return;
|
||||
}
|
||||
@ -2239,7 +2205,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(e.getSource().getType().toString());
|
||||
}
|
||||
if (e.getSource().getType() == Material.FIRE) {
|
||||
if (!inWorld(e.getBlock())) {
|
||||
if (!Util.inWorld(e.getBlock())) {
|
||||
//plugin.getLogger().info("DEBUG: Not in world");
|
||||
return;
|
||||
}
|
||||
@ -2256,7 +2222,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
plugin.getLogger().info(e.getCause().name());
|
||||
}
|
||||
if (!inWorld(e.getBlock())) {
|
||||
if (!Util.inWorld(e.getBlock())) {
|
||||
//plugin.getLogger().info("DEBUG: Not in world");
|
||||
return;
|
||||
}
|
||||
@ -2351,7 +2317,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info("pressure plate = " + e.getEventName());
|
||||
plugin.getLogger().info("action = " + e.getAction());
|
||||
}
|
||||
if (!inWorld(e.getPlayer()) || !e.getAction().equals(Action.PHYSICAL)
|
||||
if (!Util.inWorld(e.getPlayer()) || !e.getAction().equals(Action.PHYSICAL)
|
||||
|| e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|
||||
|| plugin.getIslands().playerIsOnIsland(e.getPlayer())) {
|
||||
//plugin.getLogger().info("DEBUG: Not in world");
|
||||
@ -2397,7 +2363,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
Location pistonLoc = e.getBlock().getLocation();
|
||||
if (Settings.allowPistonPush || !inWorld(pistonLoc)) {
|
||||
if (Settings.allowPistonPush || !Util.inWorld(pistonLoc)) {
|
||||
//plugin.getLogger().info("DEBUG: Not in world");
|
||||
return;
|
||||
}
|
||||
@ -2425,7 +2391,7 @@ public class IslandGuard implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("egg throwing = " + e.getEventName());
|
||||
}
|
||||
if (!inWorld(e.getPlayer()) || e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|
||||
if (!Util.inWorld(e.getPlayer()) || e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|
||||
|| plugin.getIslands().playerIsOnIsland(e.getPlayer()) || plugin.getIslands().isAtSpawn(e.getPlayer().getLocation())) {
|
||||
return;
|
||||
}
|
||||
@ -2454,7 +2420,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
// Check world
|
||||
if (!inWorld(e.getLocation())) {
|
||||
if (!Util.inWorld(e.getLocation())) {
|
||||
return;
|
||||
}
|
||||
// Check if this is on an island
|
||||
@ -2498,7 +2464,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// Check world
|
||||
if (!inWorld(e.getBlock())) {
|
||||
if (!Util.inWorld(e.getBlock())) {
|
||||
return;
|
||||
}
|
||||
// Check if this is on an island
|
||||
@ -2548,7 +2514,7 @@ public class IslandGuard implements Listener {
|
||||
public void onBlockRedstone(BlockRedstoneEvent e){
|
||||
if(Settings.disableOfflineRedstone) {
|
||||
// Check world
|
||||
if (!inWorld(e.getBlock())) {
|
||||
if (!Util.inWorld(e.getBlock())) {
|
||||
return;
|
||||
}
|
||||
// Check if this is on an island
|
||||
@ -2568,7 +2534,7 @@ public class IslandGuard implements Listener {
|
||||
{
|
||||
if (!Settings.allowTNTPushing) {
|
||||
// Check world
|
||||
if (!inWorld(event.getBlock())) {
|
||||
if (!Util.inWorld(event.getBlock())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2590,7 +2556,7 @@ public class IslandGuard implements Listener {
|
||||
{
|
||||
if (!Settings.allowTNTPushing) {
|
||||
// Check world
|
||||
if (!inWorld(event.getBlock())) {
|
||||
if (!Util.inWorld(event.getBlock())) {
|
||||
return;
|
||||
}
|
||||
for (Block block: event.getBlocks()) {
|
||||
@ -2619,7 +2585,7 @@ public class IslandGuard implements Listener {
|
||||
plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities());
|
||||
//plugin.getLogger().info("splash hit entity = " + e.getHitEntity());
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
|
||||
if (!Util.inWorld(e.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
// Try to get the shooter
|
||||
|
@ -72,7 +72,7 @@ public class IslandGuard1_8 implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("1.8 " + e.getEventName());
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getPlayer())) {
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ARMOR_STAND)) {
|
||||
@ -100,7 +100,7 @@ public class IslandGuard1_8 implements Listener {
|
||||
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
return;
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getPlayer())) {
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (e.getPlayer().isOp()) {
|
||||
@ -134,7 +134,7 @@ public class IslandGuard1_8 implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("1.8 " + "Armor stand place " + e.getEventName());
|
||||
}
|
||||
if (!IslandGuard.inWorld(p)) {
|
||||
if (!Util.inWorld(p)) {
|
||||
return;
|
||||
}
|
||||
if (p.isOp() || VaultHelper.hasPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
@ -181,7 +181,7 @@ public class IslandGuard1_8 implements Listener {
|
||||
if (!(e.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getEntity())) {
|
||||
if (!Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
final LivingEntity livingEntity = (LivingEntity) e.getEntity();
|
||||
|
@ -68,7 +68,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
}
|
||||
if (e.getEntity() instanceof Player && e.getNewState().getType().equals(Material.FROSTED_ICE)) {
|
||||
Player player= (Player) e.getEntity();
|
||||
if (!IslandGuard.inWorld(player)) {
|
||||
if (!Util.inWorld(player)) {
|
||||
return;
|
||||
}
|
||||
if (player.isOp()) {
|
||||
@ -104,7 +104,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("1.9 " +e.getEventName());
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getPlayer())) {
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (e.getPlayer().isOp()) {
|
||||
@ -138,7 +138,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("1.9 " +"End crystal place " + e.getEventName());
|
||||
}
|
||||
if (!IslandGuard.inWorld(p)) {
|
||||
if (!Util.inWorld(p)) {
|
||||
return;
|
||||
}
|
||||
if (p.isOp() || VaultHelper.hasPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||
@ -188,7 +188,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
plugin.getLogger().info("1.9 " +"IslandGuard 1_9 " + e.getEventName());
|
||||
plugin.getLogger().info("1.9 " +"Entity is " + e.getEntityType());
|
||||
}
|
||||
if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
|
||||
if (e.getEntity() == null || !Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
if (!(e.getEntity() instanceof EnderCrystal)) {
|
||||
@ -265,7 +265,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IslandGuard.inWorld(e.getLocation())) {
|
||||
if (!Util.inWorld(e.getLocation())) {
|
||||
return;
|
||||
}
|
||||
// General settings irrespective of whether this is allowed or not
|
||||
@ -318,7 +318,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
return;
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getPlayer())) {
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (e.getPlayer().isOp()) {
|
||||
@ -355,7 +355,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
plugin.getLogger().info("1.9 id = " + e.getAreaEffectCloud().getEntityId());
|
||||
plugin.getLogger().info("1.9 hit entity = " + e.getHitEntity());
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
|
||||
if (!Util.inWorld(e.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
// Try to get the shooter
|
||||
@ -386,7 +386,7 @@ public class IslandGuard1_9 implements Listener {
|
||||
plugin.getLogger().info("1.9 lingering potion cause = " + e.getCause());
|
||||
plugin.getLogger().info("1.9 lingering potion damager = " + e.getDamager());
|
||||
}
|
||||
if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
|
||||
if (!Util.inWorld(e.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
if (e.getEntity() == null || e.getEntity().getUniqueId() == null) {
|
||||
|
@ -0,0 +1,189 @@
|
||||
package us.tastybento.bskyblock.listeners.protection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
import us.tastybento.bskyblock.util.VaultHelper;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
* Provides protection to islands
|
||||
*/
|
||||
public class VisitorGuard implements Listener {
|
||||
private final BSkyBlock plugin;
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
public VisitorGuard(final BSkyBlock plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevent dropping items if player dies on another island
|
||||
* This option helps reduce the down side of dying due to traps, etc.
|
||||
* Also handles muting of death messages
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onVistorDeath(final PlayerDeathEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (!Util.inWorld(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
// Mute death messages
|
||||
if (Settings.muteDeathMessages) {
|
||||
e.setDeathMessage(null);
|
||||
}
|
||||
// If visitors will keep items and their level on death
|
||||
// This will override any global settings
|
||||
if (Settings.allowVisitorKeepInvOnDeath) {
|
||||
// If the player is not a visitor then they die and lose everything -
|
||||
// sorry :-(
|
||||
Island island = plugin.getIslands().getProtectedIslandAt(e.getEntity().getLocation());
|
||||
if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId())) {
|
||||
// They are a visitor
|
||||
InventorySave.getInstance().savePlayerInventory(e.getEntity());
|
||||
e.getDrops().clear();
|
||||
e.setKeepLevel(true);
|
||||
e.setDroppedExp(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onVistorSpawn(final PlayerRespawnEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
// This will override any global settings
|
||||
if (Settings.allowVisitorKeepInvOnDeath) {
|
||||
InventorySave.getInstance().loadPlayerInventory(e.getPlayer());
|
||||
InventorySave.getInstance().clearSavedInventory(e.getPlayer());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Prevent item pickup by visitors
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onVisitorPickup(final PlayerPickupItemEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
Island island = plugin.getIslands().getIslandAt(e.getItem().getLocation());
|
||||
if ((island != null && island.getFlag(SettingsFlag.ITEM_PICKUP))
|
||||
|| e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|
||||
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getItem().getLocation())) {
|
||||
return;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevent item drop by visitors
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onVisitorDrop(final PlayerDropItemEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
if (!Util.inWorld(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
Island island = plugin.getIslands().getIslandAt(e.getItemDrop().getLocation());
|
||||
if ((island != null && island.getFlag(SettingsFlag.ITEM_DROP))
|
||||
|| e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|
||||
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getItemDrop().getLocation())) {
|
||||
return;
|
||||
}
|
||||
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents visitors from using commands on islands, like /spawner
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVisitorCommand(final PlayerCommandPreprocessEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("Visitor command " + e.getEventName() + ": " + e.getMessage());
|
||||
}
|
||||
if (!Util.inWorld(e.getPlayer()) || e.getPlayer().isOp()
|
||||
|| VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|
||||
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) {
|
||||
//plugin.getLogger().info("player is not in world or op etc.");
|
||||
return;
|
||||
}
|
||||
// Check banned commands
|
||||
//plugin.getLogger().info(Settings.visitorCommandBlockList.toString());
|
||||
String[] args = e.getMessage().substring(1).toLowerCase().split(" ");
|
||||
if (Settings.visitorBannedCommands.contains(args[0])) {
|
||||
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents visitors from getting damage if invinciblevisitors option is set to TRUE
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVisitorGetDamage(EntityDamageEvent e){
|
||||
if(!Settings.invincibleVisitor) return;
|
||||
if(!(e.getEntity() instanceof Player)) return;
|
||||
|
||||
Player p = (Player) e.getEntity();
|
||||
if (!Util.inWorld(p) || plugin.getIslands().locationIsOnIsland(p, p.getLocation())) return;
|
||||
|
||||
if (Settings.invincibleVisitorOptions.contains(e.getCause())) e.setCancelled(true);
|
||||
|
||||
else if(e.getCause().equals(DamageCause.VOID)) {
|
||||
if(plugin.getPlayers().hasIsland(p.getUniqueId())) {
|
||||
Location safePlace = plugin.getIslands().getSafeHomeLocation(p.getUniqueId(), 1);
|
||||
if (safePlace != null) {
|
||||
p.teleport(safePlace);
|
||||
// Set their fall distance to zero otherwise they crash onto their island and die
|
||||
p.setFallDistance(0);
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// No island, or no safe spot on island
|
||||
if (plugin.getIslands().getSpawn() != null) {
|
||||
p.teleport(plugin.getIslands().getSpawnPoint());
|
||||
// Set their fall distance to zero otherwise they crash onto their island and die
|
||||
p.setFallDistance(0);
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// No island spawn, try regular spawn
|
||||
if (!p.performCommand("spawn")) {
|
||||
// If this command doesn't work, let them die otherwise they may get trapped in the void forever
|
||||
return;
|
||||
}
|
||||
// Set their fall distance to zero otherwise they crash onto their island and die
|
||||
p.setFallDistance(0);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,12 +13,15 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
|
||||
import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler;
|
||||
|
||||
@ -243,4 +246,45 @@ public class Util {
|
||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),
|
||||
"minecraft:title " + player.getName() + " actionbar {\"text\":\"" + ChatColor.stripColor(message) + "\"}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a location is in the island world or not or
|
||||
* in the new nether if it is activated
|
||||
* @param loc
|
||||
* @return true if in the island world
|
||||
*/
|
||||
public static boolean inWorld(Location loc) {
|
||||
if (loc != null) {
|
||||
if (loc.getWorld().equals(IslandWorld.getIslandWorld())) {
|
||||
return true;
|
||||
}
|
||||
if (Settings.netherIslands && loc.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
return true;
|
||||
}
|
||||
if (Settings.endIslands && loc.getWorld().equals(IslandWorld.getEndWorld())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an entity is in the island world or not or
|
||||
* in the new nether if it is activated
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static boolean inWorld(Entity entity) {
|
||||
return inWorld(entity.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a block is in the island world or not
|
||||
* @param block
|
||||
* @return true if in the island world
|
||||
*/
|
||||
public static boolean inWorld(Block block) {
|
||||
return inWorld(block.getLocation());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user