mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-03-01 15:51:03 +01:00
Merge branch 'master' of https://git.lumine.io/mythiccraft/mmoitems.git
This commit is contained in:
commit
a3bf37d334
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmoitems;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.CompatibleIds;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.Abilities;
|
||||
@ -208,6 +209,7 @@ public class ItemStats {
|
||||
MAX_CONSUME = new DoubleStat("MAX_CONSUME", Material.BLAZE_POWDER, "Max Consume", new String[]{"Max amount of usage before", "item disappears."}, new String[]{"consumable"}),
|
||||
SUCCESS_RATE = new SuccessRate(),
|
||||
COMPATIBLE_TYPES = new CompatibleTypes(),
|
||||
COMPATIBLE_IDS = new CompatibleIds(),
|
||||
|
||||
// Crafting Stats
|
||||
CRAFTING = new Crafting(),
|
||||
|
@ -1,11 +1,13 @@
|
||||
package net.Indyuce.mmoitems.ability;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -49,8 +51,12 @@ public class Hoearthquake extends Ability {
|
||||
for (int x = -1; x < 2; x++)
|
||||
for (int z = -1; z < 2; z++) {
|
||||
Block b = loc.clone().add(x, -1, z).getBlock();
|
||||
if (b.getType() == Material.GRASS || b.getType() == Material.DIRT)
|
||||
b.setType(Material.FARMLAND);
|
||||
if (b.getType() == Material.GRASS || b.getType() == Material.DIRT) {
|
||||
BlockBreakEvent event = new BlockBreakEvent(b, stats.getPlayer());
|
||||
event.setDropItems(false);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) b.setType(Material.FARMLAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(MMOItems.plugin, 0, 1);
|
||||
|
@ -53,6 +53,22 @@ public class ItemSkin extends UseItem {
|
||||
}
|
||||
}
|
||||
|
||||
if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) {
|
||||
for (String id : ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList()) {
|
||||
if (id.equalsIgnoreCase(target.getString("MMOITEMS_ITEM_ID"))) {
|
||||
compatible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!compatible) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||
.send(player);
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
// check for success rate
|
||||
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
|
||||
if (successRate != 0)
|
||||
|
@ -14,7 +14,6 @@ import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import net.mmogroup.mmolib.version.VersionSound;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -46,7 +45,7 @@ public class Lute extends UntargetedWeapon {
|
||||
Vector weight = new Vector(0, -.003 * getNBTItem().getStat(ItemStats.NOTE_WEIGHT.getId()), 0);
|
||||
|
||||
LuteAttackEffect effect = LuteAttackEffect.get(getNBTItem());
|
||||
Sound sound = new SoundReader(getNBTItem().getString("MMOITEMS_LUTE_ATTACK_SOUND"), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound()).getSound();
|
||||
SoundReader sound = new SoundReader(getNBTItem().getString("MMOITEMS_LUTE_ATTACK_SOUND"), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound());
|
||||
if (effect != null) {
|
||||
effect.getAttack().handle(stats, getNBTItem(), attackDamage, range, weight, sound);
|
||||
return;
|
||||
@ -63,7 +62,7 @@ public class Lute extends UntargetedWeapon {
|
||||
|
||||
List<Entity> entities = MMOUtils.getNearbyChunkEntities(loc);
|
||||
loc.getWorld().spawnParticle(Particle.NOTE, loc, 0);
|
||||
loc.getWorld().playSound(loc, sound, 2, (float) (.5 + (double) ti / range));
|
||||
sound.play(loc, 2, (float) (.5 + (double) ti / range));
|
||||
for (int j = 0; j < 3; j++) {
|
||||
loc.add(vec.add(weight));
|
||||
if (loc.getBlock().getType().isSolid()) {
|
||||
|
@ -1,34 +1,32 @@
|
||||
package net.Indyuce.mmoitems.api.interaction.weapon.untargeted.lute;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.SoundReader;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BruteLuteAttack implements LuteAttackHandler {
|
||||
|
||||
@Override
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, Sound sound) {
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, SoundReader sound) {
|
||||
new BukkitRunnable() {
|
||||
final Vector vec = stats.getPlayer().getEyeLocation().getDirection().multiply(.4);
|
||||
final Location loc = stats.getPlayer().getEyeLocation();
|
||||
int ti = 0;
|
||||
|
||||
public void run() {
|
||||
if (ti++ > range)
|
||||
cancel();
|
||||
if (ti++ > range) cancel();
|
||||
|
||||
List<Entity> entities = MMOUtils.getNearbyChunkEntities(loc);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
@ -39,8 +37,7 @@ public class BruteLuteAttack implements LuteAttackHandler {
|
||||
}
|
||||
|
||||
loc.getWorld().spawnParticle(Particle.NOTE, loc, 2, .1, .1, .1, 0);
|
||||
if (j == 0)
|
||||
loc.getWorld().playSound(loc, sound, 2, (float) (.5 + (double) ti / range));
|
||||
if (j == 0) sound.play(loc, 2, (float) (.5 + (double) ti / range));
|
||||
|
||||
for (Entity target : entities)
|
||||
if (MMOUtils.canDamage(stats.getPlayer(), loc, target)) {
|
||||
|
@ -1,34 +1,32 @@
|
||||
package net.Indyuce.mmoitems.api.interaction.weapon.untargeted.lute;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.SoundReader;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CircularLuteAttack implements LuteAttackHandler {
|
||||
|
||||
@Override
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, Sound sound) {
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, SoundReader sound) {
|
||||
new BukkitRunnable() {
|
||||
final Vector vec = stats.getPlayer().getEyeLocation().getDirection().multiply(.4);
|
||||
final Location loc = stats.getPlayer().getEyeLocation();
|
||||
int ti = 0;
|
||||
|
||||
public void run() {
|
||||
if (ti++ > range)
|
||||
cancel();
|
||||
if (ti++ > range) cancel();
|
||||
|
||||
List<Entity> entities = MMOUtils.getNearbyChunkEntities(loc);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
@ -42,8 +40,7 @@ public class CircularLuteAttack implements LuteAttackHandler {
|
||||
Vector vec = MMOUtils.rotateFunc(new Vector(Math.cos(a), Math.sin(a), 0).multiply(.3), loc);
|
||||
loc.getWorld().spawnParticle(Particle.NOTE, loc.clone().add(vec), 0);
|
||||
loc.getWorld().spawnParticle(Particle.NOTE, loc.clone().add(vec.multiply(-1)), 0);
|
||||
if (j == 0)
|
||||
loc.getWorld().playSound(loc, sound, 2, (float) (.5 + (double) ti / range));
|
||||
if (j == 0) sound.play(loc, 2, (float) (.5 + (double) ti / range));
|
||||
|
||||
for (Entity target : entities)
|
||||
if (MMOUtils.canDamage(stats.getPlayer(), loc, target)) {
|
||||
|
@ -2,6 +2,7 @@ package net.Indyuce.mmoitems.api.interaction.weapon.untargeted.lute;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.Indyuce.mmoitems.api.util.SoundReader;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -9,7 +10,7 @@ import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
|
||||
public interface LuteAttackHandler {
|
||||
void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, Sound sound);
|
||||
void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, SoundReader sound);
|
||||
|
||||
Random random = new Random();
|
||||
}
|
||||
|
@ -1,34 +1,32 @@
|
||||
package net.Indyuce.mmoitems.api.interaction.weapon.untargeted.lute;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.SoundReader;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleLuteAttack implements LuteAttackHandler {
|
||||
|
||||
@Override
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, Sound sound) {
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, SoundReader sound) {
|
||||
new BukkitRunnable() {
|
||||
final Vector vec = stats.getPlayer().getEyeLocation().getDirection().multiply(.4);
|
||||
final Location loc = stats.getPlayer().getEyeLocation();
|
||||
int ti = 0;
|
||||
|
||||
public void run() {
|
||||
if (ti++ > range)
|
||||
cancel();
|
||||
if (ti++ > range) cancel();
|
||||
|
||||
List<Entity> entities = MMOUtils.getNearbyChunkEntities(loc);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
@ -39,8 +37,7 @@ public class SimpleLuteAttack implements LuteAttackHandler {
|
||||
}
|
||||
|
||||
loc.getWorld().spawnParticle(Particle.NOTE, loc, 0);
|
||||
if (j == 0)
|
||||
loc.getWorld().playSound(loc, sound, 2, (float) (.5 + (double) ti / range));
|
||||
if (j == 0) sound.play(loc, 2, (float) (.5 + (double) ti / range));
|
||||
|
||||
for (Entity target : entities)
|
||||
if (MMOUtils.canDamage(stats.getPlayer(), loc, target)) {
|
||||
|
@ -1,34 +1,32 @@
|
||||
package net.Indyuce.mmoitems.api.interaction.weapon.untargeted.lute;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.SoundReader;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class SlashLuteAttack implements LuteAttackHandler {
|
||||
|
||||
@Override
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, Sound sound) {
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, SoundReader sound) {
|
||||
new BukkitRunnable() {
|
||||
final Vector vec = stats.getPlayer().getEyeLocation().getDirection();
|
||||
final Location loc = stats.getPlayer().getLocation().add(0, 1.3, 0);
|
||||
double ti = 1;
|
||||
|
||||
public void run() {
|
||||
if ((ti += .6) > 5)
|
||||
cancel();
|
||||
if ((ti += .6) > 5) cancel();
|
||||
|
||||
loc.getWorld().playSound(loc, sound, 2, (float) (.5 + ti / 5));
|
||||
sound.play(loc, 2, (float) (.5 + ti / range));
|
||||
for (int k = -30; k < 30; k += 3)
|
||||
if (random.nextBoolean()) {
|
||||
loc.setDirection(vec);
|
||||
|
@ -1,34 +1,32 @@
|
||||
package net.Indyuce.mmoitems.api.interaction.weapon.untargeted.lute;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ItemAttackResult;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
|
||||
import net.Indyuce.mmoitems.api.util.SoundReader;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WaveLuteAttack implements LuteAttackHandler {
|
||||
|
||||
@Override
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, Sound sound) {
|
||||
public void handle(CachedStats stats, NBTItem nbt, double attackDamage, double range, Vector weight, SoundReader sound) {
|
||||
new BukkitRunnable() {
|
||||
final Vector vec = stats.getPlayer().getEyeLocation().getDirection().multiply(.4);
|
||||
final Location loc = stats.getPlayer().getEyeLocation();
|
||||
int ti = 0;
|
||||
|
||||
public void run() {
|
||||
if (ti++ > range)
|
||||
cancel();
|
||||
if (ti++ > range) cancel();
|
||||
|
||||
List<Entity> entities = MMOUtils.getNearbyChunkEntities(loc);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
@ -41,8 +39,7 @@ public class WaveLuteAttack implements LuteAttackHandler {
|
||||
Vector vec = MMOUtils.rotateFunc(new Vector(.5, 0, 0), loc);
|
||||
loc.getWorld().spawnParticle(Particle.NOTE, loc.clone().add(vec.multiply(Math.sin((double) ti / 2))), 0);
|
||||
loc.getWorld().spawnParticle(Particle.NOTE, loc.clone().add(vec.multiply(-1)), 0);
|
||||
if (j == 0)
|
||||
loc.getWorld().playSound(loc, sound, 2, (float) (.5 + (double) ti / range));
|
||||
if (j == 0) sound.play(loc, 2, (float) (.5 + (double) ti / range));
|
||||
|
||||
for (Entity target : entities)
|
||||
if (MMOUtils.canDamage(stats.getPlayer(), loc, target)) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmoitems.api.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -25,7 +26,7 @@ public class SoundReader {
|
||||
}
|
||||
|
||||
this.sound = sound;
|
||||
this.soundKey = soundKey;
|
||||
this.soundKey = soundKey.toLowerCase();
|
||||
}
|
||||
|
||||
public Sound getSound() {
|
||||
@ -46,4 +47,15 @@ public class SoundReader {
|
||||
else
|
||||
player.playSound(player.getLocation(), soundKey, vol, pitch);
|
||||
}
|
||||
|
||||
public void play(Location loc) {
|
||||
play(loc, 1, 1);
|
||||
}
|
||||
|
||||
public void play(Location loc, float vol, float pitch) {
|
||||
if(soundKey.isEmpty())
|
||||
loc.getWorld().playSound(loc, sound, vol, pitch);
|
||||
else
|
||||
loc.getWorld().playSound(loc, soundKey, vol, pitch);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmoitems.comp.rpg;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -44,7 +45,7 @@ public class SkillsProHook implements RPGHandler, Listener {
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return info.getSkillName();
|
||||
return ChatColor.stripColor(info.getSkill().getDisplayName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
103
src/main/java/net/Indyuce/mmoitems/stat/CompatibleIds.java
Normal file
103
src/main/java/net/Indyuce/mmoitems/stat/CompatibleIds.java
Normal file
@ -0,0 +1,103 @@
|
||||
package net.Indyuce.mmoitems.stat;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
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.StringListData;
|
||||
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.api.item.ItemTag;
|
||||
import net.mmogroup.mmolib.api.util.AltChar;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CompatibleIds extends ItemStat {
|
||||
public CompatibleIds() {
|
||||
super("COMPATIBLE_IDS", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible IDs",
|
||||
new String[] { "The item ids this skin is", "compatible with." }, new String[] { "skin" });
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public StringListData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
|
||||
return new StringListData((List<String>) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new StatEdition(inv, ItemStats.COMPATIBLE_IDS).enable("Write in the chat the item id you want to add.");
|
||||
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (inv.getEditedSection().contains("compatible-ids")) {
|
||||
List<String> lore = inv.getEditedSection().getStringList("compatible-ids");
|
||||
if (lore.size() < 1)
|
||||
return;
|
||||
|
||||
String last = lore.get(lore.size() - 1);
|
||||
lore.remove(last);
|
||||
inv.getEditedSection().set("compatible-ids", lore);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenInput(EditionInventory inv, String message, Object... info) {
|
||||
List<String> lore = inv.getEditedSection().contains("compatible-ids") ? inv.getEditedSection().getStringList("compatible-ids")
|
||||
: new ArrayList<>();
|
||||
lore.add(message.toUpperCase());
|
||||
inv.getEditedSection().set("compatible-ids", lore);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible IDs successfully added.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<RandomStatData> statData) {
|
||||
|
||||
if (statData.isPresent()) {
|
||||
lore.add(ChatColor.GRAY + "Current Value:");
|
||||
((StringListData) statData.get()).getList().forEach(str -> lore.add(ChatColor.GRAY + str));
|
||||
|
||||
} else
|
||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
|
||||
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new id.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last id.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(ItemStackBuilder item, StatData data) {
|
||||
List<String> compatibleIds = new ArrayList<>();
|
||||
JsonArray array = new JsonArray();
|
||||
((StringListData) data).getList().forEach(line -> {
|
||||
array.add(line);
|
||||
compatibleIds.add(line);
|
||||
});
|
||||
item.getLore().insert("compatible-ids", compatibleIds);
|
||||
item.addItemTag(new ItemTag("MMOITEMS_COMPATIBLE_IDS", array.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenLoaded(ReadMMOItem mmoitem) {
|
||||
if (mmoitem.getNBT().hasTag("MMOITEMS_COMPATIBLE_IDS"))
|
||||
mmoitem.setData(ItemStats.COMPATIBLE_IDS,
|
||||
new StringListData(new JsonParser().parse(mmoitem.getNBT().getString("MMOITEMS_COMPATIBLE_IDS")).getAsJsonArray()));
|
||||
}
|
||||
}
|
@ -63,7 +63,7 @@ public class StringStat extends ItemStat {
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<RandomStatData> statData) {
|
||||
if (statData.isPresent()) {
|
||||
String value = MMOLib.plugin.parseColors(statData.toString());
|
||||
String value = MMOLib.plugin.parseColors(statData.get().toString());
|
||||
value = value.length() > 40 ? value.substring(0, 40) + "..." : value;
|
||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GREEN + value);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user