mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-23 05:41:19 +01:00
Improved codestyle (10/?)
This commit is contained in:
parent
c97ca2f9c2
commit
931d35495a
@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -15,12 +16,12 @@ public class Target extends BaseConfig {
|
||||
}
|
||||
|
||||
public Set<String> getTargets() {
|
||||
return config.getConfigurationSection("targets").getKeys(false);
|
||||
return this.getConfig().getConfigurationSection("targets").getKeys(false);
|
||||
}
|
||||
|
||||
public Set<Material> getTargetMaterials(String target) {
|
||||
public Set<Material> getTargetMaterials(@NotNull final String target) {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
config.getStringList("targets." + target).forEach((materialName) -> {
|
||||
this.getConfig().getStringList("targets." + target).forEach((materialName) -> {
|
||||
materials.add(Material.getMaterial(materialName.toUpperCase()));
|
||||
});
|
||||
|
||||
|
@ -8,29 +8,32 @@ import com.willfp.ecoenchants.display.options.sorting.implementations.RarityType
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.RarityTypeLengthSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.TypeAlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.TypeLengthSorter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class SorterManager {
|
||||
private static final Set<EnchantmentSorter> values = new HashSet<>();
|
||||
private static final Set<EnchantmentSorter> REGISTERED = new HashSet<>();
|
||||
|
||||
public static EnchantmentSorter getSorter(SortParameters... parameters) {
|
||||
return values.stream()
|
||||
public static EnchantmentSorter getSorter(@NotNull final SortParameters... parameters) {
|
||||
return REGISTERED.stream()
|
||||
.filter(enchantmentSorter -> Arrays.asList(enchantmentSorter.getParameters()).containsAll(Arrays.asList(parameters)) && enchantmentSorter.getParameters().length == parameters.length)
|
||||
.findFirst()
|
||||
.orElse(new AlphabeticSorter());
|
||||
}
|
||||
|
||||
static {
|
||||
values.add(new AlphabeticSorter());
|
||||
values.add(new LengthSorter());
|
||||
values.add(new TypeAlphabeticSorter());
|
||||
values.add(new TypeLengthSorter());
|
||||
values.add(new RarityAlphabeticSorter());
|
||||
values.add(new RarityLengthSorter());
|
||||
values.add(new RarityTypeAlphabeticSorter());
|
||||
values.add(new RarityTypeLengthSorter());
|
||||
REGISTERED.add(new AlphabeticSorter());
|
||||
REGISTERED.add(new LengthSorter());
|
||||
REGISTERED.add(new TypeAlphabeticSorter());
|
||||
REGISTERED.add(new TypeLengthSorter());
|
||||
REGISTERED.add(new RarityAlphabeticSorter());
|
||||
REGISTERED.add(new RarityLengthSorter());
|
||||
REGISTERED.add(new RarityTypeAlphabeticSorter());
|
||||
REGISTERED.add(new RarityTypeLengthSorter());
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,4 @@ public class SmokeArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.CAMPFIRE_COSY_SMOKE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,4 @@ public class SoulArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.SOUL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,4 @@ public class SoulFireArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.SOUL_FIRE_FLAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,4 @@ public class SparkleArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.FIREWORKS_SPARK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,4 @@ public class TotemArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.TOTEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,4 @@ public class WarpedArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.WARPED_SPORE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,4 @@ public class WaterArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.DRIP_WATER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,4 @@ public class WitchArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.SPELL_WITCH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,4 @@ public class ZapArtifact extends Artifact {
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.YELLOW, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,30 +9,46 @@ 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 ShotAssist extends EcoEnchant {
|
||||
public ShotAssist() {
|
||||
super(
|
||||
"shot_assist", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
@EventHandler
|
||||
public void onHit(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Arrow))
|
||||
return;
|
||||
if(!(((Arrow) event.getDamager()).getShooter() instanceof Player))
|
||||
return;
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
return;
|
||||
|
||||
if(event.isCancelled()) return;
|
||||
@EventHandler
|
||||
public void onHit(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) ((Arrow) event.getDamager()).getShooter();
|
||||
|
||||
assert player != null;
|
||||
|
||||
int points = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(points == 0) return;
|
||||
if (points == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
@ -20,9 +20,14 @@ public class Sickening 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");
|
||||
|
||||
|
@ -17,8 +17,14 @@ public class Slaughter extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(victim instanceof Monster) return;
|
||||
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 Monster) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
public class Slicing extends EcoEnchant {
|
||||
@ -22,14 +23,20 @@ public class Slicing extends EcoEnchant {
|
||||
private final ArrayList<LivingEntity> entities = new ArrayList<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCollide(PlayerMoveEvent event) {
|
||||
public void onPlayerCollide(@NotNull final PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!player.isGliding())
|
||||
if (!player.isGliding()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantChecks.chestplate(player, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (!EnchantChecks.chestplate(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entity entity : player.getNearbyEntities(1, 1, 1)) {
|
||||
LivingEntity victim;
|
||||
@ -39,8 +46,9 @@ public class Slicing extends EcoEnchant {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entities.contains(victim))
|
||||
if (entities.contains(victim)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level");
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -27,31 +28,44 @@ public class Spearfishing extends EcoEnchant {
|
||||
"spearfishing", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSpearfishingLand(ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.TRIDENT)
|
||||
public void onSpearfishingLand(@NotNull final ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.TRIDENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof Player))
|
||||
if (!(event.getEntity().getShooter() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Trident)) return;
|
||||
if (!(event.getEntity() instanceof Trident)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Trident trident = (Trident) event.getEntity();
|
||||
|
||||
if(!trident.getWorld().getBlockAt(trident.getLocation().add(0, 0.2, 0)).getType().equals(Material.WATER))
|
||||
if (!trident.getWorld().getBlockAt(trident.getLocation().add(0, 0.2, 0)).getType().equals(Material.WATER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity().getShooter();
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident);
|
||||
|
||||
if (!EnchantChecks.item(item, this)) return;
|
||||
if (!EnchantChecks.item(item, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getItemLevel(item, this);
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Material> potentialDrops = new ArrayList<>();
|
||||
this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "drops").forEach(material -> {
|
||||
|
@ -9,6 +9,8 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Spiked extends EcoEnchant {
|
||||
public Spiked() {
|
||||
super(
|
||||
@ -16,23 +18,34 @@ public class Spiked extends EcoEnchant {
|
||||
);
|
||||
}
|
||||
@EventHandler
|
||||
public void onFish(PlayerFishEvent event) {
|
||||
if(!event.getState().equals(PlayerFishEvent.State.CAUGHT_ENTITY))
|
||||
public void onFish(@NotNull final PlayerFishEvent event) {
|
||||
if (!event.getState().equals(PlayerFishEvent.State.CAUGHT_ENTITY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(event.getCaught() instanceof LivingEntity))
|
||||
if (!(event.getCaught() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getCaught();
|
||||
|
||||
if(victim.hasMetadata("NPC")) return;
|
||||
if (victim.hasMetadata("NPC")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!AntigriefManager.canInjure(player, victim)) return;
|
||||
if (!AntigriefManager.canInjure(player, victim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -18,6 +18,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Splash extends EcoEnchant {
|
||||
public Splash() {
|
||||
super(
|
||||
@ -25,14 +27,18 @@ public class Splash extends EcoEnchant {
|
||||
);
|
||||
}
|
||||
@EventHandler
|
||||
public void onSplashLand(ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.TRIDENT)
|
||||
public void onSplashLand(@NotNull final ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.TRIDENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof Player))
|
||||
if (!(event.getEntity().getShooter() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Trident)) return;
|
||||
if (!(event.getEntity() instanceof Trident)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -41,8 +47,13 @@ public class Splash extends EcoEnchant {
|
||||
|
||||
ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident);
|
||||
|
||||
if (!EnchantChecks.item(item, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (!EnchantChecks.item(item, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getItemLevel(item, this);
|
||||
|
||||
@ -50,16 +61,27 @@ public class Splash extends EcoEnchant {
|
||||
double damage = level * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level");
|
||||
|
||||
for (Entity e : trident.getNearbyEntities(radius, radius, radius)) {
|
||||
if(e.hasMetadata("NPC")) continue;
|
||||
if (e.hasMetadata("NPC")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(e instanceof LivingEntity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(e instanceof LivingEntity)) continue;
|
||||
LivingEntity entity = (LivingEntity) e;
|
||||
if(e.equals(player)) continue;
|
||||
|
||||
if (e.equals(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new EntityDamageByEntityEvent(trident, entity, EntityDamageEvent.DamageCause.ENTITY_ATTACK, damage));
|
||||
|
||||
if(!AntigriefManager.canInjure(player, entity)) continue;
|
||||
if (!AntigriefManager.canInjure(player, entity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.damage(damage, trident);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,10 @@ public class Stab 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 baseDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-base");
|
||||
double perLevelDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level");
|
||||
double damage = baseDamage + (level * perLevelDamage);
|
||||
|
@ -18,9 +18,12 @@ public class Stalwart extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(@NotNull LivingEntity victim, int level, @NotNull EntityDamageEvent event) {
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
public void onDamageWearingArmor(@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level");
|
||||
duration *= level;
|
||||
|
@ -7,6 +7,8 @@ import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Stamina extends EcoEnchant {
|
||||
public Stamina() {
|
||||
super(
|
||||
@ -14,21 +16,34 @@ public class Stamina extends EcoEnchant {
|
||||
);
|
||||
}
|
||||
@EventHandler
|
||||
public void onStaminaHunger(FoodLevelChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
public void onStaminaHunger(@NotNull final FoodLevelChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if(!player.isSprinting()) return;
|
||||
if (!player.isSprinting()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!EnchantChecks.boots(player, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if(event.getFoodLevel() > player.getFoodLevel()) return;
|
||||
if (!EnchantChecks.boots(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getFoodLevel() > player.getFoodLevel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getBootsLevel(player, this);
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -22,13 +22,21 @@ public class StoneSwitcher extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!block.getType().equals(Material.STONE)) return;
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!block.getType().equals(Material.STONE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDropItems(false);
|
||||
|
||||
@ -39,7 +47,10 @@ public class StoneSwitcher extends EcoEnchant {
|
||||
selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1);
|
||||
String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex);
|
||||
material = Material.getMaterial(materialName.toUpperCase());
|
||||
if(material == null) material = Material.COBBLESTONE;
|
||||
|
||||
if (material == null) {
|
||||
material = Material.COBBLESTONE;
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
|
||||
|
@ -21,12 +21,19 @@ public class StrayAspect extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player
|
||||
&& ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||
|
||||
|
@ -21,7 +21,10 @@ public class Succession extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBowShoot(@NotNull LivingEntity shooter, @NotNull Arrow arrow, int level, @NotNull EntityShootBowEvent event) {
|
||||
public void onBowShoot(@NotNull final LivingEntity shooter,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityShootBowEvent event) {
|
||||
int number = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "extra-arrows");
|
||||
|
||||
boolean fire = EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE);
|
||||
@ -30,7 +33,9 @@ public class Succession extends EcoEnchant {
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
Arrow arrow1 = shooter.launchProjectile(Arrow.class, event.getProjectile().getVelocity());
|
||||
arrow1.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
|
||||
if(fire) arrow1.setFireTicks(Integer.MAX_VALUE);
|
||||
if (fire) {
|
||||
arrow1.setFireTicks(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "per-arrow-damage") && shooter instanceof Player) {
|
||||
DurabilityUtils.damageItem((Player) shooter, ((Player) shooter).getInventory().getItemInMainHand(), 1, ((Player) shooter).getInventory().getHeldItemSlot());
|
||||
|
@ -19,13 +19,19 @@ public class Supercritical extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player
|
||||
&& ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier"));
|
||||
}
|
||||
|
@ -17,7 +17,10 @@ public class Sycophant extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeflect(@NotNull Player blocker, @NotNull LivingEntity attacker, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
public void onDeflect(@NotNull final Player blocker,
|
||||
@NotNull final LivingEntity attacker,
|
||||
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;
|
||||
|
@ -19,10 +19,14 @@ public class Tectonic extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFallDamage(@NotNull LivingEntity faller, int level, @NotNull EntityDamageEvent event) {
|
||||
public void onFallDamage(@NotNull final LivingEntity faller,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL))
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int radius = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-radius") + (this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "per-level-radius") * level - 1);
|
||||
int damage = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-damage") + (this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "per-level-damage") * level - 1);
|
||||
|
||||
@ -30,12 +34,16 @@ public class Tectonic extends EcoEnchant {
|
||||
Collection<Entity> entities = faller.getWorld().getNearbyEntities(faller.getLocation(), radius, 2, radius);
|
||||
|
||||
for (Entity entity : entities) {
|
||||
if (entity.equals(faller))
|
||||
if (entity.equals(faller)) {
|
||||
continue;
|
||||
if(!(entity instanceof LivingEntity)) continue;
|
||||
}
|
||||
if (!(entity instanceof LivingEntity)) {
|
||||
continue;
|
||||
}
|
||||
entity.teleport(entity.getLocation().add(0, 0.3, 0));
|
||||
if(faller instanceof Player && !AntigriefManager.canInjure((Player) faller, (LivingEntity) entity))
|
||||
if (faller instanceof Player && !AntigriefManager.canInjure((Player) faller, (LivingEntity) entity)) {
|
||||
return;
|
||||
}
|
||||
((LivingEntity) entity).damage(damage);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -44,91 +45,130 @@ public class Telekinesis extends EcoEnchant {
|
||||
|
||||
// For block drops
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void telekinesisDropItem(BlockDropItemEvent event) {
|
||||
public void telekinesisDropItem(@NotNull final BlockDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(!always && !EnchantChecks.mainhand(player, this)) return;
|
||||
if(this.getDisabledWorldNames().contains(player.getWorld().getName())) return;
|
||||
if (!always && !EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) return;
|
||||
if (this.getDisabledWorldNames().contains(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) return;
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
for(Item item : event.getItems()) drops.add(item.getItemStack());
|
||||
|
||||
for (Item item : event.getItems()) {
|
||||
drops.add(item.getItemStack());
|
||||
}
|
||||
|
||||
event.getItems().clear();
|
||||
|
||||
DropQueue queue = new DropQueue(player)
|
||||
.setLocation(block.getLocation())
|
||||
.addItems(drops);
|
||||
if(!always) queue.forceTelekinesis();
|
||||
|
||||
if (!always) {
|
||||
queue.forceTelekinesis();
|
||||
}
|
||||
|
||||
queue.push();
|
||||
}
|
||||
|
||||
// For exp drops, blockdropitemevent doesn't cover xp
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void telekinesisBreak(BlockBreakEvent event) {
|
||||
public void telekinesisBreak(@NotNull final BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if(!always && !EnchantChecks.mainhand(player, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)
|
||||
if (!always && !EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled())
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) return;
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(block.getType().equals(Material.SPAWNER)) event.setExpToDrop(0);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (block.getType().equals(Material.SPAWNER)) {
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
|
||||
DropQueue queue = new DropQueue(player)
|
||||
.setLocation(block.getLocation())
|
||||
.addXP(event.getExpToDrop());
|
||||
if(!always) queue.forceTelekinesis();
|
||||
|
||||
if (!always) {
|
||||
queue.forceTelekinesis();
|
||||
}
|
||||
|
||||
queue.push();
|
||||
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void telekinesisKill(EntityDeathByEntityEvent event) {
|
||||
public void telekinesisKill(@NotNull final EntityDeathByEntityEvent event) {
|
||||
Player player = null;
|
||||
LivingEntity entity = event.getVictim();
|
||||
ItemStack item = null;
|
||||
|
||||
if(entity instanceof Player && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "not-on-players"))
|
||||
if (entity instanceof Player && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "not-on-players")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getKiller() instanceof Player) {
|
||||
if (event.getKiller() instanceof Player) {
|
||||
player = (Player) event.getKiller();
|
||||
item = player.getInventory().getItemInMainHand();
|
||||
} else if(event.getKiller() instanceof Arrow) {
|
||||
if(((Arrow) event.getKiller()).getShooter() instanceof Player) {
|
||||
} else if (event.getKiller() instanceof Arrow) {
|
||||
if (((Arrow) event.getKiller()).getShooter() instanceof Player) {
|
||||
player = (Player) ((Arrow) event.getKiller()).getShooter();
|
||||
item = player.getInventory().getItemInMainHand();
|
||||
}
|
||||
} else if(event.getKiller() instanceof Trident) {
|
||||
if(((Trident) event.getKiller()).getShooter() instanceof Player) {
|
||||
} else if (event.getKiller() instanceof Trident) {
|
||||
if (((Trident) event.getKiller()).getShooter() instanceof Player) {
|
||||
player = (Player) ((Trident) event.getKiller()).getShooter();
|
||||
item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack((Trident) event.getKiller());
|
||||
}
|
||||
}
|
||||
|
||||
if(player == null || item == null) return;
|
||||
if (player == null || item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantChecks.item(item, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (!EnchantChecks.item(item, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int xp = event.getXp();
|
||||
Collection<ItemStack> drops = event.getDrops();
|
||||
|
||||
if(entity instanceof Player && Soulbound.getSoulboundItems((Player) entity) != null) {
|
||||
if (entity instanceof Player && Soulbound.getSoulboundItems((Player) entity) != null) {
|
||||
drops.removeAll(Soulbound.getSoulboundItems((Player) entity));
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,19 @@ public class Thor extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player
|
||||
&& ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "lightning-damage");
|
||||
|
||||
|
@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Thrive extends EcoEnchant {
|
||||
public Thrive() {
|
||||
super(
|
||||
@ -17,25 +19,31 @@ public class Thrive extends EcoEnchant {
|
||||
);
|
||||
}
|
||||
@EventHandler
|
||||
public void onArmorEquip(ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
int totalProsperityPoints = EnchantChecks.getArmorPoints(player, EcoEnchants.PROSPERITY, 0);
|
||||
int totalThrivePoints = EnchantChecks.getArmorPoints(player, EcoEnchants.THRIVE, 0);
|
||||
|
||||
if (totalThrivePoints == 0 && totalProsperityPoints == 0) {
|
||||
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
|
||||
return;
|
||||
}
|
||||
if(EcoEnchants.THRIVE.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
if (EcoEnchants.THRIVE.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
double thriveBonus = totalThrivePoints * EcoEnchants.THRIVE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-point");
|
||||
double prosperityBonus = totalProsperityPoints * EcoEnchants.PROSPERITY.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-point");
|
||||
double bonus = thriveBonus + prosperityBonus;
|
||||
|
||||
boolean onMaxHealth = false;
|
||||
if (player.getHealth() == player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())
|
||||
|
||||
if (player.getHealth() == player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
|
||||
onMaxHealth = true;
|
||||
}
|
||||
|
||||
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue() + bonus);
|
||||
boolean finalOnMaxHealth = onMaxHealth;
|
||||
|
@ -16,14 +16,15 @@ public class Tornado 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 baseVelocity = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity-per-level");
|
||||
double yVelocity = baseVelocity * level;
|
||||
|
||||
Vector toAdd = new Vector(0, yVelocity, 0);
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
victim.setVelocity(victim.getVelocity().clone().add(toAdd));
|
||||
}, 1);
|
||||
this.getPlugin().getScheduler().runLater(() -> victim.setVelocity(victim.getVelocity().clone().add(toAdd)), 1);
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,19 @@ public class Toxic extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player
|
||||
&& ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
victim.addPotionEffect(new PotionEffect(PotionEffectType.POISON, level * 10 + 20, level));
|
||||
}
|
||||
|
@ -24,26 +24,36 @@ public class Transfuse extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDropItems(false);
|
||||
|
||||
if(!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "works-on").stream().map(string -> Material.getMaterial(string.toUpperCase())).collect(Collectors.toList()).contains(block.getType()))
|
||||
if (!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "works-on").stream()
|
||||
.map(string -> Material.getMaterial(string.toUpperCase()))
|
||||
.collect(Collectors.toList()).contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material material;
|
||||
double random = NumberUtils.randFloat(0, 1);
|
||||
double band = 1/(double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size();
|
||||
int selectedIndex = (int) Math.floor(random/band);
|
||||
double band = 1 / (double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size();
|
||||
int selectedIndex = (int) Math.floor(random / band);
|
||||
selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1);
|
||||
String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex);
|
||||
material = Material.getMaterial(materialName.toUpperCase());
|
||||
if(material == null) material = Material.COBBLESTONE;
|
||||
if (material == null) {
|
||||
material = Material.COBBLESTONE;
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
|
||||
|
@ -20,17 +20,20 @@ public class Tripleshot extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBowShoot(@NotNull LivingEntity shooter, @NotNull Arrow arrow, int level, @NotNull EntityShootBowEvent event) {
|
||||
|
||||
public void onBowShoot(@NotNull final LivingEntity shooter,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityShootBowEvent event) {
|
||||
for (int i = -1; i < 2; i += 2) {
|
||||
|
||||
Vector velocity = event.getProjectile().getVelocity();
|
||||
|
||||
float radians = (float) ((float) i * Math.toRadians(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "angle")));
|
||||
velocity.rotateAroundY(radians);
|
||||
|
||||
Arrow arrow1 = shooter.launchProjectile(Arrow.class, velocity);
|
||||
if(EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE)) arrow1.setFireTicks(Integer.MAX_VALUE);
|
||||
if (EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE)) {
|
||||
arrow1.setFireTicks(Integer.MAX_VALUE);
|
||||
}
|
||||
arrow1.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,19 @@ public class VampireAspect extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player
|
||||
&& ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, level * 10 + 20, level));
|
||||
}
|
||||
|
@ -27,17 +27,24 @@ public class Vein 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;
|
||||
@ -48,7 +55,9 @@ public class Vein extends EcoEnchant {
|
||||
|
||||
for (Block veinBlock : blockSet) {
|
||||
veinBlock.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true));
|
||||
if (!AntigriefManager.canBreakBlock(player, veinBlock)) continue;
|
||||
if (!AntigriefManager.canBreakBlock(player, veinBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, veinBlock);
|
||||
|
||||
|
@ -18,9 +18,14 @@ public class Venom 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;
|
||||
}
|
||||
|
||||
victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, level * 10 + 20, level));
|
||||
}
|
||||
|
@ -17,9 +17,14 @@ public class VoidAffinity extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END))
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
|
@ -18,7 +18,7 @@ public class Voltage extends EcoEnchant {
|
||||
"voltage", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
private static final Material[] items = {
|
||||
private static final Material[] ITEMS = {
|
||||
Material.IRON_HELMET,
|
||||
Material.IRON_CHESTPLATE,
|
||||
Material.IRON_LEGGINGS,
|
||||
@ -36,17 +36,30 @@ public class Voltage 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) {
|
||||
EntityEquipment equipment = victim.getEquipment();
|
||||
if(equipment == null) return;
|
||||
|
||||
int pieces = 0;
|
||||
for (ItemStack armorPiece : equipment.getArmorContents()) {
|
||||
if(armorPiece == null) continue;
|
||||
if(Arrays.asList(items).contains(armorPiece.getType())) pieces++;
|
||||
if (equipment == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(pieces == 0) return;
|
||||
int pieces = 0;
|
||||
|
||||
for (ItemStack armorPiece : equipment.getArmorContents()) {
|
||||
if (armorPiece == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Arrays.asList(ITEMS).contains(armorPiece.getType())) {
|
||||
pieces++;
|
||||
}
|
||||
}
|
||||
|
||||
if (pieces == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
|
@ -16,9 +16,13 @@ public class WaterAffinity extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!attacker.getLocation().getBlock().getType().equals(Material.WATER))
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!attacker.getLocation().getBlock().getType().equals(Material.WATER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
@ -18,9 +18,13 @@ public class WaterAspect extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!(victim instanceof Blaze || victim instanceof MagmaCube || victim instanceof Enderman))
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
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");
|
||||
|
||||
|
@ -18,26 +18,29 @@ public class Weakening 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) {
|
||||
int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||
int ticks = ticksPerLevel * level;
|
||||
|
||||
victim.setMetadata("weak", new FixedMetadataValue(this.getPlugin(), true));
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
victim.removeMetadata("weak", this.getPlugin());
|
||||
}, ticks);
|
||||
this.getPlugin().getScheduler().runLater(() -> victim.removeMetadata("weak", this.getPlugin()), ticks);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
if(!(event.getEntity() instanceof LivingEntity))
|
||||
public void onDamage(@NotNull final EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if(!victim.hasMetadata("weak"))
|
||||
if (!victim.hasMetadata("weak")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak"));
|
||||
}
|
||||
|
@ -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 Wisdom extends EcoEnchant {
|
||||
public Wisdom() {
|
||||
super(
|
||||
@ -14,14 +16,20 @@ public class Wisdom extends EcoEnchant {
|
||||
);
|
||||
}
|
||||
@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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
||||
|
@ -19,9 +19,14 @@ public class Wound 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;
|
||||
}
|
||||
|
||||
double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage");
|
||||
|
||||
@ -36,7 +41,9 @@ public class Wound extends EcoEnchant {
|
||||
|
||||
victim.damage(bleedDamage);
|
||||
|
||||
if (currentBleedCount.get() >= finalBleedCount) bukkitRunnable.cancel();
|
||||
if (currentBleedCount.get() >= finalBleedCount) {
|
||||
bukkitRunnable.cancel();
|
||||
}
|
||||
}).runTaskTimer(0, 10);
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,14 @@ public class Zeus 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;
|
||||
}
|
||||
|
||||
double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "lightning-damage");
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -21,47 +22,57 @@ public class Soulbound extends EcoEnchant {
|
||||
"soulbound", EnchantmentType.SPECIAL
|
||||
);
|
||||
}
|
||||
private static final HashMap<Player, List<ItemStack>> soulboundItemsMap = new HashMap<>();
|
||||
private static final HashMap<Player, List<ItemStack>> SOULBOUND_ITEMS = new HashMap<>();
|
||||
|
||||
public static List<ItemStack> getSoulboundItems(Player player) {
|
||||
return soulboundItemsMap.get(player);
|
||||
public static List<ItemStack> getSoulboundItems(@NotNull final Player player) {
|
||||
return SOULBOUND_ITEMS.get(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onSoulboundDeath(PlayerDeathEvent event) {
|
||||
if(event.getKeepInventory()) return;
|
||||
public void onSoulboundDeath(@NotNull final PlayerDeathEvent event) {
|
||||
if (event.getKeepInventory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getEntity();
|
||||
List<ItemStack> soulboundItems = new ArrayList<>(); // Stored as list to preserve duplicates
|
||||
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Arrays.stream(player.getInventory().getContents()).filter(Objects::nonNull).forEach((itemStack -> {
|
||||
if(itemStack.containsEnchantment(this)) soulboundItems.add(itemStack);
|
||||
if (itemStack.containsEnchantment(this)) {
|
||||
soulboundItems.add(itemStack);
|
||||
}
|
||||
|
||||
if(itemStack.getItemMeta() instanceof EnchantmentStorageMeta && (((EnchantmentStorageMeta) itemStack.getItemMeta()).getStoredEnchants().containsKey(this))) soulboundItems.add(itemStack);
|
||||
if (itemStack.getItemMeta() instanceof EnchantmentStorageMeta && (((EnchantmentStorageMeta) itemStack.getItemMeta()).getStoredEnchants().containsKey(this))) {
|
||||
soulboundItems.add(itemStack);
|
||||
}
|
||||
}));
|
||||
|
||||
event.getDrops().removeAll(soulboundItems);
|
||||
|
||||
soulboundItemsMap.remove(player);
|
||||
soulboundItemsMap.put(player, soulboundItems);
|
||||
SOULBOUND_ITEMS.remove(player);
|
||||
SOULBOUND_ITEMS.put(player, soulboundItems);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onSoulboundRespawn(PlayerRespawnEvent event) {
|
||||
if(!soulboundItemsMap.containsKey(event.getPlayer())) return;
|
||||
public void onSoulboundRespawn(@NotNull final PlayerRespawnEvent event) {
|
||||
if (!SOULBOUND_ITEMS.containsKey(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> soulboundItems = soulboundItemsMap.get(event.getPlayer());
|
||||
List<ItemStack> soulboundItems = SOULBOUND_ITEMS.get(event.getPlayer());
|
||||
|
||||
soulboundItems.forEach((itemStack -> {
|
||||
if(Arrays.asList(event.getPlayer().getInventory().getContents()).contains(itemStack)) return;
|
||||
if (Arrays.asList(event.getPlayer().getInventory().getContents()).contains(itemStack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPlayer().getInventory().addItem(itemStack);
|
||||
}));
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
soulboundItemsMap.remove(event.getPlayer());
|
||||
}, 1);
|
||||
this.getPlugin().getScheduler().runLater(() -> SOULBOUND_ITEMS.remove(event.getPlayer()), 1);
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,18 @@ public class Spring extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(@NotNull LivingEntity victim, int level, @NotNull EntityDamageEvent event) {
|
||||
public void onDamageWearingArmor(@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJump(@NotNull Player player, int level, @NotNull PlayerMoveEvent event) {
|
||||
public void onJump(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final PlayerMoveEvent event) {
|
||||
double multiplier = 0.5 + ((double) (level * level) / 4 - 0.2) / 3;
|
||||
player.setVelocity(player.getLocation().getDirection().multiply(multiplier).setY(multiplier));
|
||||
}
|
||||
|
@ -15,8 +15,10 @@ public class Streamlining extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArmorEquip(@NotNull Player player, int level, @NotNull ArmorEquipEvent event) {
|
||||
if(level == 0) {
|
||||
public void onArmorEquip(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final ArmorEquipEvent event) {
|
||||
if (level == 0) {
|
||||
player.setWalkSpeed(0.2f);
|
||||
return;
|
||||
}
|
||||
|
@ -21,22 +21,34 @@ public class Volatile extends EcoEnchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity uncastAttacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!(uncastAttacker instanceof Player)) return;
|
||||
public void onMeleeAttack(@NotNull final LivingEntity uncastAttacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(uncastAttacker instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player attacker = (Player) uncastAttacker;
|
||||
|
||||
if (ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown(attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged"))
|
||||
if (ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown(attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean fire = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire");
|
||||
boolean breakblocks = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "break-blocks");
|
||||
|
||||
float power = (float) (0.5 + (level * 0.5));
|
||||
|
||||
if (!AntigriefManager.canCreateExplosion(attacker, event.getEntity().getLocation())) return;
|
||||
if (!AntigriefManager.canCreateExplosion(attacker, event.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (breakblocks && !AntigriefManager.canBreakBlock(attacker, event.getEntity().getLocation().getWorld().getBlockAt(event.getEntity().getLocation()))) {
|
||||
return;
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ public class Vitalize extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUse(@NotNull Player player, int level, @NotNull PlayerInteractEvent event) {
|
||||
public void onUse(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final PlayerInteractEvent event) {
|
||||
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import java.util.UUID;
|
||||
public abstract class Spell extends EcoEnchant {
|
||||
private final HashMap<UUID, SpellRunnable> tracker = new HashMap<>();
|
||||
private final Set<UUID> runningSpell = new HashSet<>();
|
||||
private static final List<Material> leftClickItems = Arrays.asList(
|
||||
private static final List<Material> LEFT_CLICK_ITEMS = Arrays.asList(
|
||||
Material.FISHING_ROD,
|
||||
Material.BOW
|
||||
);
|
||||
@ -59,7 +59,7 @@ public abstract class Spell extends EcoEnchant {
|
||||
runningSpell.add(player.getUniqueId());
|
||||
this.getPlugin().getScheduler().runLater(() -> runningSpell.remove(player.getUniqueId()), 5);
|
||||
|
||||
if (leftClickItems.contains(player.getInventory().getItemInMainHand().getType())) {
|
||||
if (LEFT_CLICK_ITEMS.contains(player.getInventory().getItemInMainHand().getType())) {
|
||||
if (!(event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK))) {
|
||||
return;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -27,12 +28,14 @@ public class VillagerListeners implements Listener {
|
||||
|
||||
// For books
|
||||
@EventHandler
|
||||
public void onVillagerGainBookTrade(VillagerAcquireTradeEvent event) {
|
||||
if (!event.getRecipe().getResult().getType().equals(Material.ENCHANTED_BOOK))
|
||||
public void onVillagerGainBookTrade(@NotNull final VillagerAcquireTradeEvent event) {
|
||||
if (!event.getRecipe().getResult().getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Configs.CONFIG.getBool("villager.enabled"))
|
||||
if (!Configs.CONFIG.getBool("villager.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack result = event.getRecipe().getResult().clone();
|
||||
int uses = event.getRecipe().getUses();
|
||||
@ -42,7 +45,9 @@ public class VillagerListeners implements Listener {
|
||||
float priceMultiplier = event.getRecipe().getPriceMultiplier();
|
||||
List<ItemStack> ingredients = event.getRecipe().getIngredients();
|
||||
|
||||
if (!(result.getItemMeta() instanceof EnchantmentStorageMeta)) return;
|
||||
if (!(result.getItemMeta() instanceof EnchantmentStorageMeta)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) result.getItemMeta();
|
||||
|
||||
@ -52,12 +57,17 @@ public class VillagerListeners implements Listener {
|
||||
double multiplier = 0.01 / Configs.CONFIG.getDouble("villager.book-times-less-likely");
|
||||
|
||||
for (EcoEnchant enchantment : enchantments) {
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier)
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) {
|
||||
continue;
|
||||
if (!enchantment.canGetFromVillager())
|
||||
}
|
||||
|
||||
if (!enchantment.canGetFromVillager()) {
|
||||
continue;
|
||||
if (!enchantment.isEnabled())
|
||||
}
|
||||
|
||||
if (!enchantment.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int level;
|
||||
|
||||
@ -74,9 +84,7 @@ public class VillagerListeners implements Listener {
|
||||
level = (int) Math.ceil(enchantlevel2 / enchantlevel3);
|
||||
}
|
||||
|
||||
meta.getStoredEnchants().forEach(((enchantment1, integer) -> {
|
||||
meta.removeStoredEnchant(enchantment1);
|
||||
}));
|
||||
meta.getStoredEnchants().forEach(((enchantment1, integer) -> meta.removeStoredEnchant(enchantment1)));
|
||||
|
||||
meta.addStoredEnchant(enchantment, level, false);
|
||||
break;
|
||||
@ -91,15 +99,19 @@ public class VillagerListeners implements Listener {
|
||||
|
||||
// For tools
|
||||
@EventHandler
|
||||
public void onVillagerGainItemTrade(VillagerAcquireTradeEvent event) {
|
||||
public void onVillagerGainItemTrade(@NotNull final VillagerAcquireTradeEvent event) {
|
||||
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(event.getRecipe().getResult().getType()))
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(event.getRecipe().getResult().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRecipe().getResult().getType().equals(Material.BOOK)) return;
|
||||
|
||||
if (!Configs.CONFIG.getBool("villager.enabled"))
|
||||
if (event.getRecipe().getResult().getType().equals(Material.BOOK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Configs.CONFIG.getBool("villager.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack result = event.getRecipe().getResult().clone();
|
||||
int uses = event.getRecipe().getUses();
|
||||
@ -109,7 +121,9 @@ public class VillagerListeners implements Listener {
|
||||
float priceMultiplier = event.getRecipe().getPriceMultiplier();
|
||||
List<ItemStack> ingredients = event.getRecipe().getIngredients();
|
||||
|
||||
if (result.getItemMeta() instanceof EnchantmentStorageMeta) return;
|
||||
if (result.getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta meta = result.getItemMeta();
|
||||
|
||||
@ -121,25 +135,42 @@ public class VillagerListeners implements Listener {
|
||||
double multiplier = 0.01;
|
||||
|
||||
for (EcoEnchant enchantment : enchantments) {
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier)
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) {
|
||||
continue;
|
||||
if (!enchantment.canGetFromVillager())
|
||||
}
|
||||
|
||||
if (!enchantment.canGetFromVillager()) {
|
||||
continue;
|
||||
if (!enchantment.canEnchantItem(result))
|
||||
}
|
||||
|
||||
if (!enchantment.canEnchantItem(result)) {
|
||||
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;
|
||||
|
||||
@ -163,9 +194,7 @@ public class VillagerListeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
toAdd.forEach(((enchantment, integer) -> {
|
||||
meta.addEnchant(enchantment, integer, false);
|
||||
}));
|
||||
toAdd.forEach(((enchantment, integer) -> meta.addEnchant(enchantment, integer, false)));
|
||||
|
||||
result.setItemMeta(meta);
|
||||
|
||||
|
@ -4,15 +4,18 @@ package com.willfp.ecoenchants.enchantments.util;
|
||||
import com.willfp.eco.util.lambda.Callable;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SpellRunnable {
|
||||
private final Spell spell;
|
||||
private final Player player;
|
||||
private long endTime = 0;
|
||||
private Callable callable = () -> {
|
||||
// Empty as must be set using this#setTask
|
||||
};
|
||||
|
||||
public SpellRunnable(Spell spell, Player player) {
|
||||
public SpellRunnable(@NotNull final Spell spell,
|
||||
@NotNull final Player player) {
|
||||
this.spell = spell;
|
||||
this.player = player;
|
||||
}
|
||||
@ -34,7 +37,7 @@ public class SpellRunnable {
|
||||
endTime = System.currentTimeMillis() + (long) ((spell.getCooldownTime() * 1000L) * Spell.getCooldownMultiplier(player));
|
||||
}
|
||||
|
||||
public void setTask(Callable callable) {
|
||||
public void setTask(@NotNull final Callable callable) {
|
||||
this.callable = callable;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Set;
|
||||
@ -35,59 +36,94 @@ import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class WatcherTriggers extends PluginDependent implements Listener {
|
||||
public WatcherTriggers(AbstractEcoPlugin plugin) {
|
||||
private static final Set<UUID> PREVIOUS_PLAYERS_ON_GROUND = Sets.newHashSet();
|
||||
private static final DecimalFormat FORMAT = new DecimalFormat("0.00");
|
||||
|
||||
|
||||
public WatcherTriggers(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onArrowDamage(EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onArrowDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
if (!(event.getDamager() instanceof Arrow))
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof Arrow)) {
|
||||
return;
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
if (((Arrow) event.getDamager()).getShooter() == null)
|
||||
}
|
||||
|
||||
if (((Arrow) event.getDamager()).getShooter() == null) {
|
||||
return;
|
||||
if (!(((Arrow) event.getDamager()).getShooter() instanceof LivingEntity))
|
||||
}
|
||||
|
||||
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 (victim.hasMetadata("NPC")) return;
|
||||
if (victim.hasMetadata("NPC")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) return;
|
||||
if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantChecks.getEnchantsOnArrow(arrow).forEach(((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(attacker.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(attacker.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onArrowDamage(attacker, victim, arrow, level, event);
|
||||
}));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onTridentDamage(EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
return;
|
||||
if (!(event.getDamager() instanceof Trident))
|
||||
public void onTridentDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(((Trident) event.getDamager()).getShooter() instanceof LivingEntity))
|
||||
if (!(event.getDamager() instanceof Trident)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((Trident) event.getDamager()).getShooter() == null)
|
||||
if (!(((Trident) event.getDamager()).getShooter() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
if (((Trident) event.getDamager()).getShooter() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled())
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity attacker = (LivingEntity) ((Trident) event.getDamager()).getShooter();
|
||||
Trident trident = (Trident) event.getDamager();
|
||||
@ -95,282 +131,455 @@ public class WatcherTriggers extends PluginDependent implements Listener {
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if (victim.hasMetadata("NPC")) return;
|
||||
if (victim.hasMetadata("NPC")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) return;
|
||||
if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantChecks.getEnchantsOnItem(item).forEach(((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(attacker.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(attacker.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onJump(@NotNull final PlayerMoveEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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())&& !player.isOnGround() && Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) {
|
||||
jumpVelocity = Float.parseFloat(FORMAT.format(jumpVelocity).replace(',', '.'));
|
||||
if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER
|
||||
&& PREVIOUS_PLAYERS_ON_GROUND.contains(player.getUniqueId())
|
||||
&& !player.isOnGround()
|
||||
&& Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) {
|
||||
EnchantChecks.getEnchantsOnArmor(player).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onJump(player, level, event);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (player.isOnGround()) {
|
||||
prevPlayersOnGround.add(player.getUniqueId());
|
||||
PREVIOUS_PLAYERS_ON_GROUND.add(player.getUniqueId());
|
||||
} else {
|
||||
prevPlayersOnGround.remove(player.getUniqueId());
|
||||
PREVIOUS_PLAYERS_ON_GROUND.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onMeleeAttack(EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
return;
|
||||
if (!(event.getDamager() instanceof LivingEntity))
|
||||
public void onMeleeAttack(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
if (!(event.getDamager() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled())
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity attacker = (LivingEntity) event.getDamager();
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if (victim.hasMetadata("NPC")) return;
|
||||
if (victim.hasMetadata("NPC")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) return;
|
||||
if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantChecks.getEnchantsOnMainhand(attacker).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(attacker.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(attacker.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onMeleeAttack(attacker, victim, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBowShoot(EntityShootBowEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onBowShoot(@NotNull final EntityShootBowEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
if (event.getProjectile().getType() != EntityType.ARROW)
|
||||
}
|
||||
|
||||
if (event.getProjectile().getType() != EntityType.ARROW) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity shooter = event.getEntity();
|
||||
Arrow arrow = (Arrow) event.getProjectile();
|
||||
|
||||
EnchantChecks.getEnchantsOnMainhand(shooter).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onBowShoot(shooter, arrow, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onFallDamage(EntityDamageEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
return;
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL))
|
||||
public void onFallDamage(@NotNull final EntityDamageEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
EnchantChecks.getEnchantsOnArmor(victim).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(victim.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(victim.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onFallDamage(victim, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onArrowHit(ProjectileHitEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
return;
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity))
|
||||
public void onArrowHit(@NotNull final ProjectileHitEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Arrow)) return;
|
||||
|
||||
if (event.getEntity().getShooter() == null)
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntity().getShooter() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Arrow arrow = (Arrow) event.getEntity();
|
||||
LivingEntity shooter = (LivingEntity) event.getEntity().getShooter();
|
||||
|
||||
EnchantChecks.getEnchantsOnArrow(arrow).forEach(((enchant, level) -> {
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return;
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onArrowHit(shooter, level, event);
|
||||
}));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onTridentHit(ProjectileHitEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
return;
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity))
|
||||
return;
|
||||
if (event.getEntity().getShooter() == null)
|
||||
public void onTridentHit(@NotNull final ProjectileHitEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Trident)) return;
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntity().getShooter() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Trident)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Trident trident = (Trident) event.getEntity();
|
||||
ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident);
|
||||
LivingEntity shooter = (LivingEntity) event.getEntity().getShooter();
|
||||
|
||||
EnchantChecks.getEnchantsOnItem(item).forEach(((enchant, level) -> {
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return;
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onTridentHit(shooter, level, event);
|
||||
}));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onBlockBreak(@NotNull final BlockBreakEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) return;
|
||||
|
||||
if (event.isCancelled())
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantChecks.getEnchantsOnMainhand(player).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onBlockBreak(player, block, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDamageWearingArmor(EntityDamageEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onDamageWearingArmor(@NotNull final EntityDamageEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
EnchantChecks.getEnchantsOnArmor(victim).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(victim.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(victim.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onDamageWearingArmor(victim, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onArmorEquip(ArmorEquipEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
EcoEnchants.values().forEach((enchant -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
int level = EnchantChecks.getArmorPoints(player, enchant);
|
||||
enchant.onArmorEquip(player, level, event);
|
||||
}));
|
||||
}, 1);
|
||||
this.getPlugin().getScheduler().runLater(() -> EcoEnchants.values().forEach(enchant -> {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getArmorPoints(player, enchant);
|
||||
enchant.onArmorEquip(player, level, event);
|
||||
}), 1);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDamageBlock(BlockDamageEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onDamageBlock(@NotNull final BlockDamageEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (event.getBlock().getDrops(player.getInventory().getItemInMainHand()).isEmpty())
|
||||
if (event.getBlock().getDrops(player.getInventory().getItemInMainHand()).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantChecks.getEnchantsOnMainhand(player).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onDamageBlock(player, block, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onTridentLaunch(ProjectileLaunchEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onTridentLaunch(@NotNull final ProjectileLaunchEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Trident))
|
||||
if (!(event.getEntity() instanceof Trident)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity))
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Trident trident = (Trident) event.getEntity();
|
||||
LivingEntity shooter = (LivingEntity) trident.getShooter();
|
||||
ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident);
|
||||
|
||||
EnchantChecks.getEnchantsOnItem(item).forEach((enchant, level) -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(shooter.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
enchant.onTridentLaunch(shooter, trident, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDeflect(EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event))
|
||||
public void onDeflect(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof LivingEntity))
|
||||
if (!(event.getDamager() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player blocker = (Player) event.getEntity();
|
||||
|
||||
LivingEntity attacker = (LivingEntity) event.getDamager();
|
||||
|
||||
if (!blocker.isBlocking()) return;
|
||||
if (!blocker.isBlocking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canInjure(blocker, attacker)) return;
|
||||
if (!AntigriefManager.canInjure(blocker, attacker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EcoEnchants.values().forEach(enchant -> {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(blocker.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
EcoEnchants.values().forEach((enchant -> {
|
||||
if (event.isCancelled()) return;
|
||||
if (!enchant.isEnabled()) return;
|
||||
if (enchant.getDisabledWorlds().contains(blocker.getWorld())) return;
|
||||
int level;
|
||||
if (!EnchantChecks.offhand(blocker, enchant) && !EnchantChecks.mainhand(blocker, enchant)) return;
|
||||
if (EnchantChecks.offhand(blocker, enchant)) level = EnchantChecks.getOffhandLevel(blocker, enchant);
|
||||
else level = EnchantChecks.getMainhandLevel(blocker, enchant);
|
||||
|
||||
if (!EnchantChecks.offhand(blocker, enchant) && !EnchantChecks.mainhand(blocker, enchant)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (EnchantChecks.offhand(blocker, enchant)) {
|
||||
level = EnchantChecks.getOffhandLevel(blocker, enchant);
|
||||
} else {
|
||||
level = EnchantChecks.getMainhandLevel(blocker, enchant);
|
||||
}
|
||||
enchant.onDeflect(blocker, attacker, level, event);
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,26 @@
|
||||
package com.willfp.ecoenchants.integrations.worldguard;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class WorldguardManager {
|
||||
private static final Set<WorldguardWrapper> worldguardWrappers = new HashSet<>();
|
||||
private static final Set<WorldguardWrapper> REGISTERED = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new WorldGuard integration
|
||||
*
|
||||
* @param worldguard The integration to register
|
||||
*/
|
||||
public static void register(WorldguardWrapper worldguard) {
|
||||
worldguardWrappers.add(worldguard);
|
||||
public static void register(@NotNull final WorldguardWrapper worldguard) {
|
||||
REGISTERED.add(worldguard);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -26,8 +29,9 @@ public class WorldguardManager {
|
||||
* @param flagName The name of the flag
|
||||
* @param defaultValue The default value for the flag to have
|
||||
*/
|
||||
public static void registerFlag(String flagName, boolean defaultValue) {
|
||||
worldguardWrappers.forEach(worldguardWrapper -> worldguardWrapper.registerFlag(flagName, defaultValue));
|
||||
public static void registerFlag(@NotNull final String flagName,
|
||||
final boolean defaultValue) {
|
||||
REGISTERED.forEach(worldguardWrapper -> worldguardWrapper.registerFlag(flagName, defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,10 +41,15 @@ public class WorldguardManager {
|
||||
* @param player The player to query
|
||||
* @return If the enchantment is enabled at a player's location
|
||||
*/
|
||||
public static boolean enabledForPlayer(EcoEnchant enchant, LivingEntity player) {
|
||||
if (!(player instanceof Player)) return true;
|
||||
if(worldguardWrappers.isEmpty()) return true;
|
||||
return worldguardWrappers.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, player.getLocation()));
|
||||
public static boolean enabledForPlayer(@NotNull final EcoEnchant enchant,
|
||||
@NotNull final LivingEntity player) {
|
||||
if (!(player instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
if (REGISTERED.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return REGISTERED.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, player.getLocation()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,9 +60,15 @@ public class WorldguardManager {
|
||||
* @param location The location to query
|
||||
* @return If the enchantment is enabled at a player's location
|
||||
*/
|
||||
public static boolean enabledForPlayer(EcoEnchant enchant, LivingEntity player, Location location) {
|
||||
if (!(player instanceof Player)) return true;
|
||||
if(worldguardWrappers.isEmpty()) return true;
|
||||
return worldguardWrappers.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, location));
|
||||
public static boolean enabledForPlayer(@NotNull final EcoEnchant enchant,
|
||||
@NotNull final LivingEntity player,
|
||||
@NotNull final Location location) {
|
||||
if (!(player instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
if (REGISTERED.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return REGISTERED.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, location));
|
||||
}
|
||||
}
|
||||
|
@ -9,22 +9,30 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.integrations.worldguard.WorldguardWrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorldguardIntegrationImpl implements WorldguardWrapper {
|
||||
private static final FlagRegistry REGISTRY = WorldGuard.getInstance().getFlagRegistry();
|
||||
|
||||
@Override
|
||||
public void registerFlag(String name, boolean def) {
|
||||
public void registerFlag(@NotNull final String name,
|
||||
final boolean def) {
|
||||
StateFlag flag = new StateFlag(name, def);
|
||||
if(REGISTRY.get(name) == null) {
|
||||
if (REGISTRY.get(name) == null) {
|
||||
REGISTRY.register(flag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabledForPlayer(EcoEnchant enchant, Player player, Location location) {
|
||||
if(WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(WorldGuardPlugin.inst().wrapPlayer(player), BukkitAdapter.adapt(location.getWorld()))) return true;
|
||||
return WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), (StateFlag) REGISTRY.get(enchant.getKey().getKey() + "-enabled")) == StateFlag.State.ALLOW;
|
||||
public boolean enabledForPlayer(@NotNull final EcoEnchant enchant,
|
||||
@NotNull final Player player,
|
||||
@NotNull final Location location) {
|
||||
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(WorldGuardPlugin.inst().wrapPlayer(player), BukkitAdapter.adapt(location.getWorld()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
|
||||
.queryState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), (StateFlag) REGISTRY.get(enchant.getKey().getKey() + "-enabled")) == StateFlag.State.ALLOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface TridentStackProxy extends AbstractProxy {
|
||||
|
||||
/**
|
||||
* Get a trident's ItemStack.
|
||||
*
|
||||
@ -14,4 +15,4 @@ public interface TridentStackProxy extends AbstractProxy {
|
||||
* @return The trident's ItemStack.
|
||||
*/
|
||||
ItemStack getTridentStack(@NotNull Trident trident);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class Tropical extends BiomesEnchantment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(@NotNull Biome biome) {
|
||||
public boolean isValid(@NotNull final Biome biome) {
|
||||
return Arrays.stream(new String[]{"jungle"}).anyMatch(biome.name().toLowerCase()::contains);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@ -18,27 +19,43 @@ import java.util.Optional;
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SprintArtifactsListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
public void onPlayerMove(@NotNull final PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(!player.isSprinting()) return;
|
||||
if(!player.isOnGround()) return;
|
||||
if (!player.isSprinting()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.isOnGround()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack boots = player.getInventory().getBoots();
|
||||
if(boots == null) return;
|
||||
if (boots == null) {
|
||||
return;
|
||||
}
|
||||
ItemMeta bootsMeta = boots.getItemMeta();
|
||||
if(bootsMeta == null) return;
|
||||
if (bootsMeta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<EcoEnchant> matching = bootsMeta.getEnchants().keySet().stream()
|
||||
.map(EcoEnchants::getFromEnchantment)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(enchantment -> enchantment.getType().equals(EnchantmentType.ARTIFACT))
|
||||
.findFirst();
|
||||
if(!matching.isPresent()) return;
|
||||
if (!matching.isPresent()) {
|
||||
return;
|
||||
}
|
||||
Artifact artifact = (Artifact) matching.get();
|
||||
|
||||
if (!EnchantChecks.boots(player, artifact)) return;
|
||||
if(artifact.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (!EnchantChecks.boots(player, artifact)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (artifact.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.getWorld().spawnParticle(artifact.getParticle(), player.getLocation().add(0, 0.1, 0), 1, 0, 0, 0, 0, artifact.getDustOptions(), true);
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
public abstract class SummoningEnchantment extends EcoEnchant {
|
||||
private final SummoningType summoningType;
|
||||
|
||||
protected SummoningEnchantment(String key, EnchantmentType type, SummoningType summoningType, Prerequisite... prerequisites) {
|
||||
protected SummoningEnchantment(@NotNull final String key,
|
||||
@NotNull final EnchantmentType type,
|
||||
@NotNull final SummoningType summoningType,
|
||||
@NotNull final Prerequisite... prerequisites) {
|
||||
super(key, type, prerequisites);
|
||||
|
||||
this.summoningType = summoningType;
|
||||
@ -37,36 +40,60 @@ public abstract class SummoningEnchantment extends EcoEnchant {
|
||||
public abstract EntityType getEntity();
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!summoningType.equals(SummoningType.MELEE)) return;
|
||||
|
||||
doSpawn(attacker, victim, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!summoningType.equals(SummoningType.RANGED)) return;
|
||||
|
||||
doSpawn(attacker, victim, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) {
|
||||
if(!summoningType.equals(SummoningType.TRIDENT)) return;
|
||||
|
||||
doSpawn(attacker, victim, level);
|
||||
}
|
||||
|
||||
private void doSpawn(LivingEntity attacker, LivingEntity victim, int level) {
|
||||
|
||||
if(summoningType.equals(SummoningType.MELEE) && attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!summoningType.equals(SummoningType.MELEE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
return;
|
||||
doSpawn(attacker, victim, level);
|
||||
}
|
||||
|
||||
if(!victim.getMetadata("eco-target").isEmpty()) return;
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!summoningType.equals(SummoningType.RANGED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
doSpawn(attacker, victim, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!summoningType.equals(SummoningType.TRIDENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
doSpawn(attacker, victim, level);
|
||||
}
|
||||
|
||||
private void doSpawn(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level) {
|
||||
|
||||
if (summoningType.equals(SummoningType.MELEE)
|
||||
&& attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!victim.getMetadata("eco-target").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = victim.getLocation().clone();
|
||||
World world = victim.getWorld();
|
||||
@ -75,12 +102,14 @@ public abstract class SummoningEnchantment extends EcoEnchant {
|
||||
int ticksToLive = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-to-live-per-level") * level;
|
||||
double health = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level") * level;
|
||||
|
||||
for(int i = 0; i < toSpawn; i++) {
|
||||
for (int i = 0; i < toSpawn; i++) {
|
||||
Location locToSpawn = location.clone().add(NumberUtils.randFloat(-3, 3), NumberUtils.randFloat(0, 3), NumberUtils.randFloat(-3, 3));
|
||||
Mob entity = (Mob) world.spawnEntity(locToSpawn, this.getEntity());
|
||||
|
||||
entity.setTarget(victim);
|
||||
if(health > entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) health = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||
if (health > entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
|
||||
health = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||
}
|
||||
entity.setHealth(health);
|
||||
entity.setMetadata("eco-target", new FixedMetadataValue(this.getPlugin(), victim));
|
||||
|
||||
@ -89,16 +118,20 @@ public abstract class SummoningEnchantment extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSwitchTarget(EntityTargetEvent event) {
|
||||
if(event.getEntity().getMetadata("eco-target").isEmpty()) return;
|
||||
public void onSwitchTarget(@NotNull final EntityTargetEvent event) {
|
||||
if (event.getEntity().getMetadata("eco-target").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity target = (LivingEntity) event.getEntity().getMetadata("eco-target").get(0).value();
|
||||
event.setTarget(target);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onDropItem(EntityDeathEvent event) {
|
||||
if(event.getEntity().getMetadata("eco-target").isEmpty()) return;
|
||||
public void onDropItem(@NotNull final EntityDeathEvent event) {
|
||||
if (event.getEntity().getMetadata("eco-target").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getDrops().clear();
|
||||
event.setDroppedExp(0);
|
||||
|
@ -47,7 +47,7 @@ public class StringUtils {
|
||||
return ChatColor.translateAlternateColorCodes('&', translateHexColorCodes(processedMessage));
|
||||
}
|
||||
|
||||
private static String translateHexColorCodes(String message) {
|
||||
private static String translateHexColorCodes(@NotNull final String message) {
|
||||
Pattern hexPattern = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
|
||||
Matcher matcher = hexPattern.matcher(message);
|
||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||
@ -91,15 +91,15 @@ public class StringUtils {
|
||||
/**
|
||||
* Remove a string of characters from the start of a string.
|
||||
*
|
||||
* @param s The string to remove the prefix from.
|
||||
* @param string The string to remove the prefix from.
|
||||
* @param prefix The substring to remove.
|
||||
* @return The string with the prefix removed.
|
||||
*/
|
||||
public String removePrefix(@NotNull final String s,
|
||||
public String removePrefix(@NotNull final String string,
|
||||
@NotNull final String prefix) {
|
||||
if (s.startsWith(prefix)) {
|
||||
return s.substring(prefix.length());
|
||||
if (string.startsWith(prefix)) {
|
||||
return string.substring(prefix.length());
|
||||
}
|
||||
return s;
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user