From 9540d8fbb17339dbcd14b73acdc7980a9f2e2e2c Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 4 Aug 2021 17:14:04 +0100 Subject: [PATCH] Created citizen extension --- eco-extensions/citizen/build.gradle | 7 +++ .../willfp/ecoenchants/citizen/Citizen.java | 56 +++++++++++++++++++ .../ecoenchants/citizen/CitizenMain.java | 24 ++++++++ .../resources/enchants/normal/citizen.yml | 28 ++++++++++ .../citizen/src/main/resources/extension.yml | 4 ++ settings.gradle | 1 + 6 files changed, 120 insertions(+) create mode 100644 eco-extensions/citizen/build.gradle create mode 100644 eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/Citizen.java create mode 100644 eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/CitizenMain.java create mode 100644 eco-extensions/citizen/src/main/resources/enchants/normal/citizen.yml create mode 100644 eco-extensions/citizen/src/main/resources/extension.yml diff --git a/eco-extensions/citizen/build.gradle b/eco-extensions/citizen/build.gradle new file mode 100644 index 00000000..e619e594 --- /dev/null +++ b/eco-extensions/citizen/build.gradle @@ -0,0 +1,7 @@ +group 'com.willfp' +version '1.0.0' +description = 'Citizen Extension' + +shadowJar { + archiveFileName = project.getDescription() + " v" + project.version + ".jar" +} \ No newline at end of file diff --git a/eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/Citizen.java b/eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/Citizen.java new file mode 100644 index 00000000..da53f017 --- /dev/null +++ b/eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/Citizen.java @@ -0,0 +1,56 @@ +package com.willfp.ecoenchants.citizen; + +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Trident; +import org.bukkit.entity.Villager; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.jetbrains.annotations.NotNull; + +public class Citizen extends EcoEnchant { + public Citizen() { + super( + "citizen", EnchantmentType.NORMAL + ); + } + + @Override + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity uncastVictim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!(uncastVictim instanceof Villager)) { + return; + } + + event.setCancelled(true); + } + + @Override + 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 Villager)) { + return; + } + + event.setCancelled(true); + } + + @Override + public void onTridentDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Trident trident, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!(victim instanceof Villager)) { + return; + } + + event.setCancelled(true); + } +} diff --git a/eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/CitizenMain.java b/eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/CitizenMain.java new file mode 100644 index 00000000..adb508ef --- /dev/null +++ b/eco-extensions/citizen/src/main/java/com/willfp/ecoenchants/citizen/CitizenMain.java @@ -0,0 +1,24 @@ +package com.willfp.ecoenchants.citizen; + +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.extensions.Extension; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; + +public class CitizenMain extends Extension { + public static final EcoEnchant CITIZEN = new Citizen(); + + public CitizenMain(@NotNull final EcoPlugin plugin) { + super(plugin); + } + + @Override + public void onEnable() { + // Handled by super + } + + @Override + public void onDisable() { + // Handled by super + } +} diff --git a/eco-extensions/citizen/src/main/resources/enchants/normal/citizen.yml b/eco-extensions/citizen/src/main/resources/enchants/normal/citizen.yml new file mode 100644 index 00000000..3badc52c --- /dev/null +++ b/eco-extensions/citizen/src/main/resources/enchants/normal/citizen.yml @@ -0,0 +1,28 @@ +# +# Citizen EcoEnchant +# + +name: "Citizen" +description: Prevent you from injuring villagers. +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: uncommon + +general-config: + flags: [] + targets: + - sword + - axe + - bow + - trident + grindstoneable: true + disabled-in-worlds: [ ] + conflicts: [] + maximum-level: 1 + +config: + # No config is available for this enchantment \ No newline at end of file diff --git a/eco-extensions/citizen/src/main/resources/extension.yml b/eco-extensions/citizen/src/main/resources/extension.yml new file mode 100644 index 00000000..f5002d5f --- /dev/null +++ b/eco-extensions/citizen/src/main/resources/extension.yml @@ -0,0 +1,4 @@ +name: Citizen +main: com.willfp.ecoenchants.citizen.CitizenMain +version: ${projectVersion} +author: Auxilor \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 2ea34deb..fe7b010c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,6 +12,7 @@ include ':eco-core:core-plugin' include ':eco-extensions' include ':eco-extensions:alchemy' include ':eco-extensions:biomes' +include ':eco-extensions:citizen' include ':eco-extensions:effects' include ':eco-extensions:endershot' include ':eco-extensions:firewand'