Improved codestyle (7/?)
This commit is contained in:
@@ -13,4 +13,4 @@ public class InkArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.SQUID_INK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ public class LavaArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.DRIP_LAVA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,4 @@ public class LimeArtifact extends Artifact {
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.fromRGB(3, 252, 140), 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ public class MagicArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.CRIT_MAGIC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ public class MagmaArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.LAVA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ public class MusicArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.NOTE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ public class NetherArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.PORTAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,14 @@ public class MisfortuneCurse extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDropItems(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Incandescence extends EcoEnchant {
|
||||
public Incandescence() {
|
||||
super(
|
||||
@@ -18,24 +20,31 @@ public class Incandescence extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onIncandescenceHurt(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
public void onIncandescenceHurt(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof LivingEntity))
|
||||
if (!(event.getDamager() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
LivingEntity victim = (LivingEntity) event.getDamager();
|
||||
|
||||
int totalIncandescencePoints = EnchantChecks.getArmorPoints(player, this, 1);
|
||||
|
||||
if (totalIncandescencePoints == 0)
|
||||
if (totalIncandescencePoints == 0) {
|
||||
return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
}
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
victim.setFireTicks(totalIncandescencePoints * this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-point") + this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-ticks"));
|
||||
}, 1);
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> victim.setFireTicks(totalIncandescencePoints
|
||||
* this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-point")
|
||||
+ this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-ticks")),
|
||||
1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.bukkit.event.block.BlockDropItemEvent;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -29,8 +30,13 @@ import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class InfernalTouch extends EcoEnchant {
|
||||
private static final HashMap<Material, Pair<Material, Integer>> recipes = new HashMap<>();
|
||||
private static final Set<Material> allowsFortune = new HashSet<>(Arrays.asList(Material.GOLD_INGOT, Material.IRON_INGOT));
|
||||
private static final HashMap<Material, Pair<Material, Integer>> RECIPES = new HashMap<>();
|
||||
private static final Set<Material> FORTUNE_MATERIALS = new HashSet<>(
|
||||
Arrays.asList(
|
||||
Material.GOLD_INGOT,
|
||||
Material.IRON_INGOT
|
||||
)
|
||||
);
|
||||
|
||||
public InfernalTouch() {
|
||||
super(
|
||||
@@ -47,36 +53,49 @@ public class InfernalTouch extends EcoEnchant {
|
||||
}
|
||||
FurnaceRecipe furnaceRecipe = (FurnaceRecipe) recipe;
|
||||
int xp = (int) Math.ceil(furnaceRecipe.getExperience());
|
||||
recipes.put(furnaceRecipe.getInput().getType(), new Pair<>(furnaceRecipe.getResult().getType(), xp));
|
||||
RECIPES.put(furnaceRecipe.getInput().getType(), new Pair<>(furnaceRecipe.getResult().getType(), xp));
|
||||
}
|
||||
}
|
||||
|
||||
private static Pair<Material, Integer> getOutput(Material input) {
|
||||
Pair<Material, Integer> toReturn = recipes.get(input);
|
||||
if(toReturn == null) return new Pair<>(input, 0);
|
||||
@NotNull
|
||||
private static Pair<Material, Integer> getOutput(@NotNull final Material input) {
|
||||
Pair<Material, Integer> toReturn = RECIPES.get(input);
|
||||
if (toReturn == null) {
|
||||
return new Pair<>(input, 0);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void infernalTouchBreak(BlockDropItemEvent event) {
|
||||
public void infernalTouchBreak(@NotNull final BlockDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this)) return;
|
||||
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlock().getState() instanceof Container)
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled())
|
||||
if (event.getBlock().getState() instanceof Container) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<ItemStack> drops = new ArrayList<>();
|
||||
|
||||
@@ -92,7 +111,7 @@ public class InfernalTouch extends EcoEnchant {
|
||||
itemStack.setType(out.getFirst());
|
||||
experience += out.getSecond();
|
||||
|
||||
if(fortune > 0 && allowsFortune.contains(itemStack.getType())) {
|
||||
if (fortune > 0 && FORTUNE_MATERIALS.contains(itemStack.getType())) {
|
||||
itemStack.setAmount((int) Math.ceil(1 / ((double) fortune + 2) + ((double) fortune + 1) / 2));
|
||||
experience++;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,22 @@ public class Inferno extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onTridentLaunch(@NotNull LivingEntity shooter, @NotNull Trident trident, int level, @NotNull ProjectileLaunchEvent event) {
|
||||
public void onTridentLaunch(@NotNull final LivingEntity shooter,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
final @NotNull ProjectileLaunchEvent event) {
|
||||
trident.setFireTicks(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(trident.getFireTicks() <= 0) return;
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (trident.getFireTicks() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
victim.setFireTicks(100);
|
||||
}
|
||||
|
||||
@@ -25,17 +25,23 @@ public class Infuriate extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onDeflect(@NotNull Player blocker, @NotNull LivingEntity attacker, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
public void onDeflect(@NotNull final Player blocker,
|
||||
@NotNull final LivingEntity attacker,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double distancePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level");
|
||||
final double distance = distancePerLevel * level;
|
||||
|
||||
for (Entity e : attacker.getWorld().getNearbyEntities(attacker.getLocation(), distance, distance, distance)) {
|
||||
if(!(e instanceof Monster)) continue;
|
||||
if (!(e instanceof Monster)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(e instanceof PigZombie) {
|
||||
if (e instanceof PigZombie) {
|
||||
((PigZombie) e).setAngry(true);
|
||||
}
|
||||
|
||||
@@ -43,7 +49,7 @@ public class Infuriate extends EcoEnchant {
|
||||
|
||||
Vector vector = attacker.getLocation().toVector().clone().subtract(e.getLocation().toVector()).normalize().multiply(0.23d);
|
||||
|
||||
if(VectorUtils.isFinite(vector)) {
|
||||
if (VectorUtils.isFinite(vector)) {
|
||||
e.setVelocity(vector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,14 @@ public class Insecticide extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!(victim instanceof Spider))
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(victim instanceof Spider)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
@@ -20,12 +20,17 @@ public class Instantaneous extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onDamageBlock(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockDamageEvent event) {
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
public void onDamageBlock(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockDamageEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(block.getDrops(player.getInventory().getItemInMainHand()).isEmpty())
|
||||
if (block.getDrops(player.getInventory().getItemInMainHand()).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AnticheatManager.exemptPlayer(player);
|
||||
|
||||
@@ -33,4 +38,4 @@ public class Instantaneous extends EcoEnchant {
|
||||
|
||||
AnticheatManager.unexemptPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Invigoration extends EcoEnchant {
|
||||
public Invigoration() {
|
||||
super(
|
||||
@@ -18,20 +20,25 @@ public class Invigoration extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onInvigorationHurt(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
public void onInvigorationHurt(@NotNull final EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (player.getHealth() > this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "below-health"))
|
||||
if (player.getHealth() > this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "below-health")) {
|
||||
return;
|
||||
}
|
||||
|
||||
int totalInvigorationPoints = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
if (totalInvigorationPoints == 0)
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalInvigorationPoints == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damageReduction = totalInvigorationPoints * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "reduction-multiplier") * 0.01;
|
||||
damageReduction += 1;
|
||||
@@ -39,19 +46,25 @@ public class Invigoration extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvigorationDamage(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player))
|
||||
public void onInvigorationDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getDamager();
|
||||
|
||||
if (player.getHealth() > this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "below-health"))
|
||||
if (player.getHealth() > this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "below-health")) {
|
||||
return;
|
||||
}
|
||||
|
||||
int totalInvigorationPoints = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
if (totalInvigorationPoints == 0)
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalInvigorationPoints == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damageBonus = totalInvigorationPoints * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier") * 0.01;
|
||||
damageBonus += 1;
|
||||
|
||||
@@ -18,11 +18,15 @@ public class Kinetic extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(@NotNull LivingEntity victim, int level, @NotNull EntityDamageEvent event) {
|
||||
if(!event.getCause().equals(EntityDamageEvent.DamageCause.FLY_INTO_WALL)) return;
|
||||
public void onDamageWearingArmor(@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.FLY_INTO_WALL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double reduction = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "reduction-per-level");
|
||||
double multiplier = 1 - ((reduction/100) * level);
|
||||
double multiplier = 1 - ((reduction / 100) * level);
|
||||
event.setDamage(event.getDamage() * multiplier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Launch extends EcoEnchant {
|
||||
public Launch() {
|
||||
@@ -19,23 +20,32 @@ public class Launch extends EcoEnchant {
|
||||
|
||||
// START OF LISTENERS
|
||||
@EventHandler
|
||||
public void onFireworkUse(PlayerInteractEvent event) {
|
||||
if (event.getItem() == null) return;
|
||||
|
||||
if (!event.getItem().getType().equals(Material.FIREWORK_ROCKET))
|
||||
public void onFireworkUse(@NotNull final PlayerInteractEvent event) {
|
||||
if (event.getItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getAction().equals(Action.RIGHT_CLICK_AIR))
|
||||
if (!event.getItem().getType().equals(Material.FIREWORK_ROCKET)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!player.isGliding())
|
||||
if (!player.isGliding()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantChecks.chestplate(player, this)) return;
|
||||
if (!EnchantChecks.chestplate(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getChestplateLevel(player, this);
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
@@ -19,7 +19,10 @@ public class Leeching extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level");
|
||||
double amountToHeal = level * multiplier;
|
||||
double newHealth = attacker.getHealth() + amountToHeal;
|
||||
|
||||
@@ -22,9 +22,14 @@ public class Lesion extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage");
|
||||
|
||||
@@ -39,7 +44,9 @@ public class Lesion extends EcoEnchant {
|
||||
|
||||
victim.damage(bleedDamage);
|
||||
|
||||
if(currentBleedCount.get() >= finalBleedCount) bukkitRunnable.cancel();
|
||||
if (currentBleedCount.get() >= finalBleedCount) {
|
||||
bukkitRunnable.cancel();
|
||||
}
|
||||
}).runTaskTimer(0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,14 @@ public class Levitate extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level");
|
||||
|
||||
|
||||
@@ -22,9 +22,14 @@ public class LiquidShot extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!(victim instanceof Blaze || victim instanceof MagmaCube || victim instanceof Enderman))
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(victim instanceof Blaze || victim instanceof MagmaCube || victim instanceof Enderman)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
|
||||
@@ -30,17 +30,24 @@ public class Lumberjack extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) {
|
||||
if (block.hasMetadata("block-ignore"))
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (block.hasMetadata("block-ignore")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) return;
|
||||
if (player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Material> materials = new ArrayList<>();
|
||||
this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "whitelisted-blocks").forEach(name -> materials.add(Material.getMaterial(name.toUpperCase())));
|
||||
|
||||
if(!materials.contains(block.getType()))
|
||||
if (!materials.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int blocksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "blocks-per-level");
|
||||
int limit = level * blocksPerLevel;
|
||||
@@ -49,15 +56,17 @@ public class Lumberjack extends EcoEnchant {
|
||||
|
||||
AnticheatManager.exemptPlayer(player);
|
||||
|
||||
for(Block treeBlock : treeBlocks) {
|
||||
for (Block treeBlock : treeBlocks) {
|
||||
treeBlock.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true));
|
||||
if(!AntigriefManager.canBreakBlock(player, treeBlock)) continue;
|
||||
if (!AntigriefManager.canBreakBlock(player, treeBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, treeBlock);
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> treeBlock.removeMetadata("block-ignore", this.getPlugin()),1);
|
||||
this.getPlugin().getScheduler().runLater(() -> treeBlock.removeMetadata("block-ignore", this.getPlugin()), 1);
|
||||
}
|
||||
|
||||
AnticheatManager.unexemptPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MagmaWalker extends EcoEnchant {
|
||||
public MagmaWalker() {
|
||||
super(
|
||||
@@ -27,14 +29,24 @@ public class MagmaWalker extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onLavaWalk(PlayerMoveEvent event) {
|
||||
public void onLavaWalk(@NotNull final PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(event.getTo() == null) return;
|
||||
if(event.getFrom().getBlock().equals(event.getTo().getBlock())) return;
|
||||
if (event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantChecks.boots(player, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (event.getFrom().getBlock().equals(event.getTo().getBlock())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantChecks.boots(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector[] circle = VectorUtils.getCircle(this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-radius")
|
||||
+ (this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "per-level-radius") * EnchantChecks.getBootsLevel(player, this) - 1));
|
||||
@@ -46,13 +58,19 @@ public class MagmaWalker extends EcoEnchant {
|
||||
|
||||
Block block = player.getWorld().getBlockAt(loc);
|
||||
|
||||
if (!AntigriefManager.canPlaceBlock(player, player.getWorld().getBlockAt(loc))) continue;
|
||||
if (!AntigriefManager.canPlaceBlock(player, player.getWorld().getBlockAt(loc))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!block.getType().equals(Material.LAVA)) continue;
|
||||
if (!block.getType().equals(Material.LAVA)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Levelled data = (Levelled) block.getBlockData();
|
||||
|
||||
if(data.getLevel() != 0) continue;
|
||||
if (data.getLevel() != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
block.setType(Material.OBSIDIAN);
|
||||
|
||||
@@ -70,7 +88,7 @@ public class MagmaWalker extends EcoEnchant {
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
if (block.getType().equals(Material.OBSIDIAN)) {
|
||||
if(!player.getWorld().getBlockAt(player.getLocation().add(0, -1, 0)).equals(block)) {
|
||||
if (!player.getWorld().getBlockAt(player.getLocation().add(0, -1, 0)).equals(block)) {
|
||||
block.setType(Material.LAVA);
|
||||
block.removeMetadata("byMagmaWalker", this.getPlugin());
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -30,17 +31,17 @@ public class Magnetic extends EcoEnchant implements EcoRunnable {
|
||||
private double bonus = 1;
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
public void onPlayerJoin(@NotNull final PlayerJoinEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
public void onPlayerLeave(@NotNull final PlayerQuitEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ public class Magnetic extends EcoEnchant implements EcoRunnable {
|
||||
players.clear();
|
||||
this.getPlugin().getServer().getOnlinePlayers().forEach(player -> {
|
||||
int level = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
if(level > 0) {
|
||||
if (level > 0) {
|
||||
players.put(player, level);
|
||||
}
|
||||
});
|
||||
@@ -60,10 +61,14 @@ public class Magnetic extends EcoEnchant implements EcoRunnable {
|
||||
public void run() {
|
||||
players.forEach((player, level) -> {
|
||||
double distance = initialDistance + (level * bonus);
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entity e : player.getWorld().getNearbyEntities(player.getLocation(), distance, 2.0d, distance)) {
|
||||
if(!(e instanceof Item || e instanceof ExperienceOrb)) continue;
|
||||
if (!(e instanceof Item || e instanceof ExperienceOrb)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (e instanceof Item && ((Item) e).getPickupDelay() > 0) {
|
||||
continue;
|
||||
@@ -71,7 +76,7 @@ public class Magnetic extends EcoEnchant implements EcoRunnable {
|
||||
|
||||
Vector vector = player.getLocation().toVector().subtract(e.getLocation().toVector()).normalize().multiply(0.1 * level);
|
||||
|
||||
if(VectorUtils.isFinite(vector)) {
|
||||
if (VectorUtils.isFinite(vector)) {
|
||||
e.setVelocity(vector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,26 +22,30 @@ public class Marking extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||
int ticks = ticksPerLevel * level;
|
||||
|
||||
victim.setMetadata("marked", new FixedMetadataValue(this.getPlugin(), true));
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
victim.removeMetadata("marked", this.getPlugin());
|
||||
}, ticks);
|
||||
this.getPlugin().getScheduler().runLater(() -> victim.removeMetadata("marked", this.getPlugin()), ticks);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHitWhileMarked(EntityDamageEvent event) {
|
||||
if(!(event.getEntity() instanceof LivingEntity))
|
||||
public void onHitWhileMarked(@NotNull final EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if(!victim.hasMetadata("marked"))
|
||||
if (!victim.hasMetadata("marked")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak"));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Marksman extends EcoEnchant {
|
||||
public Marksman() {
|
||||
super(
|
||||
@@ -19,19 +21,28 @@ public class Marksman extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onMarksmanShoot(ProjectileLaunchEvent event) {
|
||||
if (event.getEntityType() != EntityType.ARROW)
|
||||
public void onMarksmanShoot(@NotNull final ProjectileLaunchEvent event) {
|
||||
if (event.getEntityType() != EntityType.ARROW) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof Player))
|
||||
if (!(event.getEntity().getShooter() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity().getShooter();
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this)) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Arrow)) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
Arrow a = (Arrow) event.getEntity();
|
||||
a.setGravity(false);
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.bukkit.entity.WitherSkeleton;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Necrotic extends EcoEnchant {
|
||||
public Necrotic() {
|
||||
super(
|
||||
@@ -21,22 +23,31 @@ public class Necrotic extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void necroticKill(EntityDeathEvent event) {
|
||||
if (event.getEntity().getKiller() == null)
|
||||
public void necroticKill(@NotNull final EntityDeathEvent event) {
|
||||
if (event.getEntity().getKiller() == null) {
|
||||
return;
|
||||
if (!(event.getEntity() instanceof WitherSkeleton))
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof WitherSkeleton)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getEntity().getKiller();
|
||||
WitherSkeleton victim = (WitherSkeleton) event.getEntity();
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(Material.WITHER_SKELETON_SKULL, 1);
|
||||
|
||||
|
||||
@@ -19,9 +19,13 @@ public class NetherInfusion extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!attacker.getWorld().getEnvironment().equals(World.Environment.NETHER))
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!attacker.getWorld().getEnvironment().equals(World.Environment.NETHER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Indestructibility extends EcoEnchant {
|
||||
public Indestructibility() {
|
||||
super(
|
||||
@@ -18,17 +20,23 @@ public class Indestructibility extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onItemDamage(PlayerItemDamageEvent event) {
|
||||
public void onItemDamage(@NotNull final PlayerItemDamageEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
if (!EnchantChecks.item(item, this)) return;
|
||||
if (!EnchantChecks.item(item, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.getDisabledWorlds().contains(event.getPlayer().getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(event.getPlayer().getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
double level = EnchantChecks.getItemLevel(item, this);
|
||||
double levelbonus = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "level-bonus");
|
||||
double levelBonus = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "level-bonus");
|
||||
|
||||
if(NumberUtils.randFloat(0, 1) < (100/ (level + (1 + levelbonus))/100)) return;
|
||||
if (NumberUtils.randFloat(0, 1) < (100 / (level + (1 + levelBonus)) / 100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
event.setDamage(0);
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Instability extends EcoEnchant {
|
||||
public Instability() {
|
||||
super(
|
||||
@@ -20,20 +22,28 @@ public class Instability extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onInstabilityLand(ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.ARROW)
|
||||
public void onInstabilityLand(@NotNull final ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.ARROW) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof Player))
|
||||
if (!(event.getEntity().getShooter() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity().getShooter();
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this)) return;
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Arrow)) return;
|
||||
if (!(event.getEntity() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
||||
@@ -42,7 +52,10 @@ public class Instability extends EcoEnchant {
|
||||
|
||||
float power = (float) (0.5 + (level * 0.5));
|
||||
|
||||
if (!AntigriefManager.canCreateExplosion(player, event.getEntity().getLocation())) return;
|
||||
if (!AntigriefManager.canCreateExplosion(player, event.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (breakblocks) {
|
||||
breakblocks = AntigriefManager.canBreakBlock(player, event.getEntity().getLocation().getWorld().getBlockAt(event.getEntity().getLocation()));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Intellect extends EcoEnchant {
|
||||
public Intellect() {
|
||||
super(
|
||||
@@ -17,16 +19,22 @@ public class Intellect extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onExpChange(NaturalExpGainEvent event) {
|
||||
public void onExpChange(@NotNull final NaturalExpGainEvent event) {
|
||||
Player player = event.getExpChangeEvent().getPlayer();
|
||||
|
||||
if(event.getExpChangeEvent().getAmount() < 0) return;
|
||||
if (event.getExpChangeEvent().getAmount() < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
||||
if(level == 0) return;
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getExpChangeEvent().setAmount((int) Math.ceil(event.getExpChangeEvent().getAmount() * (1 + (level * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-point")))));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ public class LifeSteal extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level");
|
||||
double amountToHeal = level * multiplier;
|
||||
double newHealth = attacker.getHealth() + amountToHeal;
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Missile extends Spell {
|
||||
public Missile() {
|
||||
@@ -17,7 +18,9 @@ public class Missile extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final PlayerInteractEvent event) {
|
||||
WitherSkull skull = player.launchProjectile(WitherSkull.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity")));
|
||||
skull.setCharged(true);
|
||||
skull.setIsIncendiary(false);
|
||||
@@ -27,9 +30,14 @@ public class Missile extends Spell {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onWitherSkullDamage(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof WitherSkull)) return;
|
||||
if (event.getDamager().getMetadata("eco-damage").isEmpty()) return;
|
||||
public void onWitherSkullDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof WitherSkull)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getDamager().getMetadata("eco-damage").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = event.getDamager().getMetadata("eco-damage").get(0).asDouble();
|
||||
|
||||
@@ -37,9 +45,14 @@ public class Missile extends Spell {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWitherSkullExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof WitherSkull)) return;
|
||||
if (event.getEntity().getMetadata("nobreak").isEmpty()) return;
|
||||
public void onWitherSkullExplode(@NotNull final EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof WitherSkull)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntity().getMetadata("nobreak").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class Quake extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(@NotNull Player player, int level, @NotNull PlayerInteractEvent event) {
|
||||
int radius = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "radius-per-level") * level;
|
||||
int damage = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Vitalize extends Spell {
|
||||
public Vitalize() {
|
||||
@@ -11,7 +12,7 @@ public class Vitalize extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(@NotNull Player player, int level, @NotNull PlayerInteractEvent event) {
|
||||
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -27,14 +29,15 @@ import java.util.UUID;
|
||||
* Wrapper for Spell enchantments
|
||||
*/
|
||||
public abstract class Spell extends EcoEnchant {
|
||||
private final HashMap<UUID, SpellRunnable> cooldownTracker = new HashMap<>();
|
||||
private final HashMap<UUID, SpellRunnable> tracker = new HashMap<>();
|
||||
private final Set<UUID> runningSpell = new HashSet<>();
|
||||
private static final List<Material> leftClickItems = Arrays.asList(
|
||||
Material.FISHING_ROD,
|
||||
Material.BOW
|
||||
);
|
||||
|
||||
protected Spell(String key, Prerequisite... prerequisites) {
|
||||
protected Spell(@NotNull final String key,
|
||||
@NotNull final Prerequisite... prerequisites) {
|
||||
super(key, EnchantmentType.SPELL, prerequisites);
|
||||
}
|
||||
|
||||
@@ -47,10 +50,12 @@ public abstract class Spell extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUseEventHandler(PlayerInteractEvent event) {
|
||||
public void onUseEventHandler(@NotNull final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (runningSpell.contains(player.getUniqueId())) return;
|
||||
if (runningSpell.contains(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
runningSpell.add(player.getUniqueId());
|
||||
this.getPlugin().getScheduler().runLater(() -> runningSpell.remove(player.getUniqueId()), 5);
|
||||
|
||||
@@ -64,19 +69,21 @@ public abstract class Spell extends EcoEnchant {
|
||||
}
|
||||
}
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this))
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cooldownTracker.containsKey(player.getUniqueId()))
|
||||
cooldownTracker.put(player.getUniqueId(), new SpellRunnable(this, player));
|
||||
if (!tracker.containsKey(player.getUniqueId())) {
|
||||
tracker.put(player.getUniqueId(), new SpellRunnable(this, player));
|
||||
}
|
||||
|
||||
SpellRunnable runnable = cooldownTracker.get(player.getUniqueId());
|
||||
runnable.setTask(() -> {
|
||||
this.onUse(player, level, event);
|
||||
});
|
||||
SpellRunnable runnable = tracker.get(player.getUniqueId());
|
||||
runnable.setTask(() -> this.onUse(player, level, event));
|
||||
|
||||
int cooldown = getCooldown(this, player);
|
||||
|
||||
@@ -93,26 +100,42 @@ public abstract class Spell extends EcoEnchant {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
public abstract void onUse(Player player, int level, PlayerInteractEvent event);
|
||||
public abstract void onUse(@NotNull Player player,
|
||||
int level,
|
||||
@NotNull PlayerInteractEvent event);
|
||||
|
||||
public static int getCooldown(Spell spell, Player player) {
|
||||
if (!spell.cooldownTracker.containsKey(player.getUniqueId()))
|
||||
spell.cooldownTracker.put(player.getUniqueId(), new SpellRunnable(spell, player));
|
||||
public static int getCooldown(@NotNull final Spell spell,
|
||||
@NotNull final Player player) {
|
||||
if (!spell.tracker.containsKey(player.getUniqueId())) {
|
||||
spell.tracker.put(player.getUniqueId(), new SpellRunnable(spell, player));
|
||||
}
|
||||
|
||||
SpellRunnable runnable = spell.cooldownTracker.get(player.getUniqueId());
|
||||
SpellRunnable runnable = spell.tracker.get(player.getUniqueId());
|
||||
|
||||
long msLeft = runnable.getEndTime() - System.currentTimeMillis();
|
||||
|
||||
long secondsLeft = (long) Math.ceil((double) msLeft / 1000);
|
||||
|
||||
return new Long(secondsLeft).intValue();
|
||||
return NumberConversions.toInt(secondsLeft);
|
||||
}
|
||||
|
||||
public static double getCooldownMultiplier(Player player) {
|
||||
if(player.hasPermission("ecoenchants.cooldowntime.quarter")) return 0.25;
|
||||
if(player.hasPermission("ecoenchants.cooldowntime.third")) return 0.33;
|
||||
if(player.hasPermission("ecoenchants.cooldowntime.half")) return 0.5;
|
||||
if(player.hasPermission("ecoenchants.cooldowntime.75")) return 0.75;
|
||||
public static double getCooldownMultiplier(@NotNull final Player player) {
|
||||
if (player.hasPermission("ecoenchants.cooldowntime.quarter")) {
|
||||
return 0.25;
|
||||
}
|
||||
|
||||
if (player.hasPermission("ecoenchants.cooldowntime.third")) {
|
||||
return 0.33;
|
||||
}
|
||||
|
||||
if (player.hasPermission("ecoenchants.cooldowntime.half")) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
if (player.hasPermission("ecoenchants.cooldowntime.75")) {
|
||||
return 0.75;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,21 +28,32 @@ import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class LootPopulator extends BlockPopulator {
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
if (!Configs.CONFIG.getBool("loot.enabled"))
|
||||
public void populate(@NotNull final World world,
|
||||
final @NotNull Random random,
|
||||
final @NotNull Chunk chunk) {
|
||||
if (!Configs.CONFIG.getBool("loot.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (BlockState state : chunk.getTileEntities()) {
|
||||
Block block = state.getBlock();
|
||||
if (!(block.getState() instanceof Chest)) continue;
|
||||
if (!(block.getState() instanceof Chest)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Chest chestState = (Chest) block.getState();
|
||||
Inventory inventory = chestState.getBlockInventory();
|
||||
|
||||
for (ItemStack item : inventory) {
|
||||
if (item == null) continue;
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(item.getType())) continue;
|
||||
if (item.getType().equals(Material.BOOK)) continue;
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(item.getType())) {
|
||||
continue;
|
||||
}
|
||||
if (item.getType().equals(Material.BOOK)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
HashMap<Enchantment, Integer> toAdd = new HashMap<>();
|
||||
|
||||
@@ -59,27 +70,43 @@ public class LootPopulator extends BlockPopulator {
|
||||
}
|
||||
|
||||
for (EcoEnchant enchantment : enchantments) {
|
||||
if (enchantment == null || enchantment.getRarity() == null) continue;
|
||||
if (enchantment == null || enchantment.getRarity() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getLootProbability() * multiplier)
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getLootProbability() * multiplier) {
|
||||
continue;
|
||||
if (!enchantment.canGetFromLoot())
|
||||
}
|
||||
|
||||
if (!enchantment.canGetFromLoot()) {
|
||||
continue;
|
||||
if (!enchantment.canEnchantItem(item))
|
||||
}
|
||||
|
||||
if (!enchantment.canEnchantItem(item)) {
|
||||
continue;
|
||||
if (!enchantment.isEnabled())
|
||||
}
|
||||
|
||||
if (!enchantment.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AtomicBoolean anyConflicts = new AtomicBoolean(false);
|
||||
toAdd.forEach((enchant, integer) -> {
|
||||
if (enchantment.conflictsWithAny(toAdd.keySet())) anyConflicts.set(true);
|
||||
if (enchant.conflictsWith(enchantment)) anyConflicts.set(true);
|
||||
if (enchantment.conflictsWithAny(toAdd.keySet())) {
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
if (enchant.conflictsWith(enchantment)) {
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant);
|
||||
if (enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular())
|
||||
if (enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) {
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
});
|
||||
if (anyConflicts.get()) continue;
|
||||
if (anyConflicts.get()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int level;
|
||||
|
||||
@@ -103,15 +130,11 @@ public class LootPopulator extends BlockPopulator {
|
||||
|
||||
if (item.getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
|
||||
toAdd.forEach(((enchantment, integer) -> {
|
||||
meta.addStoredEnchant(enchantment, integer, false);
|
||||
}));
|
||||
toAdd.forEach(((enchantment, integer) -> meta.addStoredEnchant(enchantment, integer, false)));
|
||||
item.setItemMeta(meta);
|
||||
} else {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
toAdd.forEach(((enchantment, integer) -> {
|
||||
meta.addEnchant(enchantment, integer, false);
|
||||
}));
|
||||
toAdd.forEach(((enchantment, integer) -> meta.addEnchant(enchantment, integer, false)));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ public class IntegrationEssentials implements EssentialsWrapper {
|
||||
for (Enchantment enchantment : EcoEnchants.values()) {
|
||||
((Map<String, Enchantment>) FieldUtils.readDeclaredStaticField(Enchantments.class, "ENCHANTMENTS", true)).put(enchantment.getKey().getKey(), enchantment);
|
||||
}
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
} catch (IllegalAccessException ignored) {
|
||||
// Ignore reflective errors that won't happen.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.willfp.ecoenchants.integrations.mcmmo;
|
||||
|
||||
import com.willfp.eco.util.ClassUtils;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -10,18 +12,20 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
/**
|
||||
* Utility class for interfacing with mcMMO
|
||||
*/
|
||||
@UtilityClass
|
||||
public class McmmoManager {
|
||||
private static final Set<McmmoIntegration> integrations = new HashSet<>();
|
||||
private static final Set<McmmoIntegration> REGISTERED = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new mcMMO integration
|
||||
*
|
||||
* @param integration The integration to register
|
||||
*/
|
||||
public static void registerIntegration(McmmoIntegration integration) {
|
||||
if(!ClassUtils.exists("com.gmail.nossr50.events.fake.FakeEvent"))
|
||||
public static void registerIntegration(@NotNull final McmmoIntegration integration) {
|
||||
if (!ClassUtils.exists("com.gmail.nossr50.events.fake.FakeEvent")) {
|
||||
return;
|
||||
integrations.add(integration);
|
||||
}
|
||||
REGISTERED.add(integration);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,10 +34,12 @@ public class McmmoManager {
|
||||
* @param event The event to check
|
||||
* @return If the event is fake
|
||||
*/
|
||||
public static boolean isFake(Event event) {
|
||||
public static boolean isFake(@NotNull final Event event) {
|
||||
AtomicBoolean isFake = new AtomicBoolean(false);
|
||||
integrations.forEach(integration -> {
|
||||
if (integration.isFake(event)) isFake.set(true);
|
||||
REGISTERED.forEach(integration -> {
|
||||
if (integration.isFake(event)) {
|
||||
isFake.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
return isFake.get();
|
||||
|
||||
@@ -3,13 +3,14 @@ package com.willfp.ecoenchants.integrations.mcmmo.plugins;
|
||||
import com.gmail.nossr50.events.fake.FakeEvent;
|
||||
import com.willfp.ecoenchants.integrations.mcmmo.McmmoIntegration;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Concrete implementation of {@link McmmoIntegration}
|
||||
*/
|
||||
public class McmmoIntegrationImpl implements McmmoIntegration {
|
||||
@Override
|
||||
public boolean isFake(Event event) {
|
||||
public boolean isFake(@NotNull final Event event) {
|
||||
return event instanceof FakeEvent;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.util.config.configs;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Wrapper for lang.yml
|
||||
@@ -19,7 +20,7 @@ public class Lang extends BaseConfig {
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages.no-permission"));
|
||||
}
|
||||
|
||||
public String getMessage(String message) {
|
||||
public String getMessage(@NotNull final String message) {
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages." + message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user