Added firewand extension
This commit is contained in:
14
Extensions/Firewand/build.gradle
Normal file
14
Extensions/Firewand/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 = findProperty("Name") + " v" + findProperty("version") + ".jar"
|
||||
}
|
||||
|
||||
description = 'FireWand'
|
||||
|
||||
tasks.withType(Jar) {
|
||||
destinationDirectory = file("$rootDir/bin/")
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.willfp.ecoenchants.firewand;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.WitherSkull;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
public class Firewand extends Spell {
|
||||
public Firewand() {
|
||||
super("firewand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
Fireball fireball = player.launchProjectile(Fireball.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity")));
|
||||
fireball.setIsIncendiary(false);
|
||||
fireball.setMetadata("eco-damage", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level));
|
||||
if(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "no-explode")) {
|
||||
fireball.setMetadata("nobreak", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||
}
|
||||
fireball.setShooter(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onFireballDamage(EntityDamageByEntityEvent event) {
|
||||
if(!(event.getDamager() instanceof Fireball)) return;
|
||||
if(event.getDamager().getMetadata("eco-damage").isEmpty()) return;
|
||||
|
||||
double multiplier = event.getDamager().getMetadata("eco-damage").get(0).asDouble();
|
||||
|
||||
event.setDamage(multiplier);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFireballExplode(EntityExplodeEvent event) {
|
||||
if(!(event.getEntity() instanceof Fireball)) return;
|
||||
if(event.getEntity().getMetadata("nobreak").isEmpty()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.willfp.ecoenchants.firewand;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.extensions.Extension;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class FirewandMain extends Extension {
|
||||
public static final EcoEnchant FIREWAND = new Firewand();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(FIREWAND, EcoEnchantsPlugin.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# Firewand EcoEnchant
|
||||
#
|
||||
|
||||
name: "Firewand"
|
||||
description: Shoots a fireball
|
||||
enabled: true
|
||||
|
||||
obtaining:
|
||||
table: true
|
||||
villager: true
|
||||
loot: true
|
||||
rarity: legendary
|
||||
|
||||
general-config:
|
||||
targets:
|
||||
- rod
|
||||
grindstoneable: true
|
||||
conflicts: []
|
||||
maximum-level: 3
|
||||
|
||||
config:
|
||||
activation-sound: ENTITY_WITHER_SHOOT
|
||||
cooldown: 60 # In seconds
|
||||
velocity: 3
|
||||
damage-per-level: 8
|
||||
no-explode: false # Don't explode
|
||||
2
Extensions/Firewand/src/main/resources/extension.yml
Normal file
2
Extensions/Firewand/src/main/resources/extension.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
name: Firewand
|
||||
main: com.willfp.ecoenchants.firewand.FirewandMain
|
||||
@@ -12,7 +12,7 @@ public class Charge extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
Vector velocity = player.getEyeLocation().getDirection().clone();
|
||||
velocity.normalize();
|
||||
velocity.multiply(level * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity-per-level"));
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Dynamite extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if(!event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Missile extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
WitherSkull skull = player.launchProjectile(WitherSkull.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity")));
|
||||
skull.setCharged(true);
|
||||
skull.setIsIncendiary(false);
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Quake extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
int radius = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "radius-per-level") * level;
|
||||
int damage = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class Vitalize extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.SpellRunnable;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,8 +17,10 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -27,6 +30,10 @@ import java.util.UUID;
|
||||
public abstract class Spell extends EcoEnchant {
|
||||
private final HashMap<UUID, SpellRunnable> cooldownTracker = new HashMap<>();
|
||||
private final Set<UUID> runningSpell = new HashSet<>();
|
||||
private static final List<Material> leftClickItems = Arrays.asList(
|
||||
Material.FISHING_ROD,
|
||||
Material.BOW
|
||||
);
|
||||
|
||||
protected Spell(String key, Prerequisite... prerequisites) {
|
||||
super(key, EnchantmentType.SPELL, prerequisites);
|
||||
@@ -41,12 +48,17 @@ public abstract class Spell extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRightClickEventHandler(PlayerInteractEvent event) {
|
||||
if(!(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)))
|
||||
return;
|
||||
|
||||
public void onUseEventHandler(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(!leftClickItems.contains(player.getInventory().getItemInMainHand().getType())) {
|
||||
if(!(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)))
|
||||
return;
|
||||
} else {
|
||||
if(!(event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)))
|
||||
return;
|
||||
}
|
||||
|
||||
if(runningSpell.contains(player.getUniqueId())) return;
|
||||
|
||||
runningSpell.add(player.getUniqueId());
|
||||
@@ -62,7 +74,7 @@ public abstract class Spell extends EcoEnchant {
|
||||
|
||||
SpellRunnable runnable = cooldownTracker.get(player.getUniqueId());
|
||||
runnable.setTask(() -> {
|
||||
this.onRightClick(player, level, event);
|
||||
this.onUse(player, level, event);
|
||||
});
|
||||
|
||||
int cooldown = getCooldown(this, player);
|
||||
@@ -80,7 +92,7 @@ public abstract class Spell extends EcoEnchant {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
public abstract void onRightClick(Player player, int level, PlayerInteractEvent event);
|
||||
public abstract void onUse(Player player, int level, PlayerInteractEvent event);
|
||||
|
||||
public static int getCooldown(Spell spell, Player player) {
|
||||
if(!spell.cooldownTracker.containsKey(player.getUniqueId()))
|
||||
|
||||
@@ -5,10 +5,12 @@ include('API')
|
||||
include('v1_16_R1')
|
||||
include('v1_16_R2')
|
||||
include('v1_16_R3')
|
||||
include('Firewand')
|
||||
|
||||
project(":v1_15_R1").projectDir = file('NMS/v1_15_R1')
|
||||
project(":plugin").projectDir = file('Plugin')
|
||||
project(":API").projectDir = file('NMS/API')
|
||||
project(":v1_16_R1").projectDir = file('NMS/v1_16_R1')
|
||||
project(":v1_16_R2").projectDir = file('NMS/v1_16_R2')
|
||||
project(":v1_16_R3").projectDir = file('NMS/v1_16_R3')
|
||||
project(":v1_16_R3").projectDir = file('NMS/v1_16_R3')
|
||||
project(":Firewand").projectDir = file('Extensions/Firewand')
|
||||
|
||||
Reference in New Issue
Block a user