Modified Weakening and Marking

This commit is contained in:
Auxilor 2020-08-29 14:38:57 +01:00
parent 5dffe3be77
commit 42b493f96d
2 changed files with 43 additions and 25 deletions

View File

@ -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"));
}
}

View File

@ -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"));
}
}