mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Added summoning extension
This commit is contained in:
parent
ca5a86f1e6
commit
760afac38c
14
Extensions/Summoning/build.gradle
Normal file
14
Extensions/Summoning/build.gradle
Normal file
@ -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/")
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.willfp.ecoenchants.summoning;
|
||||
|
||||
public enum SummoningType {
|
||||
MELEE,
|
||||
RANGED,
|
||||
TRIDENT
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
3
Extensions/Summoning/src/main/resources/extension.yml
Normal file
3
Extensions/Summoning/src/main/resources/extension.yml
Normal file
@ -0,0 +1,3 @@
|
||||
name: Summoning
|
||||
main: com.willfp.ecoenchants.summoning.SummoningMain
|
||||
version: 1.0.0
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user