mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-26 15:45:12 +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;
|
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||||
|
|
||||||
|
import com.sun.javaws.Main;
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||||
@ -13,6 +14,8 @@ import org.bukkit.entity.LivingEntity;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -26,14 +29,12 @@ public class Marking extends EcoEnchant {
|
|||||||
|
|
||||||
// START OF LISTENERS
|
// START OF LISTENERS
|
||||||
|
|
||||||
Set<LivingEntity> weakened = new HashSet<>();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onHit(EntityDamageByEntityEvent event) {
|
public void onHit(EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getDamager() instanceof Arrow))
|
if (!(event.getDamager() instanceof Arrow))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!(((Arrow) event.getDamager()).getShooter() instanceof Player))
|
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(event.getEntity() instanceof LivingEntity))
|
if (!(event.getEntity() instanceof LivingEntity))
|
||||||
@ -43,13 +44,7 @@ public class Marking extends EcoEnchant {
|
|||||||
|
|
||||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||||
|
|
||||||
if(weakened.contains(victim)) {
|
if (!AntigriefManager.canInjure(player, victim)) return;
|
||||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak");
|
|
||||||
|
|
||||||
event.setDamage(event.getDamage() * multiplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!AntigriefManager.canInjure(player, victim)) return;
|
|
||||||
|
|
||||||
if (!HasEnchant.playerHeld(player, this)) 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 ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||||
int ticks = ticksPerLevel * level;
|
int ticks = ticksPerLevel * level;
|
||||||
|
|
||||||
weakened.add(victim);
|
victim.setMetadata("marked", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
||||||
weakened.remove(victim);
|
victim.removeMetadata("marked", EcoEnchantsPlugin.getInstance());
|
||||||
}, ticks);
|
}, 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;
|
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||||
|
|
||||||
|
import com.sun.javaws.Main;
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
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.nms.Target;
|
||||||
import com.willfp.ecoenchants.util.HasEnchant;
|
import com.willfp.ecoenchants.util.HasEnchant;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Weakening extends EcoEnchant {
|
public class Weakening extends EcoEnchant {
|
||||||
public Weakening() {
|
public Weakening() {
|
||||||
super(
|
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
|
// START OF LISTENERS
|
||||||
|
|
||||||
Set<LivingEntity> weakened = new HashSet<>();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void weakeningHit(EntityDamageByEntityEvent event) {
|
public void onHit(EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getDamager() instanceof Player))
|
if (!(event.getDamager() instanceof Player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -38,13 +41,7 @@ public class Weakening extends EcoEnchant {
|
|||||||
|
|
||||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||||
|
|
||||||
if(weakened.contains(victim)) {
|
if (!AntigriefManager.canInjure(player, victim)) return;
|
||||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak");
|
|
||||||
|
|
||||||
event.setDamage(event.getDamage() * multiplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!AntigriefManager.canInjure(player, victim)) return;
|
|
||||||
|
|
||||||
if (!HasEnchant.playerHeld(player, this)) 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 ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||||
int ticks = ticksPerLevel * level;
|
int ticks = ticksPerLevel * level;
|
||||||
|
|
||||||
weakened.add(victim);
|
victim.setMetadata("weak", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
||||||
weakened.remove(victim);
|
victim.removeMetadata("weak", EcoEnchantsPlugin.getInstance());
|
||||||
}, ticks);
|
}, 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