Arrow Potion Effects

Effects can now be put onto Bows and will be applied by any arrow shot
This commit is contained in:
ASangarin 2020-10-16 20:48:02 +02:00
parent 6c2cca379e
commit 37689fadf8
10 changed files with 197 additions and 7 deletions

View File

@ -61,6 +61,14 @@ public class ItemSet {
config.getInt("bonuses." + j + "." + key) - 1, true, false));
continue;
}
if (key.startsWith("arrow-effect-")) {
PotionEffectType potionEffectType = PotionEffectType.getByName(format.substring("arrow-effect-".length()));
Validate.notNull(potionEffectType, "Could not load potion effect type from '" + format + "'");
bonuses.addPotionEffect(new PotionEffect(potionEffectType, MMOUtils.getEffectDuration(potionEffectType),
config.getInt("bonuses." + j + "." + key) - 1, true, false));
continue;
}
// particle effect
if (key.startsWith("particle-")) {
@ -163,7 +171,7 @@ public class ItemSet {
for (PotionEffect effect : bonuses.getPotionEffects())
if (!permEffects.containsKey(effect.getType()) || permEffects.get(effect.getType()).getAmplifier() < effect.getAmplifier())
permEffects.put(effect.getType(), effect);
bonuses.getAbilities().forEach(ability -> abilities.add(ability));
}
}

View File

@ -1,6 +1,15 @@
package net.Indyuce.mmoitems.api;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffectType;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
import net.Indyuce.mmoitems.stat.data.PotionEffectData;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
public class ProjectileData {
@ -29,4 +38,15 @@ public class ProjectileData {
public boolean isCustomWeapon() {
return customWeapon;
}
public void applyEffects(LivingEntity target) {
if(!sourceItem.hasTag("MMOITEMS_ARROW_POTION_EFFECTS")) return;
for(JsonElement entry : MMOLib.plugin.getJson().parse(sourceItem.getString("MMOITEMS_ARROW_POTION_EFFECTS"), JsonArray.class)) {
if(!entry.isJsonObject()) continue;
JsonObject object = entry.getAsJsonObject();
target.addPotionEffect(new PotionEffectData(PotionEffectType.getByName(object.get("type").getAsString()),
object.get("duration").getAsDouble(), object.get("level").getAsInt()).toEffect());
}
}
}

View File

@ -239,7 +239,7 @@ public class PlayerData {
if (getPermanentPotionEffectAmplifier(effect.getType()) < effect.getLevel() - 1)
permanentEffects.put(effect.getType(), effect.toEffect());
});
/*
* apply item particles
*/

View File

@ -93,6 +93,9 @@ public class EntityManager implements Listener {
Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> unregisterCustomEntity(event.getEntity()));
}
/*
* Projectile Damage and Effects
*/
@EventHandler(ignoreCancelled = true)
public void b(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Projectile) || !(event.getEntity() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC"))
@ -108,7 +111,9 @@ public class EntityManager implements Listener {
ItemAttackResult result = new ItemAttackResult(data.isCustomWeapon() ? stats.getStat(ItemStat.ATTACK_DAMAGE) : event.getDamage(),
DamageType.WEAPON, DamageType.PROJECTILE, DamageType.PHYSICAL).applyOnHitEffects(stats, target);
data.applyEffects(target);
/*
* only modify the damage when the bow used is a custom weapon.
*/

View File

@ -0,0 +1,153 @@
package net.Indyuce.mmoitems.stat;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.PotionEffectData;
import net.Indyuce.mmoitems.stat.data.PotionEffectListData;
import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectData;
import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectListData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.util.AltChar;
public class ArrowPotionEffects extends ItemStat {
private final DecimalFormat durationFormat = new DecimalFormat("0.#");
public ArrowPotionEffects() {
super("ARROW_POTION_EFFECTS", new ItemStack(Material.TIPPED_ARROW), "Arrow Potion Effects",
new String[] { "The effects to be applied when", "entities are shot by this bow" }, new String[] { "bow", "crossbow" });
}
@Override
public RandomStatData whenInitialized(Object object) {
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section");
return new RandomPotionEffectListData((ConfigurationSection) object);
}
@Override
public void whenClicked(EditionInventory inv, InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStat.ARROW_POTION_EFFECTS).enable("Write in the chat the potion effect you want to add.",
ChatColor.AQUA + "Format: [POTION_EFFECT] [DURATION] [AMPLIFIER]");
if (event.getAction() == InventoryAction.PICKUP_HALF) {
if (inv.getEditedSection().contains("arrow-potion-effects")) {
Set<String> set = inv.getEditedSection().getConfigurationSection("arrow-potion-effects").getKeys(false);
String last = Arrays.asList(set.toArray(new String[0])).get(set.size() - 1);
inv.getEditedSection().set("arrow-potion-effects." + last, null);
if (set.size() <= 1)
inv.getEditedSection().set("arrow-potion-effects", null);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + last.substring(0, 1).toUpperCase()
+ last.substring(1).toLowerCase() + ChatColor.GRAY + ".");
}
}
}
@Override
public void whenInput(EditionInventory inv, String message, Object... info) {
String[] split = message.split("\\ ");
Validate.isTrue(split.length == 3,
message + " is not a valid [POTION_EFFECT] [DURATION] [AMPLIFIER]. Example: 'FAST_DIGGING 30 3' stands for Haste 3 for 30 seconds.");
PotionEffectType effect = null;
for (PotionEffectType effect1 : PotionEffectType.values())
if (effect1 != null)
if (effect1.getName().equalsIgnoreCase(split[0].replace("-", "_"))) {
effect = effect1;
break;
}
Validate.notNull(effect, split[0] + " is not a valid potion effect.");
double duration = MMOUtils.parseDouble(split[1]);
int amplifier = (int) MMOUtils.parseDouble(split[2]);
ConfigurationSection section = inv.getEditedSection().createSection("arrow-potion-effects." + effect.getName());
section.set("duration", duration);
section.set("amplifier", amplifier);
inv.getEditedSection().set("arrow-potion-effects." + effect.getName(), section);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + effect.getName() + " " + amplifier + " successfully added.");
}
@Override
public void whenDisplayed(List<String> lore, Optional<RandomStatData> optional) {
if (optional.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
RandomPotionEffectListData data = (RandomPotionEffectListData) optional.get();
for (RandomPotionEffectData effect : data.getEffects())
lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().toLowerCase().replace("_", " "))
+ ChatColor.GRAY + " Level: " + ChatColor.GREEN + effect.getAmplifier() + ChatColor.GRAY + " Duration: " + ChatColor.GREEN
+ effect.getDuration());
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None");
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add an effect.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last effect.");
}
@Override
public void whenApplied(ItemStackBuilder item, StatData data) {
JsonArray array = new JsonArray();
List<String> lore = new ArrayList<>();
String permEffectFormat = ItemStat.translate("arrow-potion-effects");
((PotionEffectListData) data).getEffects().forEach(effect -> {
lore.add(permEffectFormat.replace("#", MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType())
+ " " + MMOUtils.intToRoman(effect.getLevel()) + "(" + durationFormat.format(effect.getDuration()) + "s)"));
JsonObject object = new JsonObject();
object.addProperty("type", effect.getType().getName());
object.addProperty("level", effect.getLevel());
object.addProperty("duration", effect.getDuration());
array.add(object);
});
item.getLore().insert("arrow-potion-effects", lore);
item.addItemTag(new ItemTag(getNBTPath(), array.toString()));
}
@Override
public void whenLoaded(ReadMMOItem mmoitem) {
if (mmoitem.getNBT().hasTag(getNBTPath())) {
PotionEffectListData effects = new PotionEffectListData();
for(JsonElement entry : MMOLib.plugin.getJson().parse(mmoitem.getNBT().getString(getNBTPath()), JsonArray.class)) {
if(!entry.isJsonObject()) continue;
JsonObject object = entry.getAsJsonObject();
effects.add(new PotionEffectData(PotionEffectType.getByName(object.get("type").getAsString()),
object.get("duration").getAsDouble(), object.get("level").getAsInt()));
}
mmoitem.setData(ItemStat.ARROW_POTION_EFFECTS, effects);
}
}
}

View File

@ -118,8 +118,8 @@ public class PermanentEffects extends ItemStat {
String permEffectFormat = ItemStat.translate("perm-effect");
((PotionEffectListData) data).getEffects().forEach(effect -> {
lore.add(permEffectFormat.replace("#",
MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType()) + " " + MMOUtils.intToRoman(effect.getLevel())));
lore.add(permEffectFormat.replace("#", MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType())
+ " " + MMOUtils.intToRoman(effect.getLevel())));
object.addProperty(effect.getType().getName(), effect.getLevel());
});

View File

@ -18,6 +18,7 @@ import net.Indyuce.mmoitems.stat.Abilities;
import net.Indyuce.mmoitems.stat.Armor;
import net.Indyuce.mmoitems.stat.ArmorToughness;
import net.Indyuce.mmoitems.stat.ArrowParticles;
import net.Indyuce.mmoitems.stat.ArrowPotionEffects;
import net.Indyuce.mmoitems.stat.AttackDamage;
import net.Indyuce.mmoitems.stat.AttackSpeed;
import net.Indyuce.mmoitems.stat.Commands;
@ -148,7 +149,8 @@ public abstract class ItemStat {
public static final ItemStat STAMINA_COST = new DoubleStat("STAMINA_COST", VersionMaterial.LIGHT_GRAY_DYE.toItem(), "Stamina Cost",
new String[] { "Stamina spent by your weapon to be used." }, new String[] { "piercing", "slashing", "blunt", "range" });
public static final ItemStat ARROW_VELOCITY = new DoubleStat("ARROW_VELOCITY", new ItemStack(Material.ARROW), "Arrow Velocity",
new String[] { "Determins how far your", "crossbow can shoot.", "Default: 1.0" }, new String[] { "bow", "crossbow" });
new String[] { "Determins how far your", "weapon can shoot.", "Default: 1.0" }, new String[] { "bow", "crossbow" });
public static final ItemStat ARROW_POTION_EFFECTS = new ArrowPotionEffects();
public static final ItemStat PVE_DAMAGE = new DoubleStat("PVE_DAMAGE", VersionMaterial.PORKCHOP.toItem(), "PvE Damage",
new String[] { "Additional damage against", "non human entities in %." },
new String[] { "piercing", "slashing", "blunt", "offhand", "range", "tool", "armor", "gem_stone", "accessory" });

View File

@ -27,7 +27,7 @@ HELL_BOW:
infinity: 1
hide-enchants: true
unbreakable: true
tier: '&6Rare'
tier: RARE
attack-damage:
base: 11.5
spread: 0.038

View File

@ -120,6 +120,7 @@ lore-format:
- '#commands#'
# - '{bar}&8&m--------&b&l &nEffects&8 &m---------------'
# - '#perm-effects#'
# - '#arrow-potion-effects#'
# - '{bar}&8&m--------&e&l &nGem Stones&8 &m-----------'
- '{bar}'
- '#gem-stones#'

View File

@ -66,6 +66,7 @@ additional-experience: '&7■ Additional Experience: &f<plus>#%'
perm-effect: '&7■ Permanent &f#'
command: '&7■ Command: &f#c &7(&f#d&7s)'
item-cooldown: '&7■ &f#&7s Cooldown'
arrow-potion-effects: '&7■ Arrow Effect: &f#'
# Consumables
restore-health: '&7■ Restores &f# &7Health'