use of org.bukkit.scheduler.BukkitRunnable in project askyblock by tastybento.
the class AcidTask method runAcidItemRemovalTask.
public void runAcidItemRemovalTask() {
if (task != null)
task.cancel();
// If items must be removed when dropped in acid
if (Settings.acidItemDestroyTime > 0) {
task = new BukkitRunnable() {
public void run() {
// plugin.getLogger().info("DEBUG: running task every " + Settings.acidItemDestroyTime);
List<Entity> entList = ASkyBlock.getIslandWorld().getEntities();
// Clean up the itemsInWater list
Set<UUID> newItemsInWater = new HashSet<UUID>();
for (Entity current : entList) {
if (current.getType() != null && current.getType().equals(EntityType.DROPPED_ITEM)) {
if ((current.getLocation().getBlock().getType() == Material.WATER) || (current.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) {
// Check if this item was in the list last time
if (itemsInWater.contains(current.getUniqueId())) {
// Remove item
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
current.getWorld().playSound(current.getLocation(), Sound.valueOf("FIZZ"), 3F, 3F);
} else {
current.getWorld().playSound(current.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
}
current.remove();
} else {
// Add to list
newItemsInWater.add(current.getUniqueId());
}
}
}
}
// Clean up any items from the list that do not exist anymore
itemsInWater = newItemsInWater;
// plugin.getLogger().info("DEBUG: items in water size = " + itemsInWater.size());
}
}.runTaskTimer(plugin, Settings.acidItemDestroyTime, Settings.acidItemDestroyTime);
}
}
use of org.bukkit.scheduler.BukkitRunnable in project askyblock by tastybento.
the class AcidEffect method onPlayerMove.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
// Fast return if acid isn't being used
if (Settings.rainDamage == 0 && Settings.acidDamage == 0) {
return;
}
final Player player = e.getPlayer();
// Fast checks
if (player.isDead() || player.getGameMode().toString().startsWith("SPECTATOR")) {
return;
}
// Check if in teleport
if (plugin.getPlayers().isInTeleport(player.getUniqueId())) {
return;
}
// Check that they are in the ASkyBlock world
if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
return;
}
// Return if players are immune
if (player.isOp()) {
if (!Settings.damageOps) {
return;
}
} else if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.noburn") || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.noburn")) {
return;
}
if (player.getGameMode().equals(GameMode.CREATIVE)) {
return;
}
/*
if (!e.getTo().toVector().equals(e.getFrom().toVector())) {
// Head movements only
return;
}*/
if (DEBUG)
plugin.getLogger().info("DEBUG: Acid Effect " + e.getEventName());
// Slow checks
final Location playerLoc = player.getLocation();
final Block block = playerLoc.getBlock();
final Block head = block.getRelative(BlockFace.UP);
// Check for acid rain
if (Settings.rainDamage > 0D && isRaining) {
// Only check if they are in a non-dry biome
Biome biome = playerLoc.getBlock().getBiome();
if (biome != Biome.DESERT && biome != Biome.DESERT_HILLS && biome != Biome.SAVANNA && biome != Biome.MESA && biome != Biome.HELL) {
if (isSafeFromRain(player)) {
// plugin.getLogger().info("DEBUG: not hit by rain");
wetPlayers.remove(player);
} else {
// plugin.getLogger().info("DEBUG: hit by rain");
if (!wetPlayers.contains(player)) {
// plugin.getLogger().info("DEBUG: Start hurting player");
// Start hurting them
// Add to the list
wetPlayers.add(player);
// This runnable continuously hurts the player even if
// they are not
// moving but are in acid rain.
new BukkitRunnable() {
@Override
public void run() {
// Check if it is still raining or player is safe or dead or there is no damage
if (!isRaining || player.isDead() || isSafeFromRain(player) || Settings.rainDamage <= 0D) {
// plugin.getLogger().info("DEBUG: Player is dead or it has stopped raining");
wetPlayers.remove(player);
this.cancel();
// Check they are still in this world
} else {
player.damage((Settings.rainDamage - Settings.rainDamage * getDamageReduced(player)));
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
player.getWorld().playSound(playerLoc, Sound.valueOf("FIZZ"), 3F, 3F);
} else {
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
}
}
}
}.runTaskTimer(plugin, 0L, 20L);
}
}
}
}
// back up
if (playerLoc.getBlockY() < 1 && Settings.GAMETYPE.equals(GameType.ACIDISLAND)) {
final Vector v = new Vector(player.getVelocity().getX(), 1D, player.getVelocity().getZ());
player.setVelocity(v);
}
// If they are already burning in acid then return
if (burningPlayers.contains(player)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: already burning in acid");
return;
}
// plugin.getLogger().info("DEBUG: no acid water is false");
if (isSafeFromAcid(player)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: safe from acid");
return;
}
// ACID!
// plugin.getLogger().info("DEBUG: Acid!");
// Put the player into the acid list
burningPlayers.add(player);
// This runnable continuously hurts the player even if they are not
// moving but are in acid.
new BukkitRunnable() {
@Override
public void run() {
if (player.isDead() || isSafeFromAcid(player)) {
burningPlayers.remove(player);
this.cancel();
} else {
if (!Settings.acidDamageType.isEmpty()) {
for (PotionEffectType t : Settings.acidDamageType) {
if (t.equals(PotionEffectType.BLINDNESS) || t.equals(PotionEffectType.CONFUSION) || t.equals(PotionEffectType.HUNGER) || t.equals(PotionEffectType.SLOW) || t.equals(PotionEffectType.SLOW_DIGGING) || t.equals(PotionEffectType.WEAKNESS)) {
player.addPotionEffect(new PotionEffect(t, 600, 1));
} else {
// Poison
player.addPotionEffect(new PotionEffect(t, 200, 1));
}
}
}
// Apply damage if there is any
if (Settings.acidDamage > 0D) {
player.damage((Settings.acidDamage - Settings.acidDamage * getDamageReduced(player)));
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
player.getWorld().playSound(playerLoc, Sound.valueOf("FIZZ"), 3F, 3F);
} else {
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
}
}
}
}
}.runTaskTimer(plugin, 0L, 20L);
}
use of org.bukkit.scheduler.BukkitRunnable in project askyblock by tastybento.
the class IslandGuard method onBlockIgnite.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockIgnite(final BlockIgniteEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info(e.getCause().name());
}
if (!inWorld(e.getBlock())) {
// plugin.getLogger().info("DEBUG: Not in world");
return;
}
// Check if this is a portal lighting
if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: portal lighting");
return;
}
if (e.getCause() != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: ignite cause = " + e.getCause());
switch(e.getCause()) {
case ENDER_CRYSTAL:
case EXPLOSION:
case FIREBALL:
case LIGHTNING:
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire");
e.setCancelled(true);
}
break;
case FLINT_AND_STEEL:
Set<Material> transparent = new HashSet<Material>();
transparent.add(Material.AIR);
if (DEBUG) {
plugin.getLogger().info("DEBUG: block = " + e.getBlock());
// plugin.getLogger().info("DEBUG: target block = " + e.getPlayer().getTargetBlock(transparent, 10));
}
// Check if this is allowed
if (e.getPlayer() != null && (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypass"))) {
return;
}
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire");
// If this was not a player, just stop it
if (e.getPlayer() == null) {
e.setCancelled(true);
break;
}
// Get target block
Block targetBlock = e.getPlayer().getTargetBlock(transparent, 10);
if (targetBlock.getType().equals(Material.OBSIDIAN)) {
final MaterialData md = new MaterialData(e.getBlock().getType(), e.getBlock().getData());
new BukkitRunnable() {
@Override
public void run() {
if (e.getBlock().getType().equals(Material.FIRE)) {
e.getBlock().setType(md.getItemType());
e.getBlock().setData(md.getData());
}
}
}.runTask(plugin);
} else {
e.setCancelled(true);
}
}
break;
case LAVA:
case SPREAD:
// Check if this is a portal lighting
if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: obsidian lighting");
return;
}
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE_SPREAD)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire spread");
e.setCancelled(true);
}
break;
default:
break;
}
}
}
use of org.bukkit.scheduler.BukkitRunnable in project LandLord by SpatiumPrinceps.
the class Addfriend method onAddfriend.
public void onAddfriend(Player player, String[] names) {
Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
OwnedLand land = plugin.getWgHandler().getRegion(chunk);
if (land != null) {
if (!land.isOwner(player.getUniqueId()) && !player.hasPermission("landlord.admin.modifyfriends")) {
player.sendMessage(lm.getString("Commands.Addfriend.notOwn").replace("%owner%", land.printOwners()));
return;
}
if (names.length == 0) {
player.sendMessage(lm.getString("Commands.Addfriend.noPlayer").replace("%players%", Arrays.asList(names).toString()));
return;
}
for (String target : names) {
plugin.getPlayerManager().getOfflinePlayer(target, lPlayer -> {
if (lPlayer == null) {
player.sendMessage(lm.getString("Commands.Addfriend.noPlayer").replace("%players%", Arrays.asList(names).toString()));
} else {
// Success
if (!land.getWGLand().getOwners().getUniqueIds().contains(lPlayer.getUuid())) {
land.getWGLand().getMembers().addPlayer(lPlayer.getUuid());
player.sendMessage(lm.getString("Commands.Addfriend.success").replace("%players%", Arrays.asList(names).toString()));
} else {
player.sendMessage(lm.getString("Commands.Addfriend.alreadyOwn"));
}
}
});
// lets delay it, because we cant be sure, that the requests are done when executing this piece of code
new BukkitRunnable() {
@Override
public void run() {
plugin.getMapManager().updateAll();
}
}.runTaskLater(plugin, 60L);
}
}
}
use of org.bukkit.scheduler.BukkitRunnable in project LandLord by SpatiumPrinceps.
the class AddfriendAll method onAddfriend.
public void onAddfriend(Player player, String name) {
if (name == null || name.isEmpty()) {
player.sendMessage(lm.getString("Commands.AddfriendAll.noPlayer").replace("%player%", name == null ? "[]" : name));
return;
}
plugin.getPlayerManager().getOfflinePlayer(name, lPlayer -> {
if (lPlayer == null) {
// Failure
player.sendMessage(lm.getString("Commands.AddfriendAll.noPlayer").replace("%player%", name));
} else {
int count = 0;
for (ProtectedRegion protectedRegion : plugin.getWgHandler().getRegions(player.getUniqueId())) {
if (!protectedRegion.getMembers().getUniqueIds().contains(lPlayer.getUuid())) {
protectedRegion.getMembers().addPlayer(lPlayer.getUuid());
count++;
}
}
player.sendMessage(lm.getString("Commands.AddfriendAll.success").replace("%player%", name).replace("%count%", count + ""));
new BukkitRunnable() {
@Override
public void run() {
plugin.getMapManager().updateAll();
}
}.runTask(plugin);
}
});
}
Aggregations