Began migration to new listener system

This commit is contained in:
BuildTools 2020-09-24 12:36:41 +01:00
parent 36caff8728
commit e9b78175b0
41 changed files with 395 additions and 190 deletions

View File

@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
import com.willfp.ecoenchants.enchantments.util.Watcher;
import com.willfp.ecoenchants.util.Registerable;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.WordUtils;
@ -17,7 +18,7 @@ import java.lang.reflect.Field;
import java.util.*;
@SuppressWarnings("unchecked")
public abstract class EcoEnchant extends Enchantment implements Listener, Registerable {
public abstract class EcoEnchant extends Enchantment implements Listener, Registerable, Watcher {
private String name;
private String description;
private final String permissionName;

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Color;
import org.bukkit.Particle;
public class CloudsArtifact extends Artifact {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class DamageArtifact extends Artifact {
public DamageArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class DragonArtifact extends Artifact {
public DragonArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class DustArtifact extends Artifact {
public DustArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class EmeraldArtifact extends Artifact {
public EmeraldArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class EnchantmentArtifact extends Artifact {
public EnchantmentArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class EndArtifact extends Artifact {
public EndArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class FireArtifact extends Artifact {
public FireArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class HeartArtifact extends Artifact {
public HeartArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class HoneyArtifact extends Artifact {
public HoneyArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class InkArtifact extends Artifact {
public InkArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class LavaArtifact extends Artifact {
public LavaArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Color;
import org.bukkit.Particle;

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class MagicArtifact extends Artifact {
public MagicArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class MagmaArtifact extends Artifact {
public MagmaArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class MusicArtifact extends Artifact {
public MusicArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class NetherArtifact extends Artifact {
public NetherArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Color;
import org.bukkit.Particle;
public class RedstoneArtifact extends Artifact {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class SmokeArtifact extends Artifact {
public SmokeArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class SnowArtifact extends Artifact {
public SnowArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class SparkleArtifact extends Artifact {
public SparkleArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class TotemArtifact extends Artifact {
public TotemArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class WaterArtifact extends Artifact {
public WaterArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Particle;
public class WitchArtifact extends Artifact {
public WitchArtifact() {

View File

@ -1,6 +1,6 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import org.bukkit.Color;
import org.bukkit.Particle;
public class ZapArtifact extends Artifact {

View File

@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.util.NumberUtils;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockDamageEvent;
@ -17,12 +18,9 @@ public class BreaklessnessCurse extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onDamageBlock(BlockDamageEvent event) {
Player player = event.getPlayer();
if (!EnchantChecks.mainhand(player, this)) return;
@Override
public void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) {
if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance"))
return;

View File

@ -19,19 +19,9 @@ public class HarmlessnessCurse extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void harmlessnessHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.getEntity() instanceof Monster)
return;
Player player = (Player) event.getDamager();
if (!EnchantChecks.mainhand(player, this)) return;
@Override
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance"))
return;

View File

@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.util.NumberUtils;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityShootBowEvent;
@ -20,18 +21,9 @@ public class InaccuracyCurse extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onShoot(EntityShootBowEvent event) {
if (event.getProjectile().getType() != EntityType.ARROW)
return;
if (!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getEntity();
if (!EnchantChecks.mainhand(player, this)) return;
@Override
public void onBowShoot(LivingEntity shooter, int level, EntityShootBowEvent event) {
double spread = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "spread");
Vector velocity = event.getProjectile().getVelocity().clone();

View File

@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.util.NumberUtils;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
@ -17,12 +18,9 @@ public class MisfortuneCurse extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
if (!EnchantChecks.mainhand(player, this)) return;
@Override
public void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) {
if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance"))
return;

View File

@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.nms.TridentStack;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
@ -20,20 +21,9 @@ public class Abattoir extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident))
return;
if(event.getEntity() instanceof Monster) return;
Trident trident = (Trident) event.getDamager();
ItemStack item = TridentStack.getTridentStack(trident);
if(!EnchantChecks.item(item, this))
return;
int level = EnchantChecks.getItemLevel(item, this);
@Override
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {
if(victim instanceof Monster) return;
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager;
import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.util.ItemDurability;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -23,28 +24,14 @@ public class Abrasion extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof Player))
return;
if (event.isCancelled())
return;
Player player = (Player) event.getDamager();
Player victim = (Player) event.getEntity();
if(!AntigriefManager.canInjure(player, victim)) return;
if (!EnchantChecks.mainhand(player, this)) return;
int level = EnchantChecks.getMainhandLevel(player, this);
@Override
public void onMeleeAttack(LivingEntity attacker, LivingEntity uncastVictim, int level, EntityDamageByEntityEvent event) {
if(!(uncastVictim instanceof Player)) return;
Player victim = (Player) uncastVictim;
boolean notcharged = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged");
if (Cooldown.getCooldown(player) != 1.0f && !notcharged)
if (attacker instanceof Player && Cooldown.getCooldown((Player) attacker) != 1.0f && !notcharged)
return;
ArrayList<ItemStack> armor = new ArrayList<ItemStack>(Arrays.asList(victim.getInventory().getArmorContents()));
@ -55,18 +42,17 @@ public class Abrasion extends EcoEnchant {
if (armorPiece == null)
continue;
if(armorPiece.equals(victim.getInventory().getHelmet())) {
ItemDurability.damageItem(player, player.getInventory().getHelmet(), level, 39);
ItemDurability.damageItem(victim, victim.getInventory().getHelmet(), level, 39);
}
if(armorPiece.equals(victim.getInventory().getChestplate())) {
ItemDurability.damageItem(player, player.getInventory().getChestplate(), level, 38);
ItemDurability.damageItem(victim, victim.getInventory().getChestplate(), level, 38);
}
if(armorPiece.equals(victim.getInventory().getLeggings())) {
ItemDurability.damageItem(player, player.getInventory().getLeggings(), level, 37);
ItemDurability.damageItem(victim, victim.getInventory().getLeggings(), level, 37);
}
if(armorPiece.equals(victim.getInventory().getBoots())) {
ItemDurability.damageItem(player, player.getInventory().getBoots(), level, 36);
ItemDurability.damageItem(victim, victim.getInventory().getBoots(), level, 36);
}
}
}

View File

@ -1,14 +1,17 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.command.AbstractCommand;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.metadata.FixedMetadataValue;
@ -21,33 +24,20 @@ public class Aerial extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onLaunch(ProjectileLaunchEvent event) {
if(!(event.getEntity() instanceof Arrow))
return;
if(!(event.getEntity().getShooter() instanceof Player))
return;
@Override
public void onBowShoot(LivingEntity shooter, int level, EntityShootBowEvent event) {
if(!(event.getProjectile() instanceof Arrow)) return;
Arrow arrow = (Arrow) event.getEntity();
Player player = (Player) arrow.getShooter();
if(shooter.isOnGround()) return;
if(player.isOnGround()) return;
arrow.setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
event.getProjectile().setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Arrow))
return;
Arrow arrow = (Arrow) event.getDamager();
if(!EnchantChecks.arrow(arrow, this)) return;
@Override
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
if(!arrow.hasMetadata("shot-in-air")) return;
int level = EnchantChecks.getArrowLevel(arrow, this);
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier-per-level");
double reduction = 1 + (multiplier * level);

View File

@ -21,31 +21,12 @@ public class Aquatic extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident))
@Override
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {
if(!attacker.getLocation().getBlock().getType().equals(Material.WATER))
return;
if(!(((Trident) event.getDamager()).getShooter() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.isCancelled())
return;
Player player = (Player) ((Trident) event.getDamager()).getShooter();
Trident trident = (Trident) event.getDamager();
ItemStack item = TridentStack.getTridentStack(trident);
if(!player.getLocation().getBlock().getType().equals(Material.WATER))
return;
if (!EnchantChecks.item(item, this)) return;
int level = EnchantChecks.getItemLevel(item, this);
double perLevelDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "percent-more-per-level");
double totalDamagePercent = (100 + (perLevelDamage * level))/100;

View File

@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.nms.TridentStack;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
@ -20,20 +21,10 @@ public class Arachnid extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident))
return;
if(!(event.getEntity() instanceof Spider)) return;
Trident trident = (Trident) event.getDamager();
ItemStack item = TridentStack.getTridentStack(trident);
if(!EnchantChecks.item(item, this))
return;
int level = EnchantChecks.getItemLevel(item, this);
@Override
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {
if(!(victim instanceof Spider)) return;
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.util.NumberUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
@ -16,24 +17,14 @@ public class Arcanic extends EcoEnchant {
}
// START OF LISTENERS
@EventHandler
public void onEffect(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player))
return;
@Override
public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) {
if (!(event.getCause().equals(EntityDamageEvent.DamageCause.POISON) || event.getCause().equals(EntityDamageEvent.DamageCause.WITHER)))
return;
Player player = (Player) event.getEntity();
int totalArcanicPoints = EnchantChecks.getArmorPoints(player, this, 0);
if (totalArcanicPoints == 0)
return;
double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point");
if (NumberUtils.randFloat(0, 1) > totalArcanicPoints * 0.01 * chance)
if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance)
return;
event.setCancelled(true);

View File

@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.nms.TridentStack;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
@ -23,33 +24,16 @@ public class Atmospheric extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onLaunch(ProjectileLaunchEvent event) {
if(!(event.getEntity() instanceof Trident))
return;
if(!(event.getEntity().getShooter() instanceof Player))
return;
Trident trident = (Trident) event.getEntity();
Player player = (Player) trident.getShooter();
if(player.isOnGround()) return;
@Override
public void onTridentLaunch(LivingEntity shooter, Trident trident, int level, ProjectileLaunchEvent event) {
if(shooter.isOnGround()) return;
trident.setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident))
return;
Trident trident = (Trident) event.getDamager();
@Override
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {
if(!trident.hasMetadata("shot-in-air")) return;
ItemStack item = TridentStack.getTridentStack(trident);
if(!EnchantChecks.item(item, this)) return;
int level = EnchantChecks.getItemLevel(item, this);
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier-per-level");

View File

@ -1,7 +1,10 @@
package com.willfp.ecoenchants.enchantments;
package com.willfp.ecoenchants.enchantments.itemtypes;
import com.google.common.util.concurrent.AtomicDouble;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.nms.TridentStack;
import com.willfp.ecoenchants.util.NumberUtils;

View File

@ -0,0 +1,28 @@
package com.willfp.ecoenchants.enchantments.util;
import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent;
import org.bukkit.block.Block;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.PlayerMoveEvent;
public interface Watcher {
default void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {}
default void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {}
default void onJump(Player player, int level, PlayerMoveEvent event) {}
default void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {}
default void onBowShoot(LivingEntity shooter, int level, EntityShootBowEvent event) {}
default void onFallDamage(LivingEntity shooter, int level, EntityDamageEvent event) {}
default void onArrowHit(LivingEntity shooter, int level, ProjectileHitEvent event) {}
default void onTridentHit(LivingEntity shooter, int level, ProjectileHitEvent event) {}
default void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) {}
default void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) {}
default void onArmorEquip(Player player, int level, ArmorEquipEvent event) {}
default void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) {}
default void onTridentLaunch(LivingEntity shooter, Trident trident, int level, ProjectileLaunchEvent event) {}
}

View File

@ -0,0 +1,280 @@
package com.willfp.ecoenchants.enchantments.util;
import com.google.common.collect.Sets;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent;
import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager;
import com.willfp.ecoenchants.nms.TridentStack;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffectType;
import java.text.DecimalFormat;
import java.util.Set;
import java.util.UUID;
public class WatcherTriggers implements Listener {
@EventHandler(ignoreCancelled = true)
public void onArrowDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Arrow))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if(!(((Arrow) event.getDamager()).getShooter() instanceof LivingEntity))
return;
LivingEntity attacker = (LivingEntity) ((Arrow) event.getDamager()).getShooter();
Arrow arrow = (Arrow) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if(attacker instanceof Player) {
if (!AntigriefManager.canInjure((Player) attacker, victim)) return;
}
if(event.isCancelled()) return;
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.arrow(arrow, enchant)) return;
int level = EnchantChecks.getArrowLevel(arrow, enchant);
enchant.onArrowDamage(attacker, victim, arrow, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onTridentDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident))
return;
if(!(((Trident) event.getDamager()).getShooter() instanceof LivingEntity))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.isCancelled())
return;
LivingEntity attacker = (LivingEntity) ((Trident) event.getDamager()).getShooter();
Trident trident = (Trident) event.getDamager();
ItemStack item = TridentStack.getTridentStack(trident);
LivingEntity victim = (LivingEntity) event.getEntity();
if(attacker instanceof Player) {
if (!AntigriefManager.canInjure((Player) attacker, victim)) return;
}
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.item(item, enchant)) return;
int level = EnchantChecks.getItemLevel(item, enchant);
enchant.onTridentDamage(attacker, victim, trident, level, event);
}));
}
private static final Set<UUID> prevPlayersOnGround = Sets.newHashSet();
private static final DecimalFormat df = new DecimalFormat("0.00");
@EventHandler(ignoreCancelled = true)
public void onJump(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (player.getVelocity().getY() > 0) {
float jumpVelocity = 0.42f;
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
jumpVelocity += ((float) player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.1F;
}
jumpVelocity = Float.parseFloat(df.format(jumpVelocity).replace(',', '.'));
if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER && prevPlayersOnGround.contains(player.getUniqueId())) {
if (!player.isOnGround() && Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) {
EcoEnchants.getAll().forEach((enchant -> {
int level = EnchantChecks.getArmorPoints(player, enchant);
if(level == 0) return;
enchant.onJump(player, level, event);
}));
}
}
}
if (player.isOnGround()) {
prevPlayersOnGround.add(player.getUniqueId());
} else {
prevPlayersOnGround.remove(player.getUniqueId());
}
}
@EventHandler(ignoreCancelled = true)
public void onMeleeAttack(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof LivingEntity))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.isCancelled())
return;
LivingEntity attacker = (LivingEntity) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if(attacker instanceof Player) {
if (!AntigriefManager.canInjure((Player) attacker, victim)) return;
}
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.mainhand(attacker, enchant)) return;
int level = EnchantChecks.getMainhandLevel(attacker, enchant);
enchant.onMeleeAttack(attacker, victim, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onBowShoot(EntityShootBowEvent event) {
if (event.getProjectile().getType() != EntityType.ARROW)
return;
LivingEntity shooter = event.getEntity();
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.mainhand(shooter, enchant)) return;
int level = EnchantChecks.getMainhandLevel(shooter, enchant);
enchant.onBowShoot(shooter, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onFallDamage(EntityDamageEvent event) {
if(!event.getCause().equals(EntityDamageEvent.DamageCause.FALL))
return;
if(!(event.getEntity() instanceof LivingEntity))
return;
LivingEntity victim = (LivingEntity) event.getEntity();
EcoEnchants.getAll().forEach((enchant -> {
int level = EnchantChecks.getArmorPoints(victim, enchant);
if(level == 0) return;
enchant.onFallDamage(victim, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onArrowHit(ProjectileHitEvent event) {
if (!(event.getEntity().getShooter() instanceof LivingEntity))
return;
if (!(event.getEntity() instanceof Arrow)) return;
Arrow arrow = (Arrow) event.getEntity();
LivingEntity shooter = (LivingEntity) event.getEntity().getShooter();
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.arrow(arrow, enchant)) return;
int level = EnchantChecks.getArrowLevel(arrow, enchant);
enchant.onArrowHit(shooter, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onTridentHit(ProjectileHitEvent event) {
if (!(event.getEntity().getShooter() instanceof LivingEntity))
return;
if (!(event.getEntity() instanceof Trident)) return;
Trident trident = (Trident) event.getEntity();
ItemStack item = TridentStack.getTridentStack(trident);
LivingEntity shooter = (LivingEntity) event.getEntity().getShooter();
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.item(item, enchant)) return;
int level = EnchantChecks.getItemLevel(item, enchant);
enchant.onTridentHit(shooter, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if(!AntigriefManager.canBreakBlock(player, block)) return;
if (event.isCancelled())
return;
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.mainhand(player, enchant)) return;
int level = EnchantChecks.getMainhandLevel(player, enchant);
enchant.onBlockBreak(player, block, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onDamageWearingArmor(EntityDamageEvent event) {
if (!(event.getEntity() instanceof LivingEntity))
return;
LivingEntity victim = (LivingEntity) event.getEntity();
EcoEnchants.getAll().forEach((enchant -> {
int level = EnchantChecks.getArmorPoints(victim, enchant);
if(level == 0) return;
enchant.onDamageWearingArmor(victim, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onArmorEquip(ArmorEquipEvent event) {
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
EcoEnchants.getAll().forEach((enchant -> {
int level = EnchantChecks.getArmorPoints(player, enchant);
enchant.onArmorEquip(player, level, event);
}));
}, 1);
}
@EventHandler(ignoreCancelled = true)
public void onDamageBlock(BlockDamageEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.mainhand(player, enchant)) return;
int level = EnchantChecks.getMainhandLevel(player, enchant);
enchant.onDamageBlock(player, block, level, event);
}));
}
@EventHandler(ignoreCancelled = true)
public void onTridentLaunch(ProjectileLaunchEvent event) {
if(!(event.getEntity() instanceof Trident))
return;
if(!(event.getEntity().getShooter() instanceof LivingEntity))
return;
Trident trident = (Trident) event.getEntity();
LivingEntity shooter = (LivingEntity) trident.getShooter();
ItemStack item = TridentStack.getTridentStack(trident);
EcoEnchants.getAll().forEach((enchant -> {
if (!EnchantChecks.item(item, enchant)) return;
int level = EnchantChecks.getItemLevel(item, enchant);
enchant.onTridentLaunch(shooter, trident, level, event);
}));
}
}

View File

@ -16,6 +16,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import com.willfp.ecoenchants.enchantments.util.WatcherTriggers;
import com.willfp.ecoenchants.events.armorequip.ArmorListener;
import com.willfp.ecoenchants.events.armorequip.DispenserArmorListener;
import com.willfp.ecoenchants.events.entitydeathbyentity.EntityDeathByEntityListeners;
@ -241,6 +242,7 @@ public class Loader {
Bukkit.getPluginManager().registerEvents(new NaturalExpGainListeners(), EcoEnchantsPlugin.getInstance());
Bukkit.getPluginManager().registerEvents(new VillagerListeners(), EcoEnchantsPlugin.getInstance());
Bukkit.getPluginManager().registerEvents(new ArrowListeners(), EcoEnchantsPlugin.getInstance());
Bukkit.getPluginManager().registerEvents(new WatcherTriggers(), EcoEnchantsPlugin.getInstance());
Logger.info("");
/*