mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-02 06:27:42 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9ea67c5fda
@ -158,6 +158,7 @@ public class ItemStats {
|
|||||||
REMOVE_ON_CRAFT = new BooleanStat("REMOVE_ON_CRAFT", Material.GLASS_BOTTLE, "Remove on Craft", new String[]{"If the item should be completely", "removed when used in a recipe,", "or if it should become an", "empty bottle or bucket."}, new String[]{"all"}, Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.MILK_BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET),
|
REMOVE_ON_CRAFT = new BooleanStat("REMOVE_ON_CRAFT", Material.GLASS_BOTTLE, "Remove on Craft", new String[]{"If the item should be completely", "removed when used in a recipe,", "or if it should become an", "empty bottle or bucket."}, new String[]{"all"}, Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.MILK_BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET),
|
||||||
COMPATIBLE_TYPES = new CompatibleTypes(),
|
COMPATIBLE_TYPES = new CompatibleTypes(),
|
||||||
COMPATIBLE_IDS = new CompatibleIds(),
|
COMPATIBLE_IDS = new CompatibleIds(),
|
||||||
|
COMPATIBLE_MATERIALS = new CompatibleMaterials(),
|
||||||
GEM_SOCKETS = new GemSockets(),
|
GEM_SOCKETS = new GemSockets(),
|
||||||
RANDOM_UNSOCKET = new RandomUnsocket(),
|
RANDOM_UNSOCKET = new RandomUnsocket(),
|
||||||
//todo CAN_UNSOCKET = new CanUnsocket(),
|
//todo CAN_UNSOCKET = new CanUnsocket(),
|
||||||
|
@ -47,6 +47,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -54,6 +55,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -83,7 +85,7 @@ public class MMOItems extends JavaPlugin {
|
|||||||
private SetManager setManager;
|
private SetManager setManager;
|
||||||
|
|
||||||
private VaultSupport vaultSupport;
|
private VaultSupport vaultSupport;
|
||||||
private RPGHandler rpgPlugin;
|
private final List<RPGHandler> rpgPlugins = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Startup issues usually prevent the plugin from loading and just
|
* Startup issues usually prevent the plugin from loading and just
|
||||||
@ -152,7 +154,7 @@ public class MMOItems extends JavaPlugin {
|
|||||||
});
|
});
|
||||||
PluginUtils.hookDependencyIfPresent("MMOInventory", unused -> new MMOInventorySupport());
|
PluginUtils.hookDependencyIfPresent("MMOInventory", unused -> new MMOInventorySupport());
|
||||||
|
|
||||||
findRpgPlugin();
|
findRpgPlugins();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* After tiers, sets and upgrade templates are loaded, MI template data
|
* After tiers, sets and upgrade templates are loaded, MI template data
|
||||||
@ -293,8 +295,19 @@ public class MMOItems extends JavaPlugin {
|
|||||||
return setManager;
|
return setManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public RPGHandler getRPG() {
|
public RPGHandler getRPG() {
|
||||||
return rpgPlugin;
|
return getMainRPG();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public RPGHandler getMainRPG() {
|
||||||
|
Validate.isTrue(!rpgPlugins.isEmpty(), "No RPG plugin was found");
|
||||||
|
return rpgPlugins.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RPGHandler> getRPGs() {
|
||||||
|
return rpgPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -306,21 +319,38 @@ public class MMOItems extends JavaPlugin {
|
|||||||
* provider in the main plugin config. If it can't be found, it will look for RPG
|
* provider in the main plugin config. If it can't be found, it will look for RPG
|
||||||
* plugins in the installed plugin list.
|
* plugins in the installed plugin list.
|
||||||
*/
|
*/
|
||||||
public void findRpgPlugin() {
|
public void findRpgPlugins() {
|
||||||
if (rpgPlugin != null) return;
|
Validate.isTrue(rpgPlugins.isEmpty(), "RPG hooks have already been computed");
|
||||||
|
|
||||||
// Preferred rpg provider
|
// Default hook
|
||||||
String preferred = plugin.getConfig().getString("preferred-rpg-provider", null);
|
rpgPlugins.add(new DefaultHook());
|
||||||
if (preferred != null && setRPG(RPGHandler.PluginEnum.valueOf(preferred.toUpperCase())))
|
|
||||||
return;
|
// Find preferred provider
|
||||||
|
final @NotNull String preferredName = plugin.getConfig().getString("preferred-rpg-provider");
|
||||||
|
|
||||||
// Look through installed plugins
|
// Look through installed plugins
|
||||||
for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values())
|
for (RPGHandler.PluginEnum enumPlugin : RPGHandler.PluginEnum.values())
|
||||||
if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null && setRPG(pluginEnum))
|
if (Bukkit.getPluginManager().getPlugin(enumPlugin.getName()) != null)
|
||||||
return;
|
try {
|
||||||
|
final RPGHandler handler = enumPlugin.load();
|
||||||
|
rpgPlugins.add(handler);
|
||||||
|
getLogger().log(Level.INFO, "Hooked onto " + enumPlugin.getName());
|
||||||
|
|
||||||
// Just use the default
|
// Register as main RPG plugin
|
||||||
setRPG(new DefaultHook());
|
if (preferredName.equalsIgnoreCase(enumPlugin.name())) {
|
||||||
|
Collections.swap(rpgPlugins, 0, rpgPlugins.size() - 1);
|
||||||
|
getLogger().log(Level.INFO, "Now using " + enumPlugin.getName() + " as RPG core plugin");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception exception) {
|
||||||
|
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + enumPlugin.getName() + ":");
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register listener for preferred provider
|
||||||
|
final @NotNull RPGHandler preferred = rpgPlugins.get(0);
|
||||||
|
if (rpgPlugins.get(0) instanceof Listener)
|
||||||
|
Bukkit.getPluginManager().registerEvents((Listener) preferred, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -330,14 +360,14 @@ public class MMOItems extends JavaPlugin {
|
|||||||
*
|
*
|
||||||
* @param handler Your RPGHandler instance
|
* @param handler Your RPGHandler instance
|
||||||
*/
|
*/
|
||||||
public void setRPG(RPGHandler handler) {
|
public void setRPG(@NotNull RPGHandler handler) {
|
||||||
Validate.notNull(handler, "RPGHandler cannot be null");
|
Validate.notNull(handler, "RPGHandler cannot be null");
|
||||||
|
|
||||||
// Unregister events from current RPGPlugin instance
|
// Unregister old events
|
||||||
if (rpgPlugin != null && rpgPlugin instanceof Listener && isEnabled())
|
if (getMainRPG() instanceof Listener && isEnabled())
|
||||||
HandlerList.unregisterAll((Listener) rpgPlugin);
|
HandlerList.unregisterAll((Plugin) getMainRPG());
|
||||||
|
|
||||||
rpgPlugin = handler;
|
rpgPlugins.add(0, handler);
|
||||||
getLogger().log(Level.INFO, "Now using " + handler.getClass().getSimpleName() + " as RPG provider");
|
getLogger().log(Level.INFO, "Now using " + handler.getClass().getSimpleName() + " as RPG provider");
|
||||||
|
|
||||||
// Register new events
|
// Register new events
|
||||||
@ -345,25 +375,6 @@ public class MMOItems extends JavaPlugin {
|
|||||||
Bukkit.getPluginManager().registerEvents((Listener) handler, this);
|
Bukkit.getPluginManager().registerEvents((Listener) handler, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param potentialPlugin Some plugin that the user wants compatibility with
|
|
||||||
* @return If it worked
|
|
||||||
*/
|
|
||||||
public boolean setRPG(RPGHandler.PluginEnum potentialPlugin) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Validate.notNull(Bukkit.getPluginManager().getPlugin(potentialPlugin.getName()), "Plugin is not installed");
|
|
||||||
setRPG(potentialPlugin.load());
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Some loading issue
|
|
||||||
} catch (Exception exception) {
|
|
||||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + potentialPlugin.getName() + ":");
|
|
||||||
exception.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public PluginUpdateManager getUpdates() {
|
public PluginUpdateManager getUpdates() {
|
||||||
return pluginUpdateManager;
|
return pluginUpdateManager;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
|||||||
import net.Indyuce.mmoitems.ItemStats;
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.Type;
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||||
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
||||||
@ -265,7 +265,7 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
if (dataments.endsWith("}")) { dataments = dataments.substring(0, dataments.length()-1); } }
|
if (dataments.endsWith("}")) { dataments = dataments.substring(0, dataments.length()-1); } }
|
||||||
|
|
||||||
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
|
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
|
||||||
MMOItem m = MMOItems.plugin.getMMOItem(MMOItems.plugin.getTypes().get(argument), data);
|
MMOItem m = new MMOItemBuilder(MMOItems.plugin.getTemplates().getTemplate(MMOItems.plugin.getTypes().get(argument), data), 0, null, true).build();
|
||||||
|
|
||||||
// Find upgrade?
|
// Find upgrade?
|
||||||
if (!dataments.isEmpty()) {
|
if (!dataments.isEmpty()) {
|
||||||
@ -287,11 +287,8 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
ItemStackBuilder builder = m.newBuilder();
|
|
||||||
|
|
||||||
// Build display NBT and roll
|
// Build display NBT and roll
|
||||||
return builder.buildNBT(true).toItem();
|
return m.newBuilder().buildNBT(true).toItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -88,7 +88,7 @@ public class MMOItemIngredient extends Ingredient<MMOItemPlayerIngredient> {
|
|||||||
public ItemStack generateItemStack(@NotNull RPGPlayer player) {
|
public ItemStack generateItemStack(@NotNull RPGPlayer player) {
|
||||||
|
|
||||||
// Generate fresh from the template
|
// Generate fresh from the template
|
||||||
MMOItem mmo = template.newBuilder(player).build();
|
MMOItem mmo = template.newBuilder(player, true).build();
|
||||||
|
|
||||||
// Build it for display, obviously
|
// Build it for display, obviously
|
||||||
ItemStack item = mmo.newBuilder().build(true);
|
ItemStack item = mmo.newBuilder().build(true);
|
||||||
|
@ -5,12 +5,12 @@ import io.lumine.mythic.lib.api.item.NBTItem;
|
|||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmoitems.ItemStats;
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
|
||||||
import net.Indyuce.mmoitems.api.Type;
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||||
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
|
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
|
||||||
import net.Indyuce.mmoitems.stat.data.StringListData;
|
import net.Indyuce.mmoitems.stat.data.StringListData;
|
||||||
|
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -25,245 +25,240 @@ import java.lang.reflect.Field;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemSkin extends UseItem {
|
public class ItemSkin extends UseItem {
|
||||||
public ItemSkin(Player player, NBTItem item) {
|
public ItemSkin(Player player, NBTItem item) {
|
||||||
super(player, item);
|
super(player, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplyResult applyOntoItem(NBTItem target, Type targetType) {
|
public ApplyResult applyOntoItem(NBTItem target, Type targetType) {
|
||||||
if (targetType == Type.SKIN)
|
if (targetType == Type.SKIN)
|
||||||
return new ApplyResult(ResultType.NONE);
|
return new ApplyResult(ResultType.NONE);
|
||||||
|
|
||||||
if (MMOItems.plugin.getConfig().getBoolean("locked-skins") && target.getBoolean("MMOITEMS_HAS_SKIN")) {
|
if (MMOItems.plugin.getConfig().getBoolean("locked-skins") && target.getBoolean("MMOITEMS_HAS_SKIN")) {
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
|
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
|
||||||
Message.SKIN_REJECTED.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
Message.SKIN_REJECTED.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||||
.send(player);
|
.send(player);
|
||||||
return new ApplyResult(ResultType.NONE);
|
return new ApplyResult(ResultType.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean compatible = false;
|
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Applying onto " + MMOUtils.getDisplayName(target.getItem()));
|
||||||
|
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Applying onto " + MMOUtils.getDisplayName(target.getItem()));
|
// Types compatibility check
|
||||||
|
if (getMMOItem().hasData(ItemStats.COMPATIBLE_TYPES)) {
|
||||||
|
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that TYPE is compatible: ");
|
||||||
|
final List<String> acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList();
|
||||||
|
if (acceptedTypes.size() > 0 && acceptedTypes.stream().noneMatch(s -> s.equalsIgnoreCase(targetType.getId()))) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (getMMOItem().hasData(ItemStats.COMPATIBLE_TYPES)) {
|
// IDs compatibility check
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that TYPE is compatible: ");
|
if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) {
|
||||||
|
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: ");
|
||||||
|
final List<String> acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList();
|
||||||
|
final String targetId = target.getString("MMOITEMS_ITEM_ID");
|
||||||
|
|
||||||
List<String> acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList();
|
if (acceptedIDs.size() > 0 && acceptedIDs.stream()
|
||||||
|
.noneMatch(s -> s.equalsIgnoreCase(targetId))) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String type : acceptedTypes) {
|
// Material compatibility check
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7e >\u00a7f " + type);
|
if (getMMOItem().hasData(ItemStats.COMPATIBLE_MATERIALS)) {
|
||||||
|
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: ");
|
||||||
|
List<String> acceptedMaterials = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_MATERIALS)).getList();
|
||||||
|
|
||||||
if (type.equalsIgnoreCase(targetType.getId())) {
|
if (acceptedMaterials.size() > 0 && acceptedMaterials.stream()
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched");
|
.noneMatch(s -> s.equalsIgnoreCase(target.getItem().getType().name()))) {
|
||||||
compatible = true; break; }
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!compatible && acceptedTypes.size() > 0) {
|
// check for success rate
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible");
|
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
|
||||||
|
if (successRate != 0)
|
||||||
|
if (RANDOM.nextDouble() < 1 - successRate / 100) {
|
||||||
|
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||||
|
Message.SKIN_BROKE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||||
|
.send(player);
|
||||||
|
return new ApplyResult(ResultType.FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
// Apply skin
|
||||||
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
ItemStack item = applySkin(target, getMMOItem());
|
||||||
.send(player);
|
|
||||||
return new ApplyResult(ResultType.NONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) {
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: ");
|
Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
||||||
|
|
||||||
List<String> acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList();
|
return new ApplyResult(item);
|
||||||
|
}
|
||||||
|
|
||||||
for (String id : acceptedIDs) {
|
public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN";
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + id);
|
|
||||||
|
|
||||||
if (id.equalsIgnoreCase(target.getString("MMOITEMS_ITEM_ID"))) {
|
/**
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched");
|
* When applying a skin to an item, the skin item ID is saved
|
||||||
compatible = true;break; }
|
* in the target item so that if deskined, it can be retrieved
|
||||||
}
|
* and given back to the player.
|
||||||
|
*/
|
||||||
|
public static final String SKIN_ID_TAG = "MMOITEMS_SKIN_ID";
|
||||||
|
|
||||||
if (!compatible && acceptedIDs.size() > 0) {
|
/**
|
||||||
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible");
|
* Applies the skin information from a skin consumable onto any item.
|
||||||
|
*
|
||||||
|
* @param target Target item that the skin has been <b>successfully</b> applied to
|
||||||
|
* @param skinItemMMO Skin consumable
|
||||||
|
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull VolatileMMOItem skinItemMMO) {
|
||||||
|
final NBTItem skinItemNBT = skinItemMMO.getNBT();
|
||||||
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
||||||
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
target.addTag(new ItemTag(SKIN_ID_TAG, skinItemNBT.getString("MMOITEMS_ITEM_ID")));
|
||||||
.send(player);
|
if (skinItemNBT.getInteger("CustomModelData") != 0)
|
||||||
return new ApplyResult(ResultType.NONE);
|
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData")));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for success rate
|
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
|
||||||
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
|
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
|
||||||
if (successRate != 0)
|
|
||||||
if (RANDOM.nextDouble() < 1 - successRate / 100) {
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
|
||||||
Message.SKIN_BROKE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
|
|
||||||
.send(player);
|
|
||||||
return new ApplyResult(ResultType.FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply skin
|
ItemStack item = target.toItem();
|
||||||
ItemStack item = applySkin(target, getMMOItem());
|
if (item.getType() != skinItemNBT.getItem().getType())
|
||||||
|
item.setType(skinItemNBT.getItem().getType());
|
||||||
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
ItemMeta meta = item.getItemMeta();
|
||||||
Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
|
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
|
||||||
|
if (skinMeta != null && meta != null) {
|
||||||
|
|
||||||
return new ApplyResult(item);
|
// TODO factorize with a ItemSkinStat stat interface
|
||||||
}
|
if (skinMeta.isUnbreakable()) {
|
||||||
|
meta.setUnbreakable(true);
|
||||||
|
if (meta instanceof Damageable && skinMeta instanceof Damageable)
|
||||||
|
((Damageable) meta).setDamage(((Damageable) skinMeta).getDamage());
|
||||||
|
}
|
||||||
|
|
||||||
public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN";
|
if (skinMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
|
||||||
|
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) skinMeta).getColor());
|
||||||
|
|
||||||
/**
|
if (skinItemMMO.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
||||||
* When applying a skin to an item, the skin item ID is saved
|
&& skinItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||||
* in the target item so that if deskined, it can be retrieved
|
try {
|
||||||
* and given back to the player.
|
Field profileField = meta.getClass().getDeclaredField("profile");
|
||||||
*
|
profileField.setAccessible(true);
|
||||||
*
|
profileField.set(meta,
|
||||||
*/
|
((SkullTextureData) skinItemMMO.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
|
||||||
public static final String SKIN_ID_TAG = "MMOITEMS_SKIN_ID";
|
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
item.setItemMeta(meta);
|
||||||
* Applies the skin information from a skin consumable onto any item.
|
}
|
||||||
*
|
|
||||||
* @param target Target item that the skin has been <b>successfully</b> applied to
|
|
||||||
* @param skinItemMMO Skin consumable
|
|
||||||
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull VolatileMMOItem skinItemMMO) {
|
|
||||||
final NBTItem skinItemNBT = skinItemMMO.getNBT();
|
|
||||||
|
|
||||||
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
return item;
|
||||||
target.addTag(new ItemTag(SKIN_ID_TAG, skinItemNBT.getString("MMOITEMS_ITEM_ID")));
|
}
|
||||||
if (skinItemNBT.getInteger("CustomModelData") != 0)
|
|
||||||
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData")));
|
|
||||||
|
|
||||||
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
|
/**
|
||||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
|
* Copies a skin from one item to another
|
||||||
|
*
|
||||||
|
* @param target Target item that you are copying the skin onto
|
||||||
|
* @param originalItemNBT Item with a skin already, as NBT. Operation will fail
|
||||||
|
* if it doesnt have a skin.
|
||||||
|
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
||||||
|
* @author Gunging
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem originalItemNBT) {
|
||||||
|
|
||||||
ItemStack item = target.toItem();
|
// No skin no service
|
||||||
if (item.getType() != skinItemNBT.getItem().getType())
|
if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) {
|
||||||
item.setType(skinItemNBT.getItem().getType());
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
// Copy over data
|
||||||
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
|
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
||||||
if (skinMeta != null && meta != null) {
|
target.addTag(new ItemTag(SKIN_ID_TAG, originalItemNBT.getString("MMOITEMS_ITEM_ID")));
|
||||||
|
if (originalItemNBT.getInteger("CustomModelData") != 0) {
|
||||||
|
target.addTag(new ItemTag("CustomModelData", originalItemNBT.getInteger("CustomModelData")));
|
||||||
|
}
|
||||||
|
if (!originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
|
||||||
|
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO factorize with a ItemSkinStat stat interface
|
// ItemMeta values copy-over
|
||||||
if (skinMeta.isUnbreakable()) {
|
ItemStack item = target.toItem();
|
||||||
meta.setUnbreakable(true);
|
if (item.getType() != originalItemNBT.getItem().getType()) {
|
||||||
if (meta instanceof Damageable && skinMeta instanceof Damageable)
|
item.setType(originalItemNBT.getItem().getType());
|
||||||
((Damageable) meta).setDamage(((Damageable) skinMeta).getDamage());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(skinMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
|
ItemMeta meta = item.getItemMeta();
|
||||||
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) skinMeta).getColor());
|
ItemMeta originalMeta = originalItemNBT.getItem().getItemMeta();
|
||||||
|
if (originalMeta != null && meta != null) {
|
||||||
|
|
||||||
if (skinItemMMO.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
if (originalMeta.isUnbreakable()) {
|
||||||
&& skinItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
meta.setUnbreakable(true);
|
||||||
try {
|
if (meta instanceof Damageable && originalMeta instanceof Damageable)
|
||||||
Field profileField = meta.getClass().getDeclaredField("profile");
|
((Damageable) meta).setDamage(((Damageable) originalMeta).getDamage());
|
||||||
profileField.setAccessible(true);
|
}
|
||||||
profileField.set(meta,
|
|
||||||
((SkullTextureData) skinItemMMO.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
|
|
||||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
if (originalMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
|
||||||
}
|
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) originalMeta).getColor());
|
||||||
|
|
||||||
return item;
|
VolatileMMOItem originalVolatile = new VolatileMMOItem(originalItemNBT);
|
||||||
}
|
if (originalVolatile.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
||||||
|
&& originalItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||||
|
|
||||||
/**
|
try {
|
||||||
* Copies a skin from one item to another
|
Field profileField = meta.getClass().getDeclaredField("profile");
|
||||||
*
|
profileField.setAccessible(true);
|
||||||
* @param target Target item that you are copying the skin onto
|
profileField.set(meta,
|
||||||
*
|
((SkullTextureData) originalVolatile.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
|
||||||
* @param originalItemNBT Item with a skin already, as NBT. Operation will fail
|
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||||
* if it doesnt have a skin.
|
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
||||||
*
|
}
|
||||||
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
|
}
|
||||||
*
|
|
||||||
* @author Gunging
|
|
||||||
*/
|
|
||||||
@Nullable public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem originalItemNBT) {
|
|
||||||
|
|
||||||
// No skin no service
|
item.setItemMeta(meta);
|
||||||
if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) { return null; }
|
}
|
||||||
|
|
||||||
// Copy over data
|
return item;
|
||||||
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
|
}
|
||||||
target.addTag(new ItemTag(SKIN_ID_TAG, originalItemNBT.getString("MMOITEMS_ITEM_ID")));
|
|
||||||
if (originalItemNBT.getInteger("CustomModelData") != 0) {
|
|
||||||
target.addTag(new ItemTag("CustomModelData", originalItemNBT.getInteger("CustomModelData"))); }
|
|
||||||
if (!originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
|
|
||||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES"))); }
|
|
||||||
|
|
||||||
// ItemMeta values copy-over
|
public static class ApplyResult {
|
||||||
ItemStack item = target.toItem();
|
private final ResultType type;
|
||||||
if (item.getType() != originalItemNBT.getItem().getType()) { item.setType(originalItemNBT.getItem().getType()); }
|
private final ItemStack result;
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
public ApplyResult(ResultType type) {
|
||||||
ItemMeta originalMeta = originalItemNBT.getItem().getItemMeta();
|
this(null, type);
|
||||||
if (originalMeta != null && meta != null) {
|
}
|
||||||
|
|
||||||
if (originalMeta.isUnbreakable()) {
|
public ApplyResult(ItemStack result) {
|
||||||
meta.setUnbreakable(true);
|
this(result, ResultType.SUCCESS);
|
||||||
if (meta instanceof Damageable && originalMeta instanceof Damageable)
|
}
|
||||||
((Damageable) meta).setDamage(((Damageable) originalMeta).getDamage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(originalMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
|
public ApplyResult(ItemStack result, ResultType type) {
|
||||||
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) originalMeta).getColor());
|
this.type = type;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
VolatileMMOItem originalVolatile = new VolatileMMOItem(originalItemNBT);
|
public ResultType getType() {
|
||||||
if (originalVolatile.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
|
return type;
|
||||||
&& originalItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
}
|
||||||
|
|
||||||
try {
|
public ItemStack getResult() {
|
||||||
Field profileField = meta.getClass().getDeclaredField("profile");
|
return result;
|
||||||
profileField.setAccessible(true);
|
}
|
||||||
profileField.set(meta,
|
}
|
||||||
((SkullTextureData) originalVolatile.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
|
|
||||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
MMOItems.plugin.getLogger().warning("Could not read skull texture");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
public enum ResultType {
|
||||||
}
|
FAILURE, NONE, SUCCESS
|
||||||
|
}
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ApplyResult {
|
|
||||||
private final ResultType type;
|
|
||||||
private final ItemStack result;
|
|
||||||
|
|
||||||
public ApplyResult(ResultType type) {
|
|
||||||
this(null, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplyResult(ItemStack result) {
|
|
||||||
this(result, ResultType.SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplyResult(ItemStack result, ResultType type) {
|
|
||||||
this.type = type;
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResultType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ResultType {
|
|
||||||
FAILURE, NONE, SUCCESS
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ public class ArrowParticles extends BukkitRunnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
particleInfo.display(arrow.getLocation().add(0, .25, 0));
|
particleInfo.display(arrow.getLocation().add(0, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public class PlayerData {
|
|||||||
|
|
||||||
private PlayerData(@NotNull MMOPlayerData mmoData) {
|
private PlayerData(@NotNull MMOPlayerData mmoData) {
|
||||||
this.mmoData = mmoData;
|
this.mmoData = mmoData;
|
||||||
rpgPlayer = MMOItems.plugin.getRPG().getInfo(this);
|
rpgPlayer = MMOItems.plugin.getMainRPG().getInfo(this);
|
||||||
stats = new PlayerStats(this);
|
stats = new PlayerStats(this);
|
||||||
|
|
||||||
load(new ConfigFile("/userdata", getUniqueId().toString()).getConfig());
|
load(new ConfigFile("/userdata", getUniqueId().toString()).getConfig());
|
||||||
@ -305,7 +305,7 @@ public class PlayerData {
|
|||||||
stats.updateStats();
|
stats.updateStats();
|
||||||
|
|
||||||
// Update stats from external plugins
|
// Update stats from external plugins
|
||||||
MMOItems.plugin.getRPG().refreshStats(this);
|
MMOItems.plugin.getRPGs().forEach(rpg -> rpg.refreshStats(this));
|
||||||
|
|
||||||
// Actually update cached player inventory so the task doesn't infinitely loop
|
// Actually update cached player inventory so the task doesn't infinitely loop
|
||||||
inventory.helmet = getPlayer().getInventory().getHelmet();
|
inventory.helmet = getPlayer().getInventory().getHelmet();
|
||||||
@ -443,6 +443,7 @@ public class PlayerData {
|
|||||||
* Called when the corresponding MMOPlayerData has already been initialized.
|
* Called when the corresponding MMOPlayerData has already been initialized.
|
||||||
*/
|
*/
|
||||||
public static PlayerData load(@NotNull UUID player) {
|
public static PlayerData load(@NotNull UUID player) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Double check they are online, for some reason even if this is fired
|
* Double check they are online, for some reason even if this is fired
|
||||||
* from the join event the player can be offline if they left in the
|
* from the join event the player can be offline if they left in the
|
||||||
@ -460,7 +461,7 @@ public class PlayerData {
|
|||||||
* data of other rpg plugins
|
* data of other rpg plugins
|
||||||
*/
|
*/
|
||||||
PlayerData playerData = data.get(player);
|
PlayerData playerData = data.get(player);
|
||||||
playerData.rpgPlayer = MMOItems.plugin.getRPG().getInfo(playerData);
|
playerData.rpgPlayer = MMOItems.plugin.getMainRPG().getInfo(playerData);
|
||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,4 +31,8 @@ public class MoneyCondition extends Condition {
|
|||||||
public void whenCrafting(PlayerData data) {
|
public void whenCrafting(PlayerData data) {
|
||||||
MMOItems.plugin.getVault().getEconomy().withdrawPlayer(data.getPlayer(), amount);
|
MMOItems.plugin.getVault().getEconomy().withdrawPlayer(data.getPlayer(), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.Indyuce.mmoitems.comp.placeholders;
|
package net.Indyuce.mmoitems.comp.placeholders;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
|
import io.lumine.mythic.lib.UtilityMethods;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||||
import io.lumine.mythic.lib.api.util.AltChar;
|
import io.lumine.mythic.lib.api.util.AltChar;
|
||||||
@ -59,8 +60,8 @@ public class MMOItemsPlaceholders extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (identifier.startsWith("stat_")) {
|
if (identifier.startsWith("stat_")) {
|
||||||
final String stat = identifier.substring(5).toUpperCase();
|
final String stat = UtilityMethods.enumName(identifier.substring(5));
|
||||||
return StatManager.format(stat, MMOPlayerData.get(player).getStatMap().getStat(stat));
|
return StatManager.format(stat, MMOPlayerData.get(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identifier.startsWith("ability_cd_"))
|
if (identifier.startsWith("ability_cd_"))
|
||||||
|
@ -7,6 +7,7 @@ import com.archyx.aureliumskills.data.PlayerDataLoadEvent;
|
|||||||
import com.archyx.aureliumskills.skills.Skill;
|
import com.archyx.aureliumskills.skills.Skill;
|
||||||
import com.archyx.aureliumskills.skills.Skills;
|
import com.archyx.aureliumskills.skills.Skills;
|
||||||
import com.archyx.aureliumskills.stats.Stats;
|
import com.archyx.aureliumskills.stats.Stats;
|
||||||
|
import io.lumine.mythic.lib.UtilityMethods;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
@ -22,21 +23,27 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class AureliumSkillsHook implements RPGHandler, Listener {
|
public class AureliumSkillsHook implements RPGHandler, Listener {
|
||||||
private final AureliumSkills aSkills;
|
private final AureliumSkills aSkills;
|
||||||
|
|
||||||
private static final ItemStat WISDOM = new DoubleStat("WISDOM", Material.BOOK,
|
private final Map<Stats, ItemStat> statExtra = new HashMap<>();
|
||||||
"Additional Wisdom",
|
|
||||||
new String[]{"Additional wisdom (AureliumSkills)"},
|
|
||||||
new String[]{"!miscellaneous", "!block", "all"});
|
|
||||||
|
|
||||||
public AureliumSkillsHook() {
|
public AureliumSkillsHook() {
|
||||||
aSkills = (AureliumSkills) Bukkit.getPluginManager().getPlugin("AureliumSkills");
|
aSkills = (AureliumSkills) Bukkit.getPluginManager().getPlugin("AureliumSkills");
|
||||||
|
|
||||||
// Register wisdom for the max mana stat
|
for (Stats stat : Stats.values()) {
|
||||||
MMOItems.plugin.getStats().register(WISDOM);
|
final String statName = UtilityMethods.caseOnWords(stat.name().toLowerCase());
|
||||||
|
final ItemStat miStat = new DoubleStat(stat.name(), Material.BOOK,
|
||||||
|
"Additional " + statName,
|
||||||
|
new String[]{"Additional " + statName + " (AureliumSkills)"},
|
||||||
|
new String[]{"!miscellaneous", "!block", "all"});
|
||||||
|
|
||||||
|
MMOItems.plugin.getStats().register(miStat);
|
||||||
|
}
|
||||||
|
|
||||||
// Register stat for required professions
|
// Register stat for required professions
|
||||||
for (Skills skill : Skills.values())
|
for (Skills skill : Skills.values())
|
||||||
@ -50,9 +57,11 @@ public class AureliumSkillsHook implements RPGHandler, Listener {
|
|||||||
PlayerData.get(player).getInventory().scheduleUpdate();
|
PlayerData.get(player).getInventory().scheduleUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String MODIFIER_KEY = "mmoitems";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshStats(PlayerData data) {
|
public void refreshStats(PlayerData data) {
|
||||||
AureliumAPI.addStatModifier(data.getPlayer(), "mmoitems", Stats.WISDOM, data.getStats().getStat(WISDOM));
|
statExtra.forEach((stat, miStat) -> AureliumAPI.addStatModifier(data.getPlayer(), MODIFIER_KEY, stat, data.getStats().getStat(miStat)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,60 +2,18 @@ package net.Indyuce.mmoitems.comp.rpg;
|
|||||||
|
|
||||||
import com.sucy.skill.SkillAPI;
|
import com.sucy.skill.SkillAPI;
|
||||||
import com.sucy.skill.api.event.PlayerLevelUpEvent;
|
import com.sucy.skill.api.event.PlayerLevelUpEvent;
|
||||||
import com.sucy.skill.api.event.SkillDamageEvent;
|
|
||||||
import com.sucy.skill.api.player.PlayerData;
|
import com.sucy.skill.api.player.PlayerData;
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
|
||||||
import io.lumine.mythic.lib.api.player.EquipmentSlot;
|
|
||||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
|
||||||
import io.lumine.mythic.lib.damage.AttackHandler;
|
|
||||||
import io.lumine.mythic.lib.damage.AttackMetadata;
|
|
||||||
import io.lumine.mythic.lib.damage.DamageMetadata;
|
|
||||||
import io.lumine.mythic.lib.damage.DamageType;
|
|
||||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
public class ProSkillAPIHook implements RPGHandler, Listener {
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ProSkillAPIHook implements RPGHandler, Listener, AttackHandler {
|
|
||||||
private final Map<Integer, AttackMetadata> damageInfo = new HashMap<>();
|
|
||||||
|
|
||||||
public ProSkillAPIHook() {
|
|
||||||
MythicLib.plugin.getDamage().registerHandler(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RPGPlayer getInfo(net.Indyuce.mmoitems.api.player.PlayerData data) {
|
public RPGPlayer getInfo(net.Indyuce.mmoitems.api.player.PlayerData data) {
|
||||||
return new SkillAPIPlayer(data);
|
return new SkillAPIPlayer(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public AttackMetadata getAttack(EntityDamageEvent event) {
|
|
||||||
return damageInfo.get(event.getEntity().getEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void a(SkillDamageEvent event) {
|
|
||||||
if (!(event.getDamager() instanceof Player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL);
|
|
||||||
AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND));
|
|
||||||
damageInfo.put(event.getTarget().getEntityId(), attackMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void c(EntityDamageByEntityEvent event) {
|
|
||||||
damageInfo.remove(event.getEntity().getEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void b(PlayerLevelUpEvent event) {
|
public void b(PlayerLevelUpEvent event) {
|
||||||
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate();
|
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate();
|
||||||
|
@ -2,60 +2,18 @@ package net.Indyuce.mmoitems.comp.rpg;
|
|||||||
|
|
||||||
import com.sucy.skill.SkillAPI;
|
import com.sucy.skill.SkillAPI;
|
||||||
import com.sucy.skill.api.event.PlayerLevelUpEvent;
|
import com.sucy.skill.api.event.PlayerLevelUpEvent;
|
||||||
import com.sucy.skill.api.event.SkillDamageEvent;
|
|
||||||
import com.sucy.skill.api.player.PlayerData;
|
import com.sucy.skill.api.player.PlayerData;
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
|
||||||
import io.lumine.mythic.lib.api.player.EquipmentSlot;
|
|
||||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
|
||||||
import io.lumine.mythic.lib.damage.AttackHandler;
|
|
||||||
import io.lumine.mythic.lib.damage.AttackMetadata;
|
|
||||||
import io.lumine.mythic.lib.damage.DamageMetadata;
|
|
||||||
import io.lumine.mythic.lib.damage.DamageType;
|
|
||||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
public class SkillAPIHook implements RPGHandler, Listener {
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SkillAPIHook implements RPGHandler, Listener, AttackHandler {
|
|
||||||
private final Map<Integer, AttackMetadata> damageInfo = new HashMap<>();
|
|
||||||
|
|
||||||
public SkillAPIHook() {
|
|
||||||
MythicLib.plugin.getDamage().registerHandler(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RPGPlayer getInfo(net.Indyuce.mmoitems.api.player.PlayerData data) {
|
public RPGPlayer getInfo(net.Indyuce.mmoitems.api.player.PlayerData data) {
|
||||||
return new SkillAPIPlayer(data);
|
return new SkillAPIPlayer(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public AttackMetadata getAttack(EntityDamageEvent event) {
|
|
||||||
return damageInfo.get(event.getEntity().getEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void a(SkillDamageEvent event) {
|
|
||||||
if (!(event.getDamager() instanceof Player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL);
|
|
||||||
AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND));
|
|
||||||
damageInfo.put(event.getTarget().getEntityId(), attackMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void c(EntityDamageByEntityEvent event) {
|
|
||||||
damageInfo.remove(event.getEntity().getEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void b(PlayerLevelUpEvent event) {
|
public void b(PlayerLevelUpEvent event) {
|
||||||
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate();
|
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate();
|
||||||
|
@ -16,6 +16,7 @@ import net.Indyuce.mmoitems.api.crafting.recipe.Recipe;
|
|||||||
import net.Indyuce.mmoitems.api.event.PlayerUseCraftingStationEvent;
|
import net.Indyuce.mmoitems.api.event.PlayerUseCraftingStationEvent;
|
||||||
import net.Indyuce.mmoitems.api.item.util.ConfigItems;
|
import net.Indyuce.mmoitems.api.item.util.ConfigItems;
|
||||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||||
|
import net.Indyuce.mmoitems.comp.eco.MoneyCondition;
|
||||||
import net.Indyuce.mmoitems.listener.CustomSoundListener;
|
import net.Indyuce.mmoitems.listener.CustomSoundListener;
|
||||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -221,6 +222,13 @@ public class CraftingStationView extends PluginInventory {
|
|||||||
// Give ingredients back
|
// Give ingredients back
|
||||||
for (Ingredient ingredient : recipeInfo.getRecipe().getIngredients())
|
for (Ingredient ingredient : recipeInfo.getRecipe().getIngredients())
|
||||||
new SmartGive(player).give(ingredient.generateItemStack(playerData.getRPG()));
|
new SmartGive(player).give(ingredient.generateItemStack(playerData.getRPG()));
|
||||||
|
|
||||||
|
// Give money back
|
||||||
|
recipe.getConditions()
|
||||||
|
.stream()
|
||||||
|
.filter(condition -> condition instanceof MoneyCondition)
|
||||||
|
.map(condition -> (MoneyCondition) condition)
|
||||||
|
.forEach(condition -> MMOItems.plugin.getVault().getEconomy().depositPlayer(player, condition.getAmount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateData();
|
updateData();
|
||||||
|
@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.api.ConfigFile;
|
|||||||
import net.Indyuce.mmoitems.api.Type;
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
import net.Indyuce.mmoitems.stat.type.*;
|
import net.Indyuce.mmoitems.stat.type.*;
|
||||||
import net.Indyuce.mmoitems.util.ElementStatType;
|
import net.Indyuce.mmoitems.util.ElementStatType;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -3,7 +3,10 @@ package net.Indyuce.mmoitems.stat;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||||
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
||||||
|
import io.lumine.mythic.lib.api.util.AltChar;
|
||||||
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmoitems.ItemStats;
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.edition.StatEdition;
|
import net.Indyuce.mmoitems.api.edition.StatEdition;
|
||||||
@ -11,12 +14,8 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
|||||||
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
|
||||||
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||||
import net.Indyuce.mmoitems.stat.data.StringListData;
|
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.data.type.StatData;
|
||||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
|
||||||
import io.lumine.mythic.lib.api.util.AltChar;
|
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
@ -29,138 +28,130 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class CompatibleIds extends ItemStat<StringListData, StringListData> {
|
public class CompatibleIds extends ItemStat<StringListData, StringListData> {
|
||||||
public CompatibleIds() {
|
public CompatibleIds() {
|
||||||
super("COMPATIBLE_IDS", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible IDs",
|
super("COMPATIBLE_IDS", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible IDs",
|
||||||
new String[] { "The item ids this skin is", "compatible with." }, new String[] { "skin" });
|
new String[]{"The item ids this skin is", "compatible with."}, new String[]{"skin"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public StringListData whenInitialized(Object object) {
|
public StringListData whenInitialized(Object object) {
|
||||||
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
|
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
|
||||||
return new StringListData((List<String>) object);
|
return new StringListData((List<String>) object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||||
new StatEdition(inv, ItemStats.COMPATIBLE_IDS).enable("Write in the chat the item id you want to add.");
|
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 (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-ids"))
|
||||||
if (inv.getEditedSection().contains("compatible-ids")) {
|
return;
|
||||||
List<String> lore = inv.getEditedSection().getStringList("compatible-ids");
|
List<String> lore = inv.getEditedSection().getStringList("compatible-ids");
|
||||||
if (lore.size() < 1)
|
if (lore.size() < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String last = lore.get(lore.size() - 1);
|
String last = lore.get(lore.size() - 1);
|
||||||
lore.remove(last);
|
lore.remove(last);
|
||||||
inv.getEditedSection().set("compatible-ids", lore);
|
inv.getEditedSection().set("compatible-ids", lore);
|
||||||
inv.registerTemplateEdition();
|
inv.registerTemplateEdition();
|
||||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
|
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||||
List<String> lore = inv.getEditedSection().contains("compatible-ids") ? inv.getEditedSection().getStringList("compatible-ids")
|
List<String> lore = inv.getEditedSection().contains("compatible-ids") ? inv.getEditedSection().getStringList("compatible-ids")
|
||||||
: new ArrayList<>();
|
: new ArrayList<>();
|
||||||
lore.add(message.toUpperCase());
|
lore.add(message.toUpperCase());
|
||||||
inv.getEditedSection().set("compatible-ids", lore);
|
inv.getEditedSection().set("compatible-ids", lore);
|
||||||
inv.registerTemplateEdition();
|
inv.registerTemplateEdition();
|
||||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible IDs successfully added.");
|
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible IDs successfully added.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
|
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
|
||||||
|
if (statData.isPresent()) {
|
||||||
|
lore.add(ChatColor.GRAY + "Current Value:");
|
||||||
|
statData.get().getList().forEach(str -> lore.add(ChatColor.GRAY + str));
|
||||||
|
} else
|
||||||
|
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
|
||||||
|
|
||||||
if (statData.isPresent()) {
|
lore.add("");
|
||||||
lore.add(ChatColor.GRAY + "Current Value:");
|
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new id.");
|
||||||
((StringListData) statData.get()).getList().forEach(str -> lore.add(ChatColor.GRAY + str));
|
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last id.");
|
||||||
|
}
|
||||||
|
|
||||||
} else
|
@NotNull
|
||||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
|
@Override
|
||||||
|
public StringListData getClearStatData() {
|
||||||
|
return new StringListData();
|
||||||
|
}
|
||||||
|
|
||||||
lore.add("");
|
@Override
|
||||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new id.");
|
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
|
||||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last id.");
|
// Copy Array, for lore
|
||||||
}
|
List<String> compatibleIds = new ArrayList<>(data.getList());
|
||||||
|
item.getLore().insert("compatible-ids", compatibleIds);
|
||||||
|
|
||||||
@NotNull
|
// Add data
|
||||||
@Override
|
item.addItemTag(getAppliedNBT(data));
|
||||||
public StringListData getClearStatData() {
|
}
|
||||||
return new StringListData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@NotNull
|
||||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
|
@Override
|
||||||
|
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
|
||||||
|
// Build Json Array
|
||||||
|
JsonArray array = new JsonArray();
|
||||||
|
|
||||||
// Copy Array, for lore
|
// For each string in the ids of the data
|
||||||
List<String> compatibleIds = new ArrayList<>(data.getList());
|
for (String sts : data.getList()) {
|
||||||
item.getLore().insert("compatible-ids", compatibleIds);
|
array.add(sts);
|
||||||
|
}
|
||||||
|
|
||||||
// Add data
|
// Make returning array
|
||||||
item.addItemTag(getAppliedNBT(data));
|
ArrayList<ItemTag> tags = new ArrayList<>();
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
// Add Json Array
|
||||||
@Override
|
tags.add(new ItemTag(getNBTPath(), array.toString()));
|
||||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
|
|
||||||
|
|
||||||
// Build Json Array
|
return tags;
|
||||||
JsonArray array = new JsonArray();
|
}
|
||||||
|
|
||||||
// For each string in the ids of the data
|
@Override
|
||||||
for (String sts : data.getList()) { array.add(sts); }
|
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||||
|
// FInd relvant tags
|
||||||
|
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||||
|
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||||
|
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||||
|
|
||||||
// Make returning array
|
// Generate data
|
||||||
ArrayList<ItemTag> tags = new ArrayList<>();
|
StatData data = getLoadedNBT(relevantTags);
|
||||||
|
|
||||||
// Add Json Array
|
if (data != null)
|
||||||
tags.add(new ItemTag(getNBTPath(), array.toString()));
|
mmoitem.setData(this, data);
|
||||||
|
}
|
||||||
|
|
||||||
return tags;
|
@Nullable
|
||||||
}
|
@Override
|
||||||
|
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||||
|
// Find relevant tag
|
||||||
|
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||||
|
|
||||||
@Override
|
// Found?
|
||||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
if (rTag == null)
|
||||||
|
// Nope
|
||||||
|
return null;
|
||||||
|
|
||||||
// FInd relvant tags
|
try {
|
||||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
// Parse onto Json Array
|
||||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
|
||||||
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
// Make and return list
|
||||||
|
return new StringListData(array);
|
||||||
// Generate data
|
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||||
StatData data = getLoadedNBT(relevantTags);
|
/*
|
||||||
|
* OLD ITEM WHICH MUST BE UPDATED.
|
||||||
if (data != null) { mmoitem.setData(this, data);}
|
*/
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
@Nullable
|
}
|
||||||
@Override
|
|
||||||
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
|
||||||
|
|
||||||
// Find relevant tag
|
|
||||||
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
|
||||||
|
|
||||||
// Found?
|
|
||||||
if (rTag != null) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Parse onto Json Array
|
|
||||||
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
|
|
||||||
|
|
||||||
// Make and return list
|
|
||||||
return new StringListData(array);
|
|
||||||
|
|
||||||
} catch (JsonSyntaxException |IllegalStateException exception) {
|
|
||||||
/*
|
|
||||||
* OLD ITEM WHICH MUST BE UPDATED.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nope
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,169 @@
|
|||||||
|
package net.Indyuce.mmoitems.stat;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||||
|
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
||||||
|
import io.lumine.mythic.lib.api.util.AltChar;
|
||||||
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
|
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.type.StatData;
|
||||||
|
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class CompatibleMaterials extends ItemStat<StringListData, StringListData> {
|
||||||
|
|
||||||
|
public CompatibleMaterials() {
|
||||||
|
super("COMPATIBLE_MATERIALS", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible Materials",
|
||||||
|
new String[]{"The item materials 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(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||||
|
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||||
|
new StatEdition(inv, ItemStats.COMPATIBLE_MATERIALS).enable("Write in the chat the name of the material you want to add.");
|
||||||
|
|
||||||
|
if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-materials"))
|
||||||
|
return;
|
||||||
|
List<String> lore = inv.getEditedSection().getStringList("compatible-materials");
|
||||||
|
if (lore.size() < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String last = lore.get(lore.size() - 1);
|
||||||
|
lore.remove(last);
|
||||||
|
inv.getEditedSection().set("compatible-materials", lore);
|
||||||
|
inv.registerTemplateEdition();
|
||||||
|
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||||
|
final Player player = inv.getPlayer();
|
||||||
|
// Check if material exists
|
||||||
|
if (Arrays.stream(Material.values()).noneMatch(versionMaterial -> versionMaterial.name().equalsIgnoreCase(message))) {
|
||||||
|
player.sendMessage(MMOItems.plugin.getPrefix() + "Invalid material name.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> lore = inv.getEditedSection().contains("compatible-materials") ? inv.getEditedSection().getStringList("compatible-materials")
|
||||||
|
: new ArrayList<>();
|
||||||
|
lore.add(message.toUpperCase());
|
||||||
|
inv.getEditedSection().set("compatible-materials", lore);
|
||||||
|
inv.registerTemplateEdition();
|
||||||
|
player.sendMessage(MMOItems.plugin.getPrefix() + "Compatible Materials successfully added.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
|
||||||
|
if (statData.isPresent()) {
|
||||||
|
lore.add(ChatColor.GRAY + "Current Value:");
|
||||||
|
statData.get().getList().forEach(str -> lore.add(ChatColor.GRAY + str));
|
||||||
|
} else
|
||||||
|
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any material.");
|
||||||
|
|
||||||
|
lore.add("");
|
||||||
|
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new material.");
|
||||||
|
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last material.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public StringListData getClearStatData() {
|
||||||
|
return new StringListData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
|
||||||
|
// Copy Array, for lore
|
||||||
|
List<String> compatibleMaterials = new ArrayList<>(data.getList());
|
||||||
|
item.getLore().insert("compatible-materials", compatibleMaterials);
|
||||||
|
|
||||||
|
// Add data
|
||||||
|
item.addItemTag(getAppliedNBT(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
|
||||||
|
// Build Json Array
|
||||||
|
JsonArray array = new JsonArray();
|
||||||
|
|
||||||
|
// For each string in the ids of the data
|
||||||
|
for (String sts : data.getList()) {
|
||||||
|
array.add(sts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make returning array
|
||||||
|
ArrayList<ItemTag> tags = new ArrayList<>();
|
||||||
|
|
||||||
|
// Add Json Array
|
||||||
|
tags.add(new ItemTag(getNBTPath(), array.toString()));
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||||
|
// FInd relevant tags
|
||||||
|
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||||
|
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||||
|
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||||
|
|
||||||
|
// Generate data
|
||||||
|
StatData data = getLoadedNBT(relevantTags);
|
||||||
|
|
||||||
|
if (data != null)
|
||||||
|
mmoitem.setData(this, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||||
|
// Find relevant tag
|
||||||
|
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||||
|
|
||||||
|
// Found?
|
||||||
|
if (rTag == null)
|
||||||
|
// Nope
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Parse onto Json Array
|
||||||
|
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
|
||||||
|
|
||||||
|
// Make and return list
|
||||||
|
return new StringListData(array);
|
||||||
|
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||||
|
/*
|
||||||
|
* OLD ITEM WHICH MUST BE UPDATED.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,12 @@
|
|||||||
package net.Indyuce.mmoitems.stat;
|
package net.Indyuce.mmoitems.stat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||||
|
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
||||||
|
import io.lumine.mythic.lib.api.util.AltChar;
|
||||||
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmoitems.ItemStats;
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.edition.StatEdition;
|
import net.Indyuce.mmoitems.api.edition.StatEdition;
|
||||||
@ -21,149 +14,145 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
|||||||
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
|
||||||
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||||
import net.Indyuce.mmoitems.stat.data.StringListData;
|
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.data.type.StatData;
|
||||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
import org.apache.commons.lang.Validate;
|
||||||
import io.lumine.mythic.lib.api.util.AltChar;
|
import org.bukkit.ChatColor;
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class CompatibleTypes extends ItemStat<StringListData, StringListData> {
|
public class CompatibleTypes extends ItemStat<StringListData, StringListData> {
|
||||||
public CompatibleTypes() {
|
public CompatibleTypes() {
|
||||||
super("COMPATIBLE_TYPES", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible Types",
|
super("COMPATIBLE_TYPES", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible Types",
|
||||||
new String[] { "The item types this skin is", "compatible with." }, new String[] { "skin" });
|
new String[]{"The item types this skin is", "compatible with."}, new String[]{"skin"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public StringListData whenInitialized(Object object) {
|
public StringListData whenInitialized(Object object) {
|
||||||
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
|
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
|
||||||
return new StringListData((List<String>) object);
|
return new StringListData((List<String>) object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||||
new StatEdition(inv, ItemStats.COMPATIBLE_TYPES).enable("Write in the chat the name of the type you want to add.");
|
new StatEdition(inv, ItemStats.COMPATIBLE_TYPES).enable("Write in the chat the name of the type you want to add.");
|
||||||
|
|
||||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-types"))
|
||||||
if (inv.getEditedSection().contains("compatible-types")) {
|
return;
|
||||||
List<String> lore = inv.getEditedSection().getStringList("compatible-types");
|
List<String> lore = inv.getEditedSection().getStringList("compatible-types");
|
||||||
if (lore.size() < 1)
|
if (lore.size() < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String last = lore.get(lore.size() - 1);
|
String last = lore.get(lore.size() - 1);
|
||||||
lore.remove(last);
|
lore.remove(last);
|
||||||
inv.getEditedSection().set("compatible-types", lore);
|
inv.getEditedSection().set("compatible-types", lore);
|
||||||
inv.registerTemplateEdition();
|
inv.registerTemplateEdition();
|
||||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
|
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||||
List<String> lore = inv.getEditedSection().contains("compatible-types") ? inv.getEditedSection().getStringList("compatible-types")
|
List<String> lore = inv.getEditedSection().contains("compatible-types") ? inv.getEditedSection().getStringList("compatible-types")
|
||||||
: new ArrayList<>();
|
: new ArrayList<>();
|
||||||
lore.add(message.toUpperCase());
|
lore.add(message.toUpperCase());
|
||||||
inv.getEditedSection().set("compatible-types", lore);
|
inv.getEditedSection().set("compatible-types", lore);
|
||||||
inv.registerTemplateEdition();
|
inv.registerTemplateEdition();
|
||||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible Types successfully added.");
|
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible Types successfully added.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
|
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
|
||||||
|
if (statData.isPresent()) {
|
||||||
|
lore.add(ChatColor.GRAY + "Current Value:");
|
||||||
|
statData.get().getList().forEach(str -> lore.add(ChatColor.GRAY + str));
|
||||||
|
} else
|
||||||
|
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
|
||||||
|
|
||||||
if (statData.isPresent()) {
|
lore.add("");
|
||||||
lore.add(ChatColor.GRAY + "Current Value:");
|
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new type.");
|
||||||
((StringListData) statData.get()).getList().forEach(str -> lore.add(ChatColor.GRAY + str));
|
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last type.");
|
||||||
|
}
|
||||||
|
|
||||||
} else
|
@NotNull
|
||||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
|
@Override
|
||||||
|
public StringListData getClearStatData() {
|
||||||
|
return new StringListData();
|
||||||
|
}
|
||||||
|
|
||||||
lore.add("");
|
@Override
|
||||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new type.");
|
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
|
||||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last type.");
|
// Copy Array, for lore
|
||||||
}
|
List<String> compatibleTypes = new ArrayList<>(data.getList());
|
||||||
|
item.getLore().insert("compatible-types", compatibleTypes);
|
||||||
|
|
||||||
@NotNull
|
// Add data
|
||||||
@Override
|
item.addItemTag(getAppliedNBT(data));
|
||||||
public StringListData getClearStatData() {
|
}
|
||||||
return new StringListData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@NotNull
|
||||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
|
@Override
|
||||||
|
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
|
||||||
|
// Build Json Array
|
||||||
|
JsonArray array = new JsonArray();
|
||||||
|
|
||||||
// Copy Array, for lore
|
// For each string in the ids of the data
|
||||||
List<String> compatibleTypes = new ArrayList<>(((StringListData) data).getList());
|
for (String sts : data.getList()) {
|
||||||
item.getLore().insert("compatible-types", compatibleTypes);
|
array.add(sts);
|
||||||
|
}
|
||||||
|
|
||||||
// Add data
|
// Make returning array
|
||||||
item.addItemTag(getAppliedNBT(data));
|
ArrayList<ItemTag> tags = new ArrayList<>();
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
// Add Json Array
|
||||||
@Override
|
tags.add(new ItemTag(getNBTPath(), array.toString()));
|
||||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
|
|
||||||
|
|
||||||
// Build Json Array
|
return tags;
|
||||||
JsonArray array = new JsonArray();
|
}
|
||||||
|
|
||||||
// For each string in the ids of the data
|
@Override
|
||||||
for (String sts : ((StringListData) data).getList()) { array.add(sts); }
|
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||||
|
// FInd relevant tags
|
||||||
|
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||||
|
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||||
|
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||||
|
|
||||||
// Make returning array
|
// Generate data
|
||||||
ArrayList<ItemTag> tags = new ArrayList<>();
|
StatData data = getLoadedNBT(relevantTags);
|
||||||
|
|
||||||
// Add Json Array
|
if (data != null)
|
||||||
tags.add(new ItemTag(getNBTPath(), array.toString()));
|
mmoitem.setData(this, data);
|
||||||
|
}
|
||||||
|
|
||||||
return tags;
|
@Nullable
|
||||||
}
|
@Override
|
||||||
|
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||||
|
// Find relevant tag
|
||||||
|
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||||
|
|
||||||
@Override
|
// Found?
|
||||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
if (rTag == null)
|
||||||
|
// Nope
|
||||||
|
return null;
|
||||||
|
|
||||||
// FInd relvant tags
|
try {
|
||||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
// Parse onto Json Array
|
||||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
|
||||||
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
|
||||||
|
|
||||||
// Generate data
|
// Make and return list
|
||||||
StatData data = getLoadedNBT(relevantTags);
|
return new StringListData(array);
|
||||||
|
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||||
if (data != null) { mmoitem.setData(this, data);}
|
/*
|
||||||
}
|
* OLD ITEM WHICH MUST BE UPDATED.
|
||||||
|
*/
|
||||||
@Nullable
|
}
|
||||||
@Override
|
return null;
|
||||||
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
}
|
||||||
|
|
||||||
// Find relevant tag
|
|
||||||
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
|
||||||
|
|
||||||
// Found?
|
|
||||||
if (rTag != null) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// Parse onto Json Array
|
|
||||||
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
|
|
||||||
|
|
||||||
// Make and return list
|
|
||||||
return new StringListData(array);
|
|
||||||
|
|
||||||
} catch (JsonSyntaxException |IllegalStateException exception) {
|
|
||||||
/*
|
|
||||||
* OLD ITEM WHICH MUST BE UPDATED.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nope
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ import org.bukkit.Material;
|
|||||||
|
|
||||||
public class RepairReference extends StringStat implements GemStoneStat {
|
public class RepairReference extends StringStat implements GemStoneStat {
|
||||||
public RepairReference() {
|
public RepairReference() {
|
||||||
super("REPAIR_TYPE", Material.ANVIL, "Repair Reference", new String[]{"If items have a repair type they can", "only be repaired by consumables", "with the same repair type.", "(And vice-versa)"}, new String[]{"all"});
|
super("REPAIR_TYPE", Material.ANVIL, "Repair Reference", new String[]{"If items have a repair reference, they can", "only be repaired by consumables", "with the same repair reference,", "and vice-versa."}, new String[]{"all"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,12 +61,11 @@ public class MMOUtils {
|
|||||||
* They are a piece of text stored as an NBTTag for instance. Items can
|
* They are a piece of text stored as an NBTTag for instance. Items can
|
||||||
* interact (in a certain way) only if the corresponding reference match.
|
* interact (in a certain way) only if the corresponding reference match.
|
||||||
* <p>
|
* <p>
|
||||||
* A null reference is considered just like a non-null reference.
|
* Any item can interact with an item with the universal reference 'all'.
|
||||||
* Any item can interact with an item with the universal reference 'all'
|
* A null/empty reference is considered like the universal reference.
|
||||||
* <p>
|
* <p>
|
||||||
* TODO
|
|
||||||
* This is a simple symmetrical computation. Used for:
|
* This is a simple symmetrical computation. Used for:
|
||||||
* - for item upgrading
|
* - for item upgrading TODO
|
||||||
* - item repairing
|
* - item repairing
|
||||||
*
|
*
|
||||||
* @param ref1 First reference
|
* @param ref1 First reference
|
||||||
@ -74,11 +73,7 @@ public class MMOUtils {
|
|||||||
* @return If items can interact
|
* @return If items can interact
|
||||||
*/
|
*/
|
||||||
public static boolean checkReference(@Nullable String ref1, @Nullable String ref2) {
|
public static boolean checkReference(@Nullable String ref1, @Nullable String ref2) {
|
||||||
if (ref1 == null)
|
return ref1 == null || ref1.isEmpty() || ref2 == null || ref2.isEmpty() || ref1.equals(UNIVERSAL_REFERENCE) || ref2.equals(UNIVERSAL_REFERENCE) || ref1.equals(ref2);
|
||||||
return ref2 == null || ref2.equals(UNIVERSAL_REFERENCE);
|
|
||||||
if (ref2 == null)
|
|
||||||
return ref1 == null || ref1.equals(UNIVERSAL_REFERENCE);
|
|
||||||
return ref1.equals(UNIVERSAL_REFERENCE) || ref2.equals(UNIVERSAL_REFERENCE) || ref1.equals(ref2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,23 @@ iterate-whole-inventory: false
|
|||||||
# When this is set to true, skins can only be applied to an item ONCE.
|
# When this is set to true, skins can only be applied to an item ONCE.
|
||||||
locked-skins: true
|
locked-skins: true
|
||||||
|
|
||||||
|
# Since 6.9.3 dev builds, MMOItems supports the use of multiple
|
||||||
|
# RPG core plugins at the same time. However, MMOItems needs one
|
||||||
|
# specific plugin to hook onto level, class, etc.
|
||||||
|
#
|
||||||
|
# Available plugins:
|
||||||
|
# - MMOCORE (level, class, mana, stamina)
|
||||||
|
# - HEROES (level, class, mana, stamina)
|
||||||
|
# - SKILLAPI or PROSKILLAPI (level, class, mana)
|
||||||
|
# - RPGPLAYERLEVELING (level, mana, power)
|
||||||
|
# - RACESANDCLASSES (level, class, mana)
|
||||||
|
# - BATTLELEVELS (level)
|
||||||
|
# - MCMMO (power level)
|
||||||
|
# - MCRPG (power level)
|
||||||
|
# - SKILLS or SKILLSPRO (class, level, mana)
|
||||||
|
# - AURELIUM_SKILLS (power level, mana)
|
||||||
|
preferred-rpg-provider: MMOCORE
|
||||||
|
|
||||||
# By default, all player inventories will be updated every
|
# By default, all player inventories will be updated every
|
||||||
# 10 ticks which corresponds to 2 inventory updates a second.
|
# 10 ticks which corresponds to 2 inventory updates a second.
|
||||||
inventory-update-delay: 10
|
inventory-update-delay: 10
|
||||||
@ -103,11 +120,11 @@ soulbound:
|
|||||||
damage:
|
damage:
|
||||||
base: 1
|
base: 1
|
||||||
per-lvl: 1
|
per-lvl: 1
|
||||||
|
|
||||||
# Whether or not soulbound items should be
|
# Whether or not soulbound items should be
|
||||||
# kept when a player dies.
|
# kept when a player dies.
|
||||||
keep-on-death: true
|
keep-on-death: true
|
||||||
|
|
||||||
# Whether or not soulbound item can be
|
# Whether or not soulbound item can be
|
||||||
# dropped by the player
|
# dropped by the player
|
||||||
can-drop: true
|
can-drop: true
|
||||||
@ -194,7 +211,7 @@ action-bar-display:
|
|||||||
item-break: false
|
item-break: false
|
||||||
|
|
||||||
recipes:
|
recipes:
|
||||||
|
|
||||||
# Enables the vanilla recipe book for MMOItems recipes
|
# Enables the vanilla recipe book for MMOItems recipes
|
||||||
use-recipe-book: true
|
use-recipe-book: true
|
||||||
|
|
||||||
@ -381,6 +398,3 @@ gem-upgrade-default: 'NEVER'
|
|||||||
# This option allows you to disable the ability to
|
# This option allows you to disable the ability to
|
||||||
# use MMOItems that have been removed from your config.
|
# use MMOItems that have been removed from your config.
|
||||||
disable-removed-items: true
|
disable-removed-items: true
|
||||||
|
|
||||||
# When I was a kid, I saw the Mona Lisa in my school art book...
|
|
||||||
# The fist time I saw her, with her hands on her knee... how do I say this...
|
|
Loading…
Reference in New Issue
Block a user