Added spell enchantments
This commit is contained in:
@@ -58,6 +58,7 @@ public final class EnchantDisplay {
|
||||
static String specialColor;
|
||||
static String artifactColor;
|
||||
static String descriptionColor;
|
||||
static String spellColor;
|
||||
|
||||
static int numbersThreshold;
|
||||
static boolean useNumerals;
|
||||
@@ -77,6 +78,7 @@ public final class EnchantDisplay {
|
||||
curseColor = StringUtils.translate(ConfigManager.getLang().getString("curse-color"));
|
||||
specialColor = StringUtils.translate(ConfigManager.getLang().getString("special-color"));
|
||||
artifactColor = StringUtils.translate(ConfigManager.getLang().getString("artifact-color"));
|
||||
spellColor = StringUtils.translate(ConfigManager.getLang().getString("spell-color"));
|
||||
normalColor = StringUtils.translate(ConfigManager.getLang().getString("not-curse-color"));
|
||||
|
||||
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
|
||||
|
||||
@@ -61,6 +61,9 @@ public class EnchantmentCache {
|
||||
case CURSE:
|
||||
color = EnchantDisplay.curseColor;
|
||||
break;
|
||||
case SPELL:
|
||||
color = EnchantDisplay.spellColor;
|
||||
break;
|
||||
default:
|
||||
color = EnchantDisplay.normalColor;
|
||||
break;
|
||||
|
||||
@@ -49,18 +49,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type) {
|
||||
this(key, type, EcoEnchantsPlugin.class, new Prerequisite[]{});
|
||||
}
|
||||
|
||||
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Prerequisite... prerequisites) {
|
||||
this(key, type, EcoEnchantsPlugin.class, prerequisites);
|
||||
}
|
||||
|
||||
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin) {
|
||||
this(key, type, plugin, new Prerequisite[]{});
|
||||
}
|
||||
|
||||
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) {
|
||||
super(NamespacedKey.minecraft(key));
|
||||
|
||||
@@ -360,7 +352,8 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
||||
NORMAL(false),
|
||||
CURSE(false),
|
||||
SPECIAL(true),
|
||||
ARTIFACT(true);
|
||||
ARTIFACT(true),
|
||||
SPELL(true);
|
||||
|
||||
static {
|
||||
update();
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.curse.MisfortuneCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.PermanenceCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.*;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.*;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Missile;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -247,6 +248,7 @@ public class EcoEnchants {
|
||||
public static final EcoEnchant DWELLER = new Dweller();
|
||||
public static final EcoEnchant STALWART = new Stalwart();
|
||||
public static final EcoEnchant PLASMIC = new Plasmic();
|
||||
public static final EcoEnchant MISSILE = new Missile();
|
||||
|
||||
/**
|
||||
* Get all registered {@link EcoEnchant}s
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.spell;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.WitherSkull;
|
||||
|
||||
public class Missile extends Spell {
|
||||
public Missile() {
|
||||
super("missile");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick(Player player, int level) {
|
||||
WitherSkull skull = player.launchProjectile(WitherSkull.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity")));
|
||||
skull.setCharged(true);
|
||||
skull.setIsIncendiary(false);
|
||||
skull.setYield((float) this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "power"));
|
||||
skull.setShooter(player);
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,6 @@ public abstract class Artifact extends EcoEnchant {
|
||||
private Particle particle;
|
||||
private Particle.DustOptions extra;
|
||||
|
||||
protected Artifact(String key) {
|
||||
this(key, new Prerequisite[]{});
|
||||
}
|
||||
|
||||
protected Artifact(String key, Prerequisite... prerequisites) {
|
||||
super(key, EnchantmentType.ARTIFACT, prerequisites);
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.willfp.ecoenchants.enchantments.itemtypes;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.SpellRunnable;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Wrapper for Spell enchantments
|
||||
*/
|
||||
public abstract class Spell extends EcoEnchant {
|
||||
private final HashMap<UUID, SpellRunnable> cooldownTracker = new HashMap<>();
|
||||
|
||||
protected Spell(String key, Prerequisite... prerequisites) {
|
||||
super(key, EnchantmentType.SPELL, prerequisites);
|
||||
}
|
||||
|
||||
public int getCooldownTime() {
|
||||
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "cooldown");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRightClickEventHandler(PlayerInteractEvent event) {
|
||||
if(!event.getAction().equals(Action.RIGHT_CLICK_AIR))
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(!EnchantChecks.mainhand(player, this))
|
||||
return;
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
||||
if(!cooldownTracker.containsKey(player.getUniqueId()))
|
||||
cooldownTracker.put(player.getUniqueId(), new SpellRunnable(player, this));
|
||||
|
||||
SpellRunnable runnable = cooldownTracker.get(player.getUniqueId());
|
||||
runnable.setTask(() -> {
|
||||
this.onRightClick(player, level);
|
||||
});
|
||||
|
||||
long msLeft = runnable.getEndTime() - System.currentTimeMillis();
|
||||
|
||||
long secondsLeft = (long) Math.ceil((double) msLeft / 1000);
|
||||
|
||||
if(msLeft > 0) {
|
||||
String message = ConfigManager.getLang().getMessage("on-cooldown").replaceAll("%seconds%", String.valueOf(secondsLeft)).replaceAll("%name%", EnchantmentCache.getEntry(this).getRawName());
|
||||
player.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
public abstract void onRightClick(Player player, int level);
|
||||
}
|
||||
@@ -102,8 +102,7 @@ public class EnchantingListeners implements Listener {
|
||||
|
||||
if(EcoEnchants.getFromEnchantment(enchant) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant);
|
||||
if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && EcoEnchant.EnchantmentType.SPECIAL.isSingular()) anyConflicts.set(true);
|
||||
if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && EcoEnchant.EnchantmentType.ARTIFACT.isSingular()) anyConflicts.set(true);
|
||||
if(enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) anyConflicts.set(true);
|
||||
}
|
||||
});
|
||||
if (anyConflicts.get()) continue;
|
||||
|
||||
@@ -74,8 +74,7 @@ public class LootPopulator extends BlockPopulator {
|
||||
if (enchant.conflictsWith(enchantment)) anyConflicts.set(true);
|
||||
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant);
|
||||
if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && EcoEnchant.EnchantmentType.SPECIAL.isSingular()) anyConflicts.set(true);
|
||||
if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && EcoEnchant.EnchantmentType.ARTIFACT.isSingular()) anyConflicts.set(true);
|
||||
if(enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) anyConflicts.set(true);
|
||||
});
|
||||
if (anyConflicts.get()) continue;
|
||||
|
||||
|
||||
@@ -134,8 +134,7 @@ public class VillagerListeners implements Listener {
|
||||
if (enchant.conflictsWith(enchantment)) anyConflicts.set(true);
|
||||
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant);
|
||||
if (enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && EcoEnchant.EnchantmentType.SPECIAL.isSingular()) anyConflicts.set(true);
|
||||
if (enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && EcoEnchant.EnchantmentType.ARTIFACT.isSingular()) anyConflicts.set(true);
|
||||
if(enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) anyConflicts.set(true);
|
||||
});
|
||||
if (anyConflicts.get()) continue;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Callback {
|
||||
void call();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.willfp.ecoenchants.enchantments.util;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpellRunnable {
|
||||
private final UUID player;
|
||||
private final Spell spell;
|
||||
private long endTime = 0;
|
||||
private Callback callback = () -> {};
|
||||
|
||||
public SpellRunnable(Player player, Spell spell) {
|
||||
this.player = player.getUniqueId();
|
||||
this.spell = spell;
|
||||
}
|
||||
|
||||
public Spell getSpell() {
|
||||
return spell;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
callback.call();
|
||||
updateEndTime();
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void updateEndTime() {
|
||||
endTime = System.currentTimeMillis() + (spell.getCooldownTime()*1000);
|
||||
}
|
||||
|
||||
public void setTask(Callback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
}
|
||||
@@ -221,6 +221,8 @@ public class Loader {
|
||||
Logger.info(StringUtils.translate(ConfigManager.getLang().getString("special-color")) + "- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
|
||||
} else if(ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)) {
|
||||
Logger.info(StringUtils.translate(ConfigManager.getLang().getString("artifact-color")) + "- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
|
||||
} else if(ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPELL)) {
|
||||
Logger.info(StringUtils.translate(ConfigManager.getLang().getString("spell-color")) + "- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
|
||||
} else {
|
||||
Logger.info("- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
|
||||
}
|
||||
|
||||
26
Plugin/src/main/resources/enchants/spell/missile.yml
Normal file
26
Plugin/src/main/resources/enchants/spell/missile.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# Missile EcoEnchant
|
||||
#
|
||||
|
||||
name: "Missile"
|
||||
description: Shoots a wither skull
|
||||
enabled: true
|
||||
|
||||
obtaining:
|
||||
table: true
|
||||
villager: true
|
||||
loot: true
|
||||
rarity: epic
|
||||
|
||||
general-config:
|
||||
targets:
|
||||
- sword
|
||||
- axe
|
||||
grindstoneable: true
|
||||
conflicts: []
|
||||
maximum-level: 3
|
||||
|
||||
config:
|
||||
cooldown: 20 # In seconds
|
||||
velocity: 3
|
||||
power: 5
|
||||
@@ -16,6 +16,7 @@ messages:
|
||||
&9Can be applied to: &r%target%
|
||||
&9Conflicts with: &r%conflicts%
|
||||
outdated: "You are running an outdated version of &aEcoEnchants! &fCurrently running &e%ver%&f, newest version &e%newver%&f. Download at &a&lhttps://www.spigotmc.org/resources/ecoenchants.79573/"
|
||||
on-cooldown: "&fThis spell is on cooldown! Wait &a%seconds% Seconds&f to use &a%name%&f again."
|
||||
|
||||
no-targets: "&cCannot be applied"
|
||||
no-conflicts: "&cNo conflicts"
|
||||
@@ -24,6 +25,7 @@ curse-color: "&c"
|
||||
not-curse-color: "&7"
|
||||
special-color: "&d"
|
||||
artifact-color: "&e"
|
||||
spell-color: "&9"
|
||||
|
||||
description-color: "&8"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user