mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Modified Weakening and Marking
This commit is contained in:
parent
5dffe3be77
commit
42b493f96d
@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.sun.javaws.Main;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
@ -13,6 +14,8 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -26,14 +29,12 @@ public class Marking extends EcoEnchant {
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
Set<LivingEntity> weakened = new HashSet<>();
|
||||
|
||||
@EventHandler
|
||||
public void onHit(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Arrow))
|
||||
return;
|
||||
|
||||
if(!(((Arrow) event.getDamager()).getShooter() instanceof Player))
|
||||
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player))
|
||||
return;
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
@ -43,13 +44,7 @@ public class Marking extends EcoEnchant {
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if(weakened.contains(victim)) {
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak");
|
||||
|
||||
event.setDamage(event.getDamage() * multiplier);
|
||||
}
|
||||
|
||||
if(!AntigriefManager.canInjure(player, victim)) return;
|
||||
if (!AntigriefManager.canInjure(player, victim)) return;
|
||||
|
||||
if (!HasEnchant.playerHeld(player, this)) return;
|
||||
|
||||
@ -58,10 +53,23 @@ public class Marking extends EcoEnchant {
|
||||
int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||
int ticks = ticksPerLevel * level;
|
||||
|
||||
weakened.add(victim);
|
||||
victim.setMetadata("marked", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
||||
weakened.remove(victim);
|
||||
victim.removeMetadata("marked", EcoEnchantsPlugin.getInstance());
|
||||
}, ticks);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHitWhileMarked(EntityDamageEvent event) {
|
||||
if(!(event.getEntity() instanceof LivingEntity))
|
||||
return;
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if(!victim.hasMetadata("marked"))
|
||||
return;
|
||||
|
||||
event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak"));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.sun.javaws.Main;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
@ -8,26 +9,28 @@ import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.nms.Target;
|
||||
import com.willfp.ecoenchants.util.HasEnchant;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Weakening extends EcoEnchant {
|
||||
public Weakening() {
|
||||
super(
|
||||
new EcoEnchantBuilder("weakening", EnchantmentType.NORMAL, Target.Applicable.SWORD, 4.0)
|
||||
new EcoEnchantBuilder("weakening", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
Set<LivingEntity> weakened = new HashSet<>();
|
||||
|
||||
@EventHandler
|
||||
public void weakeningHit(EntityDamageByEntityEvent event) {
|
||||
public void onHit(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player))
|
||||
return;
|
||||
|
||||
@ -38,13 +41,7 @@ public class Weakening extends EcoEnchant {
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if(weakened.contains(victim)) {
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak");
|
||||
|
||||
event.setDamage(event.getDamage() * multiplier);
|
||||
}
|
||||
|
||||
if(!AntigriefManager.canInjure(player, victim)) return;
|
||||
if (!AntigriefManager.canInjure(player, victim)) return;
|
||||
|
||||
if (!HasEnchant.playerHeld(player, this)) return;
|
||||
|
||||
@ -53,10 +50,23 @@ public class Weakening extends EcoEnchant {
|
||||
int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||
int ticks = ticksPerLevel * level;
|
||||
|
||||
weakened.add(victim);
|
||||
victim.setMetadata("weak", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
||||
weakened.remove(victim);
|
||||
victim.removeMetadata("weak", EcoEnchantsPlugin.getInstance());
|
||||
}, ticks);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
if(!(event.getEntity() instanceof LivingEntity))
|
||||
return;
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if(!victim.hasMetadata("weak"))
|
||||
return;
|
||||
|
||||
event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user