use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard method onEntityDamage.
/**
* This method protects players from PVP if it is not allowed and from
* arrows fired by other players
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageByEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info("DEBUG: Damager = " + e.getDamager().toString());
plugin.getLogger().info("DEBUG: Entitytype = " + e.getEntityType());
plugin.getLogger().info("DEBUG: Entity = " + e.getEntity());
}
// Check world
if (!inWorld(e.getEntity())) {
return;
}
// Get the island where the damage is occurring
Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation());
boolean inNether = false;
if (e.getEntity().getWorld().equals(ASkyBlock.getNetherWorld())) {
inNether = true;
}
// Stop TNT damage if it is disallowed
if (!Settings.allowTNTDamage && (e.getDamager().getType().equals(EntityType.PRIMED_TNT) || e.getDamager().getType().equals(EntityType.FIREWORK))) {
if (DEBUG)
plugin.getLogger().info("DEBUG: cancelling TNT or firework damage");
e.setCancelled(true);
return;
}
// Check for creeper damage at spawn
if (island != null && island.isSpawn() && e.getDamager().getType().equals(EntityType.CREEPER) && island.getIgsFlag(SettingsFlag.CREEPER_PAIN)) {
return;
}
// Stop Creeper damager if it is disallowed
if (!Settings.allowCreeperDamage && e.getDamager().getType().equals(EntityType.CREEPER) && !(e.getEntity() instanceof Player)) {
e.setCancelled(true);
return;
}
// Stop Creeper griefing if it is disallowed
if (!Settings.allowCreeperGriefing && e.getDamager().getType().equals(EntityType.CREEPER)) {
// Now we have to check what the target was
Creeper creeper = (Creeper) e.getDamager();
// plugin.getLogger().info("DEBUG: entity being damaged is " + e.getEntity());
if (creeper.getTarget() instanceof Player) {
// plugin.getLogger().info("DEBUG: target is a player");
Player target = (Player) creeper.getTarget();
// Check if the target is on their own island or not
if (!plugin.getGrid().locationIsOnIsland(target, e.getEntity().getLocation())) {
// They are a visitor tsk tsk
// plugin.getLogger().info("DEBUG: player is a visitor");
e.setCancelled(true);
return;
}
}
// Check if this creeper was lit by a visitor
if (litCreeper.contains(creeper.getUniqueId())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: preventing creeeper from damaging");
}
e.setCancelled(true);
return;
}
}
// Ops can do anything
if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager();
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
}
// Get the real attacker
boolean flamingArrow = false;
boolean projectile = false;
Player attacker = null;
if (e.getDamager() instanceof Player) {
attacker = (Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Projectile damage");
projectile = true;
// Find out who fired the arrow
Projectile p = (Projectile) e.getDamager();
if (DEBUG)
plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString());
if (p.getShooter() instanceof Player) {
attacker = (Player) p.getShooter();
if (p.getFireTicks() > 0) {
flamingArrow = true;
}
// Check if this is a flaming arrow
if (DEBUG)
plugin.getLogger().info("DEBUG: fire ticks = " + p.getFireTicks() + " max = " + p.getMaxFireTicks());
}
}
if (attacker == null) {
// Not a player
return;
}
// Self damage
if (e.getEntity() instanceof Player && attacker.equals(e.getEntity())) {
if (DEBUG)
plugin.getLogger().info("Self damage!");
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Another player");
// Check to see if it's an item frame
if (e.getEntity() instanceof ItemFrame || e.getEntityType().toString().endsWith("STAND")) {
if (island != null && (island.getIgsFlag(SettingsFlag.BREAK_BLOCKS) || island.getMembers().contains(attacker.getUniqueId()))) {
return;
}
// Else not allowed
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
e.setCancelled(true);
return;
}
// Monsters being hurt
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) {
// Normal island check
if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
// Members always allowed
return;
}
if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) {
// Check for visitors setting creepers alight using flint steel
if (!Settings.allowCreeperGriefing && e.getEntity() instanceof Creeper) {
for (ItemStack holding : Util.getPlayerInHandItems(attacker)) {
if (holding.getType().equals(Material.FLINT_AND_STEEL)) {
// Save this creeper for later when any damage caused by its explosion will be nullified
litCreeper.add(e.getEntity().getUniqueId());
if (DEBUG) {
plugin.getLogger().info("DEBUG: adding to lit creeper set");
}
}
}
}
return;
}
// Not allowed
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
e.setCancelled(true);
return;
}
// Mobs being hurt
if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman || e.getEntity() instanceof Villager) {
if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
// Else not allowed
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
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 (e.getEntity() instanceof Player) {
if (pvp) {
return;
} else {
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
e.setCancelled(true);
return;
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard1_9 method onHitEndCrystal.
/**
* Handle interaction with end crystals 1.9
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onHitEndCrystal(final PlayerInteractAtEntityEvent e) {
if (!IslandGuard.inWorld(e.getPlayer())) {
return;
}
if (e.getPlayer().isOp()) {
return;
}
// This permission bypasses protection
if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ENDER_CRYSTAL)) {
// Check island
Island island = plugin.getGrid().getIslandAt(e.getRightClicked().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
}
if (island != null) {
if (island.getMembers().contains(e.getPlayer().getUniqueId()) || island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
return;
}
}
e.setCancelled(true);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard1_9 method EndCrystalDamage.
/**
* Handle end crystal damage by visitors
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void EndCrystalDamage(final EntityDamageByEntityEvent e) {
if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
return;
}
if (!(e.getEntity() instanceof EnderCrystal)) {
return;
}
Player p = null;
if (e.getDamager() instanceof Player) {
p = (Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile) {
// Get the shooter
Projectile projectile = (Projectile) e.getDamager();
ProjectileSource shooter = projectile.getShooter();
if (shooter instanceof Player) {
p = (Player) shooter;
}
}
if (p != null) {
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);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class LavaCheck method onCobbleGen.
/**
* Magic Cobble Generator
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCobbleGen(BlockFromToEvent e) {
// If magic cobble gen isnt used
if (!Settings.useMagicCobbleGen) {
// plugin.getLogger().info("DEBUG: no magic cobble gen");
return;
}
// Only do this in ASkyBlock world
if (!e.getBlock().getWorld().equals(ASkyBlock.getIslandWorld())) {
// plugin.getLogger().info("DEBUG: wrong world");
return;
}
// Do nothing if a new island is being created
if (plugin.isNewIsland()) {
// plugin.getLogger().info("DEBUG: new island in creation");
return;
}
// If only at spawn, do nothing if we're not at spawn
if (Settings.magicCobbleGenOnlyAtSpawn && (!ASkyBlockAPI.getInstance().isAtSpawn(e.getBlock().getLocation()))) {
return;
}
final Block b = e.getBlock();
if (b.getType().equals(Material.WATER) || b.getType().equals(Material.STATIONARY_WATER) || b.getType().equals(Material.LAVA) || b.getType().equals(Material.STATIONARY_LAVA)) {
// plugin.getLogger().info("DEBUG: From block is water or lava. To = " + e.getToBlock().getType());
final Block toBlock = e.getToBlock();
if (toBlock.getType().equals(Material.AIR) && generatesCobble(b, toBlock)) {
// plugin.getLogger().info("DEBUG: potential cobble gen");
// Get island level or use default
long l = Long.MIN_VALUE;
Island island = plugin.getGrid().getIslandAt(b.getLocation());
if (island != null) {
if (island.getOwner() != null) {
l = plugin.getPlayers().getIslandLevel(island.getOwner());
// plugin.getLogger().info("DEBUG: level " + level);
}
}
final long level = l;
// Check if cobble was generated next tick
// Store surrounding blocks and their current material types
final List<Block> prevBlock = new ArrayList<Block>();
final List<Material> prevMat = new ArrayList<Material>();
for (BlockFace face : FACES) {
Block r = toBlock.getRelative(face);
prevBlock.add(r);
prevMat.add(r.getType());
// r = toBlock.getRelative(face,2);
// prevBlock.add(r);
// prevMat.add(r.getType());
}
// Check if they became cobblestone next tick
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Iterator<Block> blockIt = prevBlock.iterator();
Iterator<Material> matIt = prevMat.iterator();
while (blockIt.hasNext() && matIt.hasNext()) {
Block block = blockIt.next();
Material material = matIt.next();
if (block.getType().equals(Material.COBBLESTONE) && !block.getType().equals(material)) {
// plugin.getLogger().info("DEBUG: Cobble generated. Island level = " + level);
if (!Settings.magicCobbleGenChances.isEmpty()) {
Entry<Long, TreeMap<Double, Material>> entry = Settings.magicCobbleGenChances.floorEntry(level);
double maxValue = entry.getValue().lastKey();
double rnd = Util.randomDouble() * maxValue;
Entry<Double, Material> en = entry.getValue().ceilingEntry(rnd);
// plugin.getLogger().info("DEBUG: material = " + en.getValue());
if (en != null) {
block.setType(en.getValue());
// Record stats, per level
if (stats.containsKey(entry.getKey())) {
stats.get(entry.getKey()).add(en.getValue());
} else {
Multiset<Material> set = HashMultiset.create();
set.add(en.getValue());
stats.put(entry.getKey(), set);
}
}
}
}
}
}
});
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class SettingsPanel method islandGuardPanel.
/**
* Presents a GUI for toggling or viewing settings
* @param player
* @return
*/
public Inventory islandGuardPanel(Player player) {
UUID uuid = player.getUniqueId();
// Get the island settings for this player's location
Island island = plugin.getGrid().getProtectedIslandAt(player.getLocation());
List<IPItem> ip = new ArrayList<IPItem>();
Inventory newPanel = null;
if (island == null) {
// plugin.getLogger().info("DEBUG: default world settings");
ip.add(new IPItem(Material.MAP, plugin.myLocale(uuid).igsSettingsGeneralTitle, plugin.myLocale(uuid).igsSettingsGeneralDesc));
// General settings all enum
for (SettingsFlag flag : SettingsFlag.values()) {
// plugin.getLogger().info("DEBUG: default setting = " + Settings.defaultWorldSettings.get(flag));
if (flag.equals(SettingsFlag.ACID_DAMAGE) && Settings.acidDamage == 0)
continue;
if (Settings.defaultWorldSettings.containsKey(flag) && lookup.inverse().containsKey(flag) && plugin.myLocale(uuid).igs.containsKey(flag)) {
ip.add(new IPItem(Settings.defaultWorldSettings.get(flag), lookup.inverse().get(flag), plugin.myLocale(uuid).igs.get(flag), uuid));
}
}
// System settings that are visible to users
ip.add(new IPItem(Settings.allowChestDamage, Material.CHEST, plugin.myLocale(uuid).igsChestDamage, uuid));
ip.add(new IPItem(Settings.allowCreeperDamage, Material.SKULL_ITEM, 4, plugin.myLocale(uuid).igsCreeperDamage, uuid));
ip.add(new IPItem(Settings.allowCreeperGriefing, Material.SKULL_ITEM, 4, plugin.myLocale(uuid).igsCreeperGriefing, uuid));
ip.add(new IPItem(!Settings.restrictWither, Material.SKULL_ITEM, 1, plugin.myLocale(uuid).igsWitherDamage, uuid));
ip.add(new IPItem(Settings.allowTNTDamage, Material.TNT, plugin.myLocale(uuid).igsTNT, uuid));
ip.add(new IPItem(Settings.allowVisitorKeepInvOnDeath, Material.IRON_CHESTPLATE, plugin.myLocale(uuid).igsVisitorKeep, uuid));
} else if (island.isSpawn()) {
ip.add(new IPItem(Material.MAP, plugin.myLocale(uuid).igsSettingsSpawnTitle, plugin.myLocale(uuid).igsSettingsSpawnDesc));
// Spawn settings
for (SettingsFlag flag : Settings.defaultSpawnSettings.keySet()) {
// plugin.getLogger().info("DEBUG: " + flag.toString());
if (flag.equals(SettingsFlag.ACID_DAMAGE) && Settings.acidDamage == 0)
continue;
if (lookup.inverse().containsKey(flag) && plugin.myLocale(uuid).igs.containsKey(flag)) {
ip.add(new IPItem(island.getIgsFlag(flag), lookup.inverse().get(flag), plugin.myLocale(uuid).igs.get(flag), uuid));
}
}
} else {
// Standard island
// plugin.getLogger().info("DEBUG: Standard island");
ip.add(new IPItem(Material.MAP, plugin.myLocale(uuid).igsSettingsIslandTitle, plugin.myLocale(uuid).igsSettingsIslandDesc));
for (SettingsFlag flag : Settings.visitorSettings.keySet()) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: visitor flag = " + flag);
plugin.getLogger().info("DEBUG: setting for island = " + island.getIgsFlag(flag));
}
if (flag.equals(SettingsFlag.ACID_DAMAGE) && Settings.acidDamage == 0)
continue;
if (lookup.inverse().get(flag) != null) {
if (plugin.myLocale(uuid).igs.containsKey(flag)) {
// plugin.getLogger().info("DEBUG: Adding flag");
ip.add(new IPItem(island.getIgsFlag(flag), lookup.inverse().get(flag), plugin.myLocale(uuid).igs.get(flag), uuid));
}
} else if (DEBUG) {
plugin.getLogger().severe("DEBUG: " + flag + " is missing an icon");
}
}
}
if (ip.size() > 0) {
// Make sure size is a multiple of 9
int size = ip.size() + 8;
size -= (size % 9);
String title = plugin.myLocale(uuid).igsTitle;
if (title.length() > 32) {
title = title.substring(0, 31);
}
newPanel = Bukkit.createInventory(null, size, title);
// Fill the inventory and return
int slot = 0;
for (IPItem i : ip) {
i.setSlot(slot);
newPanel.addItem(i.getItem());
}
}
return newPanel;
}
Aggregations