From aae45e98d54290504dfd9ab21102e6223a725506 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 29 Aug 2020 14:07:09 +0100 Subject: [PATCH] Added Marking --- .../ecoenchants/enchantments/EcoEnchants.java | 1 + .../ecoenchants/normal/Marking.java | 67 +++++++++++++++++++ .../resources/enchants/normal/marking.yml | 24 +++++++ Plugin/src/main/resources/plugin.yml | 4 ++ 4 files changed, 96 insertions(+) create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java create mode 100644 Plugin/src/main/resources/enchants/normal/marking.yml diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index 8b045b23..c90092fb 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -191,6 +191,7 @@ public class EcoEnchants { public static final EcoEnchant FORCE = new Force(); public static final EcoEnchant END_INFUSION = new EndInfusion(); public static final EcoEnchant DIURNAL = new Diurnal(); + public static final EcoEnchant MARKING = new Marking(); /** * Get all registered {@link EcoEnchant}s diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java new file mode 100644 index 00000000..4e4821fc --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java @@ -0,0 +1,67 @@ +package com.willfp.ecoenchants.enchantments.ecoenchants.normal; + +import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.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 java.util.HashSet; +import java.util.Set; + +public class Marking extends EcoEnchant { + public Marking() { + super( + new EcoEnchantBuilder("marking", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.CROSSBOW, Target.Applicable.BOW}, 4.0) + ); + } + + // START OF LISTENERS + + Set weakened = new HashSet<>(); + + @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; + + Player player = (Player) ((Arrow) event.getDamager()).getShooter(); + + 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 (!HasEnchant.playerHeld(player, this)) return; + + int level = HasEnchant.getPlayerLevel(player, this); + + int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); + int ticks = ticksPerLevel * level; + + weakened.add(victim); + + Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> { + weakened.remove(victim); + }, ticks); + } +} diff --git a/Plugin/src/main/resources/enchants/normal/marking.yml b/Plugin/src/main/resources/enchants/normal/marking.yml new file mode 100644 index 00000000..ea6d7e72 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/marking.yml @@ -0,0 +1,24 @@ +# +# Marking EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Marking" + +description: Increases subsequent damage dealt to opponent. + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 4 + +config: + ticks-per-level: 15 # Ticks to weaken player for per level + multiplier-while-weak: 1.3 # Times more damage to deal while weakened diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 09ada895..8f6c4160 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -210,6 +210,7 @@ permissions: ecoenchants.fromtable.force: true ecoenchants.fromtable.endinfusion: true ecoenchants.fromtable.diurnal: true + ecoenchants.fromtable.marking: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -712,4 +713,7 @@ permissions: default: true ecoenchants.fromtable.diurnal: description: Allows getting diurnal from an enchanting table + default: true + ecoenchants.fromtable.marking: + description: Allows getting marking from an enchanting table default: true \ No newline at end of file