2016-01-13 21:14:34 +00:00
|
|
|
package com.projectkorra.projectkorra.ability;
|
|
|
|
|
2016-01-19 02:14:07 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
2016-01-13 21:14:34 +00:00
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.World.Environment;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
|
|
|
|
2016-01-19 02:14:07 +00:00
|
|
|
import com.projectkorra.projectkorra.GeneralMethods;
|
|
|
|
import com.projectkorra.rpg.event.EventManager;
|
2016-01-13 21:14:34 +00:00
|
|
|
|
2016-01-19 02:14:07 +00:00
|
|
|
/**
|
|
|
|
* ElementalAbility is used to hold methods that should be accessible by every
|
2017-01-16 06:48:20 +00:00
|
|
|
* Air, Water, Earth, Fire, Chi, or AvatarAbility. This class is mainly used to
|
|
|
|
* keep CoreAbility from becoming too cluttered.
|
2016-01-19 02:14:07 +00:00
|
|
|
*/
|
2016-01-13 21:14:34 +00:00
|
|
|
public abstract class ElementalAbility extends CoreAbility {
|
2017-01-16 06:48:20 +00:00
|
|
|
private static final PotionEffectType[] POSITIVE_EFFECTS = { PotionEffectType.ABSORPTION, PotionEffectType.DAMAGE_RESISTANCE, PotionEffectType.FAST_DIGGING, PotionEffectType.FIRE_RESISTANCE, PotionEffectType.HEAL, PotionEffectType.HEALTH_BOOST, PotionEffectType.INCREASE_DAMAGE, PotionEffectType.JUMP, PotionEffectType.NIGHT_VISION, PotionEffectType.REGENERATION, PotionEffectType.SATURATION, PotionEffectType.SPEED, PotionEffectType.WATER_BREATHING };
|
|
|
|
private static final PotionEffectType[] NEUTRAL_EFFECTS = { PotionEffectType.INVISIBILITY };
|
|
|
|
private static final PotionEffectType[] NEGATIVE_EFFECTS = { PotionEffectType.POISON, PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.WITHER };
|
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public ElementalAbility(Player player) {
|
|
|
|
super(player);
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public boolean isTransparent(Block block) {
|
|
|
|
return isTransparent(player, getName(), block);
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2017-08-06 07:18:12 +00:00
|
|
|
public static Material[] getTransparentMaterials() {
|
|
|
|
return GeneralMethods.NON_OPAQUE;
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2017-08-06 07:18:12 +00:00
|
|
|
public static HashSet<Material> getTransparentMaterialSet() {
|
|
|
|
HashSet<Material> set = new HashSet<Material>();
|
|
|
|
for (Material material : getTransparentMaterials()) {
|
|
|
|
set.add(material);
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return set;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isDay(World world) {
|
|
|
|
long time = world.getTime();
|
|
|
|
if (world.getEnvironment() == Environment.NETHER || world.getEnvironment() == Environment.THE_END) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
if (time >= 23500 || time <= 12500) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-15 01:07:59 +00:00
|
|
|
public static boolean isEarth(Block block) {
|
|
|
|
return block != null ? isEarth(block.getType()) : false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-15 01:07:59 +00:00
|
|
|
public static boolean isEarth(Material material) {
|
|
|
|
return getConfig().getStringList("Properties.Earth.EarthBlocks").contains(material.toString());
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isFullMoon(World world) {
|
|
|
|
if (GeneralMethods.hasRPG()) {
|
|
|
|
return EventManager.marker.get(world).equalsIgnoreCase("FullMoon");
|
|
|
|
} else {
|
|
|
|
long days = world.getFullTime() / 24000;
|
|
|
|
long phase = days % 8;
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
if (phase == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-01-15 01:07:59 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isIce(Block block) {
|
2016-02-27 07:57:55 +00:00
|
|
|
return block != null ? isIce(block.getType()) : false;
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|
2016-01-15 01:07:59 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isIce(Material material) {
|
2016-02-27 07:57:55 +00:00
|
|
|
return getConfig().getStringList("Properties.Water.IceBlocks").contains(material.toString());
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isLava(Block block) {
|
|
|
|
return block != null ? isLava(block.getType()) : false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isLava(Material material) {
|
|
|
|
return material == Material.LAVA || material == Material.STATIONARY_LAVA;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-08-10 20:53:38 +00:00
|
|
|
public static boolean isSnow(Block block) {
|
|
|
|
return block != null ? isSnow(block.getType()) : false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-04-14 01:00:21 +00:00
|
|
|
public static boolean isSnow(Material material) {
|
|
|
|
return getConfig().getStringList("Properties.Water.SnowBlocks").contains(material.toString());
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isLunarEclipse(World world) {
|
2016-01-19 02:14:07 +00:00
|
|
|
if (world == null || !GeneralMethods.hasRPG()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-19 02:14:07 +00:00
|
|
|
return EventManager.marker.get(world).equalsIgnoreCase("LunarEclipse");
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-19 02:14:07 +00:00
|
|
|
public static boolean isSolarEclipse(World world) {
|
2016-12-11 19:43:39 +00:00
|
|
|
if (world == null || !GeneralMethods.hasRPG() || !EventManager.marker.containsKey(world)) {
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return EventManager.marker.get(world).equalsIgnoreCase("SolarEclipse");
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isMeltable(Block block) {
|
|
|
|
if (block.getType() == Material.ICE || block.getType() == Material.SNOW) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isMetal(Block block) {
|
|
|
|
return block != null ? isMetal(block.getType()) : false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isMetal(Material material) {
|
|
|
|
return getConfig().getStringList("Properties.Earth.MetalBlocks").contains(material.toString());
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isMetalBlock(Block block) {
|
2017-01-16 06:48:20 +00:00
|
|
|
if (block.getType() == Material.GOLD_BLOCK || block.getType() == Material.IRON_BLOCK || block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE || block.getType() == Material.QUARTZ_BLOCK || block.getType() == Material.QUARTZ_ORE) {
|
2016-01-13 21:14:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isNegativeEffect(PotionEffectType effect) {
|
|
|
|
for (PotionEffectType effect2 : NEGATIVE_EFFECTS) {
|
|
|
|
if (effect2.equals(effect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isNeutralEffect(PotionEffectType effect) {
|
|
|
|
for (PotionEffectType effect2 : NEUTRAL_EFFECTS) {
|
|
|
|
if (effect2.equals(effect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isNight(World world) {
|
|
|
|
if (world.getEnvironment() == Environment.NETHER || world.getEnvironment() == Environment.THE_END) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
long time = world.getTime();
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
if (time >= 12950 && time <= 23050) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isPlant(Block block) {
|
2016-02-27 07:57:55 +00:00
|
|
|
return block != null ? isPlant(block.getType()) : false;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-02-27 07:57:55 +00:00
|
|
|
public static boolean isPlant(Material material) {
|
|
|
|
return getConfig().getStringList("Properties.Water.PlantBlocks").contains(material.toString());
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|
2016-01-15 01:07:59 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isPositiveEffect(PotionEffectType effect) {
|
|
|
|
for (PotionEffectType effect2 : POSITIVE_EFFECTS) {
|
|
|
|
if (effect2.equals(effect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-15 01:07:59 +00:00
|
|
|
public static boolean isSand(Block block) {
|
2017-01-16 06:48:20 +00:00
|
|
|
return block != null ? isSand(block.getType()) : false;
|
2016-01-15 01:07:59 +00:00
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-15 01:07:59 +00:00
|
|
|
public static boolean isSand(Material material) {
|
|
|
|
return getConfig().getStringList("Properties.Earth.SandBlocks").contains(material.toString());
|
|
|
|
}
|
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isSozinsComet(World world) {
|
2016-01-19 02:14:07 +00:00
|
|
|
if (world == null || !GeneralMethods.hasRPG()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-19 02:14:07 +00:00
|
|
|
return EventManager.marker.get(world).equalsIgnoreCase("SozinsComet");
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 01:07:59 +00:00
|
|
|
public static boolean isTransparent(Player player, Block block) {
|
|
|
|
return isTransparent(player, null, block);
|
|
|
|
}
|
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isTransparent(Player player, String abilityName, Block block) {
|
2017-08-06 07:18:12 +00:00
|
|
|
return Arrays.asList(getTransparentMaterials()).contains(block.getType()) && !GeneralMethods.isRegionProtectedFromBuild(player, abilityName, block.getLocation());
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isUndead(Entity entity) {
|
|
|
|
if (entity == null) {
|
|
|
|
return false;
|
2017-01-16 06:48:20 +00:00
|
|
|
} else if (entity.getType() == EntityType.ZOMBIE || entity.getType() == EntityType.BLAZE || entity.getType() == EntityType.GIANT || entity.getType() == EntityType.IRON_GOLEM || entity.getType() == EntityType.MAGMA_CUBE || entity.getType() == EntityType.PIG_ZOMBIE || entity.getType() == EntityType.SKELETON || entity.getType() == EntityType.SLIME || entity.getType() == EntityType.SNOWMAN || entity.getType() == EntityType.ZOMBIE) {
|
2016-01-13 21:14:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-08-06 07:18:12 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isWater(Block block) {
|
|
|
|
return block != null ? isWater(block.getType()) : null;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
public static boolean isWater(Material material) {
|
|
|
|
return material == Material.WATER || material == Material.STATIONARY_WATER;
|
|
|
|
}
|
2017-01-16 06:48:20 +00:00
|
|
|
|
2016-01-13 21:14:34 +00:00
|
|
|
}
|