diff --git a/Extensions/Summoning/build.gradle b/Extensions/Summoning/build.gradle new file mode 100644 index 00000000..62e6f7e6 --- /dev/null +++ b/Extensions/Summoning/build.gradle @@ -0,0 +1,14 @@ +dependencies { + compileOnly 'org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT' + compileOnly project(':plugin') +} + +jar{ + archiveFileName = project.name + " Extension" + ".jar" +} + +description = 'Summoning' + +tasks.withType(Jar) { + destinationDirectory = file("$rootDir/bin/") +} \ No newline at end of file diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java new file mode 100644 index 00000000..47cfc93f --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java @@ -0,0 +1,111 @@ +package com.willfp.ecoenchants.summoning; + +import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.nms.Cooldown; +import com.willfp.ecoenchants.util.NumberUtils; +import com.willfp.ecoenchants.util.optional.Prerequisite; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Mob; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.entity.Trident; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityDropItemEvent; +import org.bukkit.event.entity.EntityTameEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.metadata.FixedMetadataValue; + +public abstract class SummoningEnchantment extends EcoEnchant { + private final SummoningType summoningType; + + protected SummoningEnchantment(String key, EnchantmentType type, SummoningType summoningType, Prerequisite... prerequisites) { + super(key, type, SummoningMain.class, prerequisites); + + this.summoningType = summoningType; + } + + public abstract EntityType getEntity(); + + @Override + public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) { + if(!summoningType.equals(SummoningType.MELEE)) return; + + doSpawn(attacker, victim, level); + } + + @Override + public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { + if(!summoningType.equals(SummoningType.RANGED)) return; + + doSpawn(attacker, victim, level); + } + + @Override + public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { + if(!summoningType.equals(SummoningType.TRIDENT)) return; + + doSpawn(attacker, victim, level); + } + + private void doSpawn(LivingEntity attacker, LivingEntity victim, int level) { + + if(summoningType.equals(SummoningType.MELEE)) { + if (attacker instanceof Player) { + if (Cooldown.getCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) + return; + } + } + + if(!EnchantmentUtils.passedChance(this, level)) + return; + + if(!victim.getMetadata("eco-target").isEmpty()) return; + + Location location = victim.getLocation().clone(); + World world = victim.getWorld(); + + int toSpawn = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "mobs-per-level") * level; + int ticksToLive = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-to-live-per-level") * level; + double health = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level") * level; + + for(int i = 0; i < toSpawn; i++) { + Location locToSpawn = location.clone().add(NumberUtils.randFloat(-3, 3), NumberUtils.randFloat(0, 3), NumberUtils.randFloat(-3, 3)); + Mob entity = (Mob) world.spawnEntity(locToSpawn, this.getEntity()); + + entity.setTarget(victim); + if(health > entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) health = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + entity.setHealth(health); + entity.setMetadata("eco-target", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), victim)); + + Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), entity::remove, ticksToLive); + } + } + + @EventHandler + public void onSwitchTarget(EntityTargetEvent event) { + if(event.getEntity().getMetadata("eco-target").isEmpty()) return; + + LivingEntity target = (LivingEntity) event.getEntity().getMetadata("eco-target").get(0).value(); + event.setTarget(target); + } + + @EventHandler(priority = EventPriority.LOW) + public void onDropItem(EntityDeathEvent event) { + if(event.getEntity().getMetadata("eco-target").isEmpty()) return; + + event.getDrops().clear(); + } +} diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningMain.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningMain.java new file mode 100644 index 00000000..aa713edc --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningMain.java @@ -0,0 +1,33 @@ +package com.willfp.ecoenchants.summoning; + +import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.extensions.Extension; +import com.willfp.ecoenchants.summoning.enchants.Crawler; +import com.willfp.ecoenchants.summoning.enchants.Firestorm; +import com.willfp.ecoenchants.summoning.enchants.Ghoul; +import com.willfp.ecoenchants.summoning.enchants.Metallic; +import com.willfp.ecoenchants.summoning.enchants.Mortality; +import org.bukkit.Bukkit; + +public class SummoningMain extends Extension { + public static final EcoEnchant METALLIC = new Metallic(); + public static final EcoEnchant FIRESTORM = new Firestorm(); + public static final EcoEnchant MORTALITY = new Mortality(); + public static final EcoEnchant GHOUL = new Ghoul(); + public static final EcoEnchant CRAWLER = new Crawler(); + + @Override + public void onEnable() { + Bukkit.getPluginManager().registerEvents(FIRESTORM, EcoEnchantsPlugin.getInstance()); + Bukkit.getPluginManager().registerEvents(METALLIC, EcoEnchantsPlugin.getInstance()); + Bukkit.getPluginManager().registerEvents(MORTALITY, EcoEnchantsPlugin.getInstance()); + Bukkit.getPluginManager().registerEvents(GHOUL, EcoEnchantsPlugin.getInstance()); + Bukkit.getPluginManager().registerEvents(CRAWLER, EcoEnchantsPlugin.getInstance()); + } + + @Override + public void onDisable() { + + } +} diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningType.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningType.java new file mode 100644 index 00000000..20f2ea2d --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningType.java @@ -0,0 +1,7 @@ +package com.willfp.ecoenchants.summoning; + +public enum SummoningType { + MELEE, + RANGED, + TRIDENT +} diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Crawler.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Crawler.java new file mode 100644 index 00000000..2d1ebdad --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Crawler.java @@ -0,0 +1,16 @@ +package com.willfp.ecoenchants.summoning.enchants; + +import com.willfp.ecoenchants.summoning.SummoningEnchantment; +import com.willfp.ecoenchants.summoning.SummoningType; +import org.bukkit.entity.EntityType; + +public class Crawler extends SummoningEnchantment { + public Crawler() { + super("crawler", EnchantmentType.NORMAL, SummoningType.TRIDENT); + } + + @Override + public EntityType getEntity() { + return EntityType.CAVE_SPIDER; + } +} diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Firestorm.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Firestorm.java new file mode 100644 index 00000000..7ec9214e --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Firestorm.java @@ -0,0 +1,16 @@ +package com.willfp.ecoenchants.summoning.enchants; + +import com.willfp.ecoenchants.summoning.SummoningEnchantment; +import com.willfp.ecoenchants.summoning.SummoningType; +import org.bukkit.entity.EntityType; + +public class Firestorm extends SummoningEnchantment { + public Firestorm() { + super("firestorm", EnchantmentType.NORMAL, SummoningType.MELEE); + } + + @Override + public EntityType getEntity() { + return EntityType.BLAZE; + } +} diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Ghoul.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Ghoul.java new file mode 100644 index 00000000..089762c4 --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Ghoul.java @@ -0,0 +1,16 @@ +package com.willfp.ecoenchants.summoning.enchants; + +import com.willfp.ecoenchants.summoning.SummoningEnchantment; +import com.willfp.ecoenchants.summoning.SummoningType; +import org.bukkit.entity.EntityType; + +public class Ghoul extends SummoningEnchantment { + public Ghoul() { + super("ghoul", EnchantmentType.NORMAL, SummoningType.RANGED); + } + + @Override + public EntityType getEntity() { + return EntityType.ZOMBIE; + } +} diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Metallic.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Metallic.java new file mode 100644 index 00000000..87804e3b --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Metallic.java @@ -0,0 +1,16 @@ +package com.willfp.ecoenchants.summoning.enchants; + +import com.willfp.ecoenchants.summoning.SummoningEnchantment; +import com.willfp.ecoenchants.summoning.SummoningType; +import org.bukkit.entity.EntityType; + +public class Metallic extends SummoningEnchantment { + public Metallic() { + super("metallic", EnchantmentType.SPECIAL, SummoningType.MELEE); + } + + @Override + public EntityType getEntity() { + return EntityType.IRON_GOLEM; + } +} diff --git a/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Mortality.java b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Mortality.java new file mode 100644 index 00000000..e7351658 --- /dev/null +++ b/Extensions/Summoning/src/main/java/com/willfp/ecoenchants/summoning/enchants/Mortality.java @@ -0,0 +1,16 @@ +package com.willfp.ecoenchants.summoning.enchants; + +import com.willfp.ecoenchants.summoning.SummoningEnchantment; +import com.willfp.ecoenchants.summoning.SummoningType; +import org.bukkit.entity.EntityType; + +public class Mortality extends SummoningEnchantment { + public Mortality() { + super("mortality", EnchantmentType.NORMAL, SummoningType.RANGED); + } + + @Override + public EntityType getEntity() { + return EntityType.WITHER_SKELETON; + } +} diff --git a/Extensions/Summoning/src/main/resources/enchants/normal/crawler.yml b/Extensions/Summoning/src/main/resources/enchants/normal/crawler.yml new file mode 100644 index 00000000..f39ff8a3 --- /dev/null +++ b/Extensions/Summoning/src/main/resources/enchants/normal/crawler.yml @@ -0,0 +1,26 @@ +# +# Crawler EcoEnchant +# + +name: "Crawler" +description: Spawns cave spiders to attack your target. +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + targets: + - trident + grindstoneable: true + conflicts: [] + maximum-level: 3 + +config: + mobs-per-level: 2 # Amount of mobs to spawn per level + ticks-to-live-per-level: 30 # Ticks for mob to live per level + health-per-level: 6 # Health for mobs to have per level + chance-per-level: 5 # Chance to spawn mobs per level \ No newline at end of file diff --git a/Extensions/Summoning/src/main/resources/enchants/normal/firestorm.yml b/Extensions/Summoning/src/main/resources/enchants/normal/firestorm.yml new file mode 100644 index 00000000..d83dd39e --- /dev/null +++ b/Extensions/Summoning/src/main/resources/enchants/normal/firestorm.yml @@ -0,0 +1,27 @@ +# +# Firestorm EcoEnchant +# + +name: "Firestorm" +description: Spawns blazes to attack your target. +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + targets: + - sword + grindstoneable: true + conflicts: [] + maximum-level: 3 + +config: + mobs-per-level: 2 # Amount of mobs to spawn per level + ticks-to-live-per-level: 50 # Ticks for mob to live per level + health-per-level: 4 # Health for mobs to have per level + chance-per-level: 5 # Chance to spawn mobs per level + allow-not-fully-charged: false # don't require sword attack to be at full charge \ No newline at end of file diff --git a/Extensions/Summoning/src/main/resources/enchants/normal/ghoul.yml b/Extensions/Summoning/src/main/resources/enchants/normal/ghoul.yml new file mode 100644 index 00000000..d596ae91 --- /dev/null +++ b/Extensions/Summoning/src/main/resources/enchants/normal/ghoul.yml @@ -0,0 +1,27 @@ +# +# Ghoul EcoEnchant +# + +name: "Ghoul" +description: Spawns zombies to attack your target. +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + targets: + - bow + - crossbow + grindstoneable: true + conflicts: [] + maximum-level: 4 + +config: + mobs-per-level: 1 # Amount of mobs to spawn per level + ticks-to-live-per-level: 30 # Ticks for mob to live per level + health-per-level: 4 # Health for mobs to have per level + chance-per-level: 5 # Chance to spawn mobs per level \ No newline at end of file diff --git a/Extensions/Summoning/src/main/resources/enchants/normal/mortality.yml b/Extensions/Summoning/src/main/resources/enchants/normal/mortality.yml new file mode 100644 index 00000000..79d98cd0 --- /dev/null +++ b/Extensions/Summoning/src/main/resources/enchants/normal/mortality.yml @@ -0,0 +1,27 @@ +# +# Mortality EcoEnchant +# + +name: "Mortality" +description: Spawns wither skeletons to attack your target. +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + targets: + - bow + - crossbow + grindstoneable: true + conflicts: [] + maximum-level: 4 + +config: + mobs-per-level: 1 # Amount of mobs to spawn per level + ticks-to-live-per-level: 30 # Ticks for mob to live per level + health-per-level: 6 # Health for mobs to have per level + chance-per-level: 5 # Chance to spawn mobs per level \ No newline at end of file diff --git a/Extensions/Summoning/src/main/resources/enchants/special/metallic.yml b/Extensions/Summoning/src/main/resources/enchants/special/metallic.yml new file mode 100644 index 00000000..3d7180f6 --- /dev/null +++ b/Extensions/Summoning/src/main/resources/enchants/special/metallic.yml @@ -0,0 +1,27 @@ +# +# Metallic EcoEnchant +# + +name: "Metallic" +description: Spawns iron golems to attack your target. +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: veryspecial + +general-config: + targets: + - sword + grindstoneable: true + conflicts: [] + maximum-level: 2 + +config: + mobs-per-level: 1 # Amount of mobs to spawn per level + ticks-to-live-per-level: 20 # Ticks for mob to live per level + health-per-level: 4 # Health for mobs to have per level + chance-per-level: 5 # Chance to spawn mobs per level + allow-not-fully-charged: false # don't require sword attack to be at full charge \ No newline at end of file diff --git a/Extensions/Summoning/src/main/resources/extension.yml b/Extensions/Summoning/src/main/resources/extension.yml new file mode 100644 index 00000000..41119aca --- /dev/null +++ b/Extensions/Summoning/src/main/resources/extension.yml @@ -0,0 +1,3 @@ +name: Summoning +main: com.willfp.ecoenchants.summoning.SummoningMain +version: 1.0.0 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index c7e865df..f0418023 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,3 +23,5 @@ project(":Precision").projectDir = file('Extensions/Precision') include('Effects') findProject(':Effects').projectDir = file('Extensions/Effects') +include('Summoning') +findProject(':Summoning').projectDir = file('Extensions/Summoning')