use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class EntityLimits method onPlayerBlockPlace.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBlockPlace(final HangingPlaceEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info("DEBUG: block placed " + e.getBlock().getType());
plugin.getLogger().info("DEBUG: entity " + e.getEntity().getType());
}
if (Settings.allowedFakePlayers.contains(e.getPlayer().getName()))
return;
// plugin.getLogger().info(e.getEventName());
if (IslandGuard.inWorld(e.getPlayer())) {
// This permission bypasses protection
if (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
Island island = plugin.getGrid().getProtectedIslandAt(e.getBlock().getLocation());
// Outside of island protection zone
if (island == null) {
if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
return;
}
if (island.getIgsFlag(SettingsFlag.PLACE_BLOCKS) || island.getMembers().contains(e.getPlayer().getUniqueId())) {
// Check how many placed
String type = e.getEntity().getType().toString();
if (e.getEntity().getType().equals(EntityType.ITEM_FRAME) || e.getEntity().getType().equals(EntityType.PAINTING)) {
// tile entity placed
if (Settings.limitedBlocks.containsKey(type) && Settings.limitedBlocks.get(type) > -1) {
// Convert from EntityType to Material via string - ugh
int count = island.getTileEntityCount(Material.valueOf(type), e.getEntity().getWorld());
if (Settings.limitedBlocks.get(type) <= count) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]", Util.prettifyText(type))).replace("[number]", String.valueOf(Settings.limitedBlocks.get(type))));
e.setCancelled(true);
}
}
}
} else {
// Visitor
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 EntityLimits method onTreeGrow.
/**
* Prevents trees from growing outside of the protected area.
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Check world
if (!IslandGuard.inWorld(e.getLocation())) {
return;
}
// Check if this is on an island
Island island = plugin.getGrid().getIslandAt(e.getLocation());
if (island == null || island.isSpawn()) {
return;
}
Iterator<BlockState> it = e.getBlocks().iterator();
while (it.hasNext()) {
BlockState b = it.next();
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2 || b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
if (!island.onIsland(b.getLocation())) {
it.remove();
}
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class EntityLimits method onVillagerSpawn.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onVillagerSpawn(final CreatureSpawnEvent e) {
// If not an villager
if (!(e.getEntity() instanceof Villager)) {
return;
}
if (DEBUG3) {
plugin.getLogger().info("Villager spawn event! " + e.getEventName());
plugin.getLogger().info("Reason:" + e.getSpawnReason().toString());
plugin.getLogger().info("Entity:" + e.getEntityType().toString());
}
// Only cover overworld
if (!e.getEntity().getWorld().equals(ASkyBlock.getIslandWorld())) {
return;
}
// If there's no limit - leave it
if (Settings.villagerLimit <= 0) {
return;
}
// We only care about villagers breeding, being cured or coming from a spawn egg, etc.
if (e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.BREEDING && e.getSpawnReason() != SpawnReason.DISPENSE_EGG && e.getSpawnReason() != SpawnReason.SPAWNER_EGG && e.getSpawnReason() != SpawnReason.CURED) {
return;
}
Island island = plugin.getGrid().getProtectedIslandAt(e.getLocation());
if (island == null || island.getOwner() == null || island.isSpawn()) {
// No island, no limit
return;
}
int limit = Settings.villagerLimit * Math.max(1, plugin.getPlayers().getMembers(island.getOwner()).size());
// plugin.getLogger().info("DEBUG: villager limit = " + limit);
// long time = System.nanoTime();
int pop = island.getPopulation();
// plugin.getLogger().info("DEBUG: time = " + ((System.nanoTime() - time)*0.000000001));
if (pop >= limit) {
plugin.getLogger().warning("Island at " + island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ() + " hit the island villager limit of " + limit);
// plugin.getLogger().info("Stopped villager spawning on island " + island.getCenter());
// Get all players in the area
List<Entity> players = e.getEntity().getNearbyEntities(10, 10, 10);
for (Entity player : players) {
if (player instanceof Player) {
Player p = (Player) player;
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit)));
}
}
plugin.getMessages().tellTeam(island.getOwner(), ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit)));
if (e.getSpawnReason().equals(SpawnReason.CURED)) {
// Easter Egg. Or should I say Easter Apple?
ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE);
// Nerfed
// goldenApple.setDurability((short)1);
e.getLocation().getWorld().dropItemNaturally(e.getLocation(), goldenApple);
}
e.setCancelled(true);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock 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.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onFishing.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onFishing(final 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();
}
}
}
}
}
Aggregations