use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.
the class IslandGuard method onPlayerHitEntity.
/**
* Handles hitting minecarts or feeding animals
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerHitEntity(PlayerInteractEntityEvent e) {
Player p = e.getPlayer();
if (DEBUG) {
plugin.getLogger().info("Hit entity event " + e.getEventName());
}
if (!inWorld(p)) {
return;
}
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
// You can do anything if you are Op of have the bypass
return;
}
/*
* Leashes are deal with mostly using the PlayerLeashEvent and PlayerUnleashEvent
* however, skeleton and zombie horses cannot be leashed, so those should be exempted
*/
if (Util.playerIsHolding(p, Material.LEASH) && e.getRightClicked() != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: checking horse types");
// Pre 1.11
if (e.getRightClicked() instanceof Horse) {
boolean skellyZombieHorse = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: horse clicked ");
Horse horse = (Horse) e.getRightClicked();
if (DEBUG)
plugin.getLogger().info("DEBUG: horse variant = " + horse.getVariant());
if (horse.getVariant().equals(Variant.SKELETON_HORSE) || horse.getVariant().equals(Variant.UNDEAD_HORSE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: skelly or zombie horse");
skellyZombieHorse = true;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Checking entity types :" + e.getRightClicked().getType().name());
// For 1.11 onwards
if (e.getRightClicked().getType().name().equals("ZOMBIE_HORSE") || e.getRightClicked().getType().name().equals("SKELETON_HORSE")) {
skellyZombieHorse = true;
}
if (!skellyZombieHorse)
return;
if (DEBUG)
plugin.getLogger().info("DEBUG: zombie horse or skelly horse");
}
}
Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
if (!plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
// Handle village trading
if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.VILLAGER)) {
if (island != null) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: island is not null");
plugin.getLogger().info("DEBUG: island is not spawn");
plugin.getLogger().info("DEBUG: villager trading is " + island.getIgsFlag(SettingsFlag.VILLAGER_TRADING));
}
if ((!island.getIgsFlag(SettingsFlag.VILLAGER_TRADING) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
}
// Handle name tags and dyes
if (Util.playerIsHolding(p, Material.NAME_TAG) || Util.playerIsHolding(p, Material.INK_SACK)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getPlayer().updateInventory();
return;
}
// Handle cookies (to animals)
if (Util.playerIsHolding(p, Material.COOKIE) && e.getRightClicked() instanceof Animals) {
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MOBS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
if (island != null) {
if ((!island.getIgsFlag(SettingsFlag.HURT_MOBS) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
}
// Handle breeding
if (e.getRightClicked() instanceof Animals) {
for (ItemStack item : Util.getPlayerInHandItems(p)) {
Material type = item.getType();
if (type == Material.EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.BREEDING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
if (island != null) {
if ((!island.getIgsFlag(SettingsFlag.BREEDING) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
}
}
}
switch(e.getRightClicked().getType()) {
case CREEPER:
// This seems to be called when the player is in Creative mode...
if (!Settings.allowCreeperGriefing) {
for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) {
if (item != null && item.getType().equals(Material.FLINT_AND_STEEL)) {
if (!island.getMembers().contains(e.getPlayer().getUniqueId())) {
// Visitor
litCreeper.add(e.getRightClicked().getUniqueId());
if (DEBUG) {
plugin.getLogger().info("DEBUG: visitor lit creeper");
}
}
}
}
}
break;
case LLAMA:
case SKELETON_HORSE:
case ZOMBIE_HORSE:
case HORSE:
// plugin.getLogger().info("Horse riding");
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HORSE_RIDING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getPlayer().updateInventory();
}
if (island != null && !island.getIgsFlag(SettingsFlag.HORSE_RIDING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getPlayer().updateInventory();
}
break;
case ITEM_FRAME:
// This is to place items in an item frame
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
if (island != null) {
if (!island.getIgsFlag(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
break;
case MINECART_CHEST:
case MINECART_FURNACE:
case MINECART_HOPPER:
// plugin.getLogger().info("Minecarts");
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.CHEST)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
if (island != null) {
if (!island.getIgsFlag(SettingsFlag.CHEST)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
break;
default:
break;
}
}
}
use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.
the class IslandGuard method onEggThrow.
/**
* Handle visitor chicken egg throwing
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEggThrow(PlayerEggThrowEvent e) {
if (DEBUG) {
plugin.getLogger().info("egg throwing = " + e.getEventName());
}
if (!inWorld(e.getPlayer()) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().playerIsOnIsland(e.getPlayer()) || plugin.getGrid().isAtSpawn(e.getPlayer().getLocation())) {
return;
}
// Check island
Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
if (island == null) {
return;
}
if (!island.getIgsFlag(SettingsFlag.EGGS)) {
e.setHatching(false);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
// e.getPlayer().updateInventory();
}
return;
}
use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.
the class IslandGuard method onFishing.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onFishing(PlayerFishEvent e) {
if (DEBUG) {
plugin.getLogger().info("Player fish event " + e.getEventName());
plugin.getLogger().info("Player fish event " + e.getCaught());
}
if (e.getCaught() == null)
return;
Player p = e.getPlayer();
if (!inWorld(p)) {
return;
}
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
// You can do anything if you are Op of have the bypass
return;
}
// Handle rods
Island island = plugin.getGrid().getProtectedIslandAt(e.getCaught().getLocation());
// PVP check
if (e.getCaught() instanceof Player) {
// Check if this is the player who is holding the rod
if (e.getCaught().equals(e.getPlayer())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: player cught themselves!");
return;
}
if (island == null && (e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL) && !Settings.defaultWorldSettings.get(SettingsFlag.PVP)) || ((e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER) && !Settings.defaultWorldSettings.get(SettingsFlag.NETHER_PVP)))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea);
e.setCancelled(true);
e.getHook().remove();
return;
}
if (island != null && ((e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL) && !island.getIgsFlag(SettingsFlag.PVP)) || (e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER) && !island.getIgsFlag(SettingsFlag.NETHER_PVP)))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea);
e.setCancelled(true);
e.getHook().remove();
return;
}
}
if (!plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
if (e.getCaught() instanceof Animals) {
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MOBS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getHook().remove();
return;
}
if (island != null) {
if ((!island.getIgsFlag(SettingsFlag.HURT_MOBS) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getHook().remove();
return;
}
}
}
// Monster protection
if (e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) {
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MONSTERS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getHook().remove();
return;
}
if (island != null) {
if ((!island.getIgsFlag(SettingsFlag.HURT_MONSTERS) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getHook().remove();
return;
}
}
}
}
}
use of com.wasteofplastic.acidisland.Island in project acidisland 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 && islandFrom != 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.acidisland.Island in project acidisland by tastybento.
the class IslandGuard1_8 method ArmorStandDestroy.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void ArmorStandDestroy(EntityDamageByEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info("1.8 " + "IslandGuard New " + e.getEventName());
}
if (!(e.getEntity() instanceof LivingEntity)) {
return;
}
if (!IslandGuard.inWorld(e.getEntity())) {
return;
}
final LivingEntity livingEntity = (LivingEntity) e.getEntity();
if (!livingEntity.getType().equals(EntityType.ARMOR_STAND)) {
return;
}
if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager();
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
// Check if on island
if (plugin.getGrid().playerIsOnIsland(p)) {
return;
}
// Check island
Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
}
if (island != null && island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
return;
}
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
Aggregations