1.13 update
Mostly remove item things that was useful for some internal MassiveCraft plugins but wont be for Factions.
This commit is contained in:
parent
ec5a87a338
commit
810c639e56
@ -5,6 +5,7 @@ website: ${project.url}
|
||||
description: ${project.description}
|
||||
authors: [Cayorion]
|
||||
load: startup
|
||||
api-version: 1.13
|
||||
permissions:
|
||||
# -------------------------------------------- #
|
||||
# THE REAL NODES
|
||||
|
@ -6,13 +6,9 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.massivecraft.massivecore.adapter.AdapterBackstringSet;
|
||||
import com.massivecraft.massivecore.adapter.AdapterBannerPatterns;
|
||||
import com.massivecraft.massivecore.adapter.AdapterEntityInternalMap;
|
||||
import com.massivecraft.massivecore.adapter.AdapterEntry;
|
||||
import com.massivecraft.massivecore.adapter.AdapterInventory;
|
||||
import com.massivecraft.massivecore.adapter.AdapterItemStack;
|
||||
import com.massivecraft.massivecore.adapter.AdapterJsonElement;
|
||||
import com.massivecraft.massivecore.adapter.AdapterMassiveList;
|
||||
import com.massivecraft.massivecore.adapter.AdapterMassiveMap;
|
||||
@ -22,7 +18,6 @@ import com.massivecraft.massivecore.adapter.AdapterMassiveTreeSet;
|
||||
import com.massivecraft.massivecore.adapter.AdapterModdedEnumType;
|
||||
import com.massivecraft.massivecore.adapter.AdapterMson;
|
||||
import com.massivecraft.massivecore.adapter.AdapterMsonEvent;
|
||||
import com.massivecraft.massivecore.adapter.AdapterPlayerInventory;
|
||||
import com.massivecraft.massivecore.adapter.AdapterSound;
|
||||
import com.massivecraft.massivecore.adapter.AdapterUUID;
|
||||
import com.massivecraft.massivecore.collections.BackstringSet;
|
||||
@ -37,21 +32,16 @@ import com.massivecraft.massivecore.collections.MassiveTreeMapDef;
|
||||
import com.massivecraft.massivecore.collections.MassiveTreeSet;
|
||||
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
|
||||
import com.massivecraft.massivecore.command.type.RegistryType;
|
||||
import com.massivecraft.massivecore.item.DataBannerPattern;
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
import com.massivecraft.massivecore.item.WriterItemStack;
|
||||
import com.massivecraft.massivecore.mixin.MixinEvent;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.mson.MsonEvent;
|
||||
import com.massivecraft.massivecore.nms.NmsBasics;
|
||||
import com.massivecraft.massivecore.nms.NmsItemStackCreate17R4P;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.ps.PSAdapter;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.EntityInternalMap;
|
||||
import com.massivecraft.massivecore.store.ModificationPollerLocal;
|
||||
import com.massivecraft.massivecore.store.ModificationPollerRemote;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorUtil;
|
||||
import com.massivecraft.massivecore.util.BoardUtil;
|
||||
import com.massivecraft.massivecore.util.ContainerUtil;
|
||||
import com.massivecraft.massivecore.util.EventUtil;
|
||||
@ -70,12 +60,8 @@ import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
@ -156,20 +142,6 @@ public class MassiveCore extends MassivePlugin
|
||||
ret.registerTypeAdapter(Mson.class, AdapterMson.get());
|
||||
ret.registerTypeAdapter(MsonEvent.class, AdapterMsonEvent.get());
|
||||
|
||||
// Banner Patterns Upgrade Adapter
|
||||
// NOTE: Must come after the "MassiveContainers" section for priority.
|
||||
Type typeBannerPatterns = new TypeToken<MassiveListDef<DataBannerPattern>>(){}.getType();
|
||||
ret.registerTypeAdapter(typeBannerPatterns, AdapterBannerPatterns.get());
|
||||
|
||||
// ItemStack
|
||||
ret.registerTypeAdapter(ItemStack.class, AdapterItemStack.get());
|
||||
Class<?> classCraftItemStack = NmsItemStackCreate17R4P.getClassCraftItemStackCatch();
|
||||
if (classCraftItemStack != null) ret.registerTypeAdapter(classCraftItemStack, AdapterItemStack.get());
|
||||
|
||||
// Inventory
|
||||
ret.registerTypeAdapter(Inventory.class, AdapterInventory.get());
|
||||
ret.registerTypeAdapter(PlayerInventory.class, AdapterPlayerInventory.get());
|
||||
|
||||
// Storage
|
||||
ret.registerTypeAdapter(EntityInternalMap.class, AdapterEntityInternalMap.get());
|
||||
|
||||
@ -233,19 +205,12 @@ public class MassiveCore extends MassivePlugin
|
||||
// Setup RegistryType
|
||||
RegistryType.registerAll();
|
||||
|
||||
MigratorUtil.addJsonRepresentation(ItemStack.class, DataItemStack.class);
|
||||
MigratorUtil.addJsonRepresentation(Inventory.class, null);
|
||||
MigratorUtil.setTargetVersion(Inventory.class, MigratorUtil.getTargetVersion(DataItemStack.class));
|
||||
|
||||
// Activate
|
||||
this.activateAuto();
|
||||
|
||||
// These must be activated after nms
|
||||
this.activate(
|
||||
|
||||
// Writer,
|
||||
WriterItemStack.class,
|
||||
|
||||
// Util
|
||||
PlayerUtil.class,
|
||||
BoardUtil.class
|
||||
|
@ -1,181 +0,0 @@
|
||||
package com.massivecraft.massivecore;
|
||||
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterPotionEffectType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class wraps the Bukkit PotionEffect class by reimplementing storage of the data.
|
||||
* The purpose of this class is to allow for serialization using GSON.
|
||||
* You can not serialize the Bukkit PotionEffect due to some strange GSON bug.
|
||||
* Also we get the opportunity to add in some nice utility methods.
|
||||
*/
|
||||
public class PotionEffectWrap
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorType(TypeConverterPotionEffectType.class)
|
||||
protected int id;
|
||||
public int getId() { return this.id; }
|
||||
public void setId(int id) { this.id = id; }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setPotionEffectType(PotionEffectType potionEffectType) { this.setId(potionEffectType.getId());}
|
||||
@SuppressWarnings("deprecation")
|
||||
public PotionEffectType getPotionEffectType() { return PotionEffectType.getById(this.getId()); }
|
||||
|
||||
protected int amplifier;
|
||||
public int getAmplifier() { return this.amplifier; }
|
||||
public void setAmplifier(int amplifier) { this.amplifier = amplifier; }
|
||||
|
||||
protected int duration;
|
||||
public int getDuration() { return this.duration; }
|
||||
public void setDuration(int duration) { this.duration = duration; }
|
||||
|
||||
protected boolean ambient;
|
||||
public boolean isAmbient() { return this.ambient; }
|
||||
public void setAmbient(boolean ambient) { this.ambient = ambient; }
|
||||
|
||||
// Since Minecraft 1.8
|
||||
protected boolean particles;
|
||||
public boolean isParticles() { return this.particles; }
|
||||
public void setParticles(boolean particles) { this.particles = particles; }
|
||||
// TODO: How to backwards compat?
|
||||
// TODO: For now we just don't support this 1.8 option...
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public PotionEffectWrap(int id, int amplifier, int duration, boolean ambient, boolean particles)
|
||||
{
|
||||
this.id = id;
|
||||
this.amplifier = amplifier;
|
||||
this.duration = duration;
|
||||
this.ambient = ambient;
|
||||
this.particles = particles;
|
||||
}
|
||||
|
||||
public PotionEffectWrap()
|
||||
{
|
||||
this.id = 0;
|
||||
this.amplifier = 0;
|
||||
this.duration = 0;
|
||||
this.ambient = false;
|
||||
this.particles = true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FROM BUKKIT
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static PotionEffectWrap valueOf(PotionEffect potionEffect)
|
||||
{
|
||||
return new PotionEffectWrap(potionEffect.getType().getId(), potionEffect.getAmplifier(), potionEffect.getDuration(), potionEffect.isAmbient(), true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TO BUKKIT
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public PotionEffect asPotionEffect()
|
||||
{
|
||||
return new PotionEffect(PotionEffectType.getById(id), this.duration, this.amplifier, this.ambient);
|
||||
}
|
||||
|
||||
public boolean addTo(LivingEntity entity)
|
||||
{
|
||||
return entity.addPotionEffect(this.asPotionEffect(), true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static List<PotionEffectWrap> getEffects(LivingEntity entity)
|
||||
{
|
||||
// Create Ret
|
||||
List<PotionEffectWrap> ret = new MassiveList<>();
|
||||
|
||||
// Fill Ret
|
||||
for (PotionEffect potionEffect : entity.getActivePotionEffects())
|
||||
{
|
||||
ret.add(PotionEffectWrap.valueOf(potionEffect));
|
||||
}
|
||||
|
||||
// Return Ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void removeEffects(LivingEntity entity)
|
||||
{
|
||||
// For each active potion effect ...
|
||||
for (PotionEffect potionEffect : entity.getActivePotionEffects())
|
||||
{
|
||||
// ... remove that type.
|
||||
entity.removePotionEffect(potionEffect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
public static void addEffects(LivingEntity entity, Iterable<? extends PotionEffectWrap> potionEffectWraps)
|
||||
{
|
||||
// For each supplied potion effect wrap ...
|
||||
for (PotionEffectWrap potionEffectWrap : potionEffectWraps)
|
||||
{
|
||||
// ... add it to the entity.
|
||||
potionEffectWrap.addTo(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setEffects(LivingEntity entity, Collection<? extends PotionEffectWrap> potionEffectWraps)
|
||||
{
|
||||
// Remove ...
|
||||
removeEffects(entity);
|
||||
|
||||
// ... then add.
|
||||
addEffects(entity, potionEffectWraps);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TO STRING
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getListLine()
|
||||
{
|
||||
// Create Ret
|
||||
StringBuilder ret = new StringBuilder();
|
||||
|
||||
// Type Name (ID)
|
||||
ret.append(this.getPotionEffectType().getName());
|
||||
ret.append(' ');
|
||||
|
||||
// Amplifier
|
||||
ret.append(this.amplifier);
|
||||
ret.append(' ');
|
||||
|
||||
// Duration
|
||||
ret.append(this.duration);
|
||||
ret.append(' ');
|
||||
|
||||
// Ambient
|
||||
ret.append(this.ambient);
|
||||
ret.append(' ');
|
||||
|
||||
// Particles
|
||||
ret.append(this.particles);
|
||||
|
||||
// Return Ret
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.massivecraft.massivecore.collections.MassiveListDef;
|
||||
import com.massivecraft.massivecore.item.DataBannerPattern;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class AdapterBannerPatterns implements JsonDeserializer<MassiveListDef<DataBannerPattern>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final AdapterBannerPatterns i = new AdapterBannerPatterns();
|
||||
public static AdapterBannerPatterns get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
// Default serialization is fine.
|
||||
// We do however provide a smarter deserialiser.
|
||||
// This is for the sole purpose of upgrading from the old deprecated database format.
|
||||
//
|
||||
// In the old version (around version 2.8.10) we made use of a list with primitives.
|
||||
// id, color, id, color...
|
||||
// They were just coming in that order and were not wrapped in some kind of entry.
|
||||
//
|
||||
// The data types are the same in the old and new version.
|
||||
// String, Number, String, Number...
|
||||
//
|
||||
// In the new version we do however wrap them in the DataBannerPattern.
|
||||
|
||||
@Override
|
||||
public MassiveListDef<DataBannerPattern> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
// Create
|
||||
MassiveListDef<DataBannerPattern> ret = new MassiveListDef<>();
|
||||
|
||||
// Null (Def implementation is never null)
|
||||
if (json == null) return ret;
|
||||
if (json.equals(JsonNull.INSTANCE)) return ret;
|
||||
|
||||
// It is an array in both old and new version
|
||||
JsonArray array = json.getAsJsonArray();
|
||||
|
||||
// Empty?
|
||||
if (array.size() == 0) return ret;
|
||||
|
||||
// First element indicates version
|
||||
JsonElement first = array.get(0);
|
||||
if (first instanceof JsonObject)
|
||||
{
|
||||
// New
|
||||
for (JsonElement element : array)
|
||||
{
|
||||
DataBannerPattern dataBannerPattern = context.deserialize(element, DataBannerPattern.class);
|
||||
ret.add(dataBannerPattern);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Old aka Upgrade Mode
|
||||
Iterator<JsonElement> iterator = array.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
DataBannerPattern dataBannerPattern = new DataBannerPattern();
|
||||
|
||||
JsonElement idElement = iterator.next();
|
||||
String id = idElement.getAsString();
|
||||
dataBannerPattern.setId(id);
|
||||
|
||||
JsonElement colorElement = iterator.next();
|
||||
Integer color = colorElement.getAsInt();
|
||||
dataBannerPattern.setColor(color);
|
||||
|
||||
ret.add(dataBannerPattern);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
import com.massivecraft.massivecore.mixin.MixinInventory;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorUtil;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* This is my Gson adapter for Inventories.
|
||||
* It handles all inventories as CraftInventoryCustom "Chest"s with size of your choice
|
||||
* except for PlayerInventory which it handles pretty darn well!
|
||||
*/
|
||||
public class AdapterInventory implements JsonDeserializer<Inventory>, JsonSerializer<Inventory>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final int SIZE_PLAYER_STORAGE = 36;
|
||||
public static final int INDEX_PLAYER_STORAGE_FROM = 0;
|
||||
public static final int INDEX_PLAYER_STORAGE_TO = SIZE_PLAYER_STORAGE - 1;
|
||||
|
||||
public static final int INDEX_PLAYER_SHIELD = 40;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD NAME CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String SIZE = "size";
|
||||
|
||||
public static final String PLAYER = "player";
|
||||
|
||||
public static final String HELMET = "helmet";
|
||||
public static final String CHESTPLATE = "chestplate";
|
||||
public static final String LEGGINGS = "leggings";
|
||||
public static final String BOOTS = "boots";
|
||||
public static final String SHIELD = "shield";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final AdapterInventory i = new AdapterInventory();
|
||||
public static AdapterInventory get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Inventory src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return toJson(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return fromJson(json);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// IMPLEMENTATION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static JsonElement toJson(Inventory src)
|
||||
{
|
||||
// The return value is this object:
|
||||
JsonObject jsonInventory = new JsonObject();
|
||||
|
||||
// These variables are used in loops and repetitive logic.
|
||||
ItemStack itemStack = null;
|
||||
JsonElement jsonItemStack = null;
|
||||
String index = null;
|
||||
|
||||
// Every inventory has a content part.
|
||||
ItemStack[] itemStacks = src.getContents();
|
||||
|
||||
if (src instanceof PlayerInventory)
|
||||
{
|
||||
// Add the size "player"
|
||||
jsonInventory.addProperty(SIZE, PLAYER);
|
||||
|
||||
// Cast to PlayerInventory
|
||||
PlayerInventory psrc = (PlayerInventory)src;
|
||||
|
||||
// Helmet
|
||||
itemStack = psrc.getHelmet();
|
||||
if (itemStack != null)
|
||||
{
|
||||
jsonItemStack = MassiveCore.gson.toJsonTree(itemStack, ItemStack.class);
|
||||
jsonInventory.add(HELMET, jsonItemStack);
|
||||
}
|
||||
|
||||
// Chestplate
|
||||
itemStack = psrc.getChestplate();
|
||||
if (itemStack != null)
|
||||
{
|
||||
jsonItemStack = MassiveCore.gson.toJsonTree(itemStack, ItemStack.class);
|
||||
jsonInventory.add(CHESTPLATE, jsonItemStack);
|
||||
}
|
||||
|
||||
// Leggings
|
||||
itemStack = psrc.getLeggings();
|
||||
if (itemStack != null)
|
||||
{
|
||||
jsonItemStack = MassiveCore.gson.toJsonTree(itemStack, ItemStack.class);
|
||||
jsonInventory.add(LEGGINGS, jsonItemStack);
|
||||
}
|
||||
|
||||
// Boots
|
||||
itemStack = psrc.getBoots();
|
||||
if (itemStack != null)
|
||||
{
|
||||
jsonItemStack = MassiveCore.gson.toJsonTree(itemStack, ItemStack.class);
|
||||
jsonInventory.add(BOOTS, jsonItemStack);
|
||||
}
|
||||
|
||||
// Shield (Minecraft 1.9)
|
||||
itemStack = null;
|
||||
if (INDEX_PLAYER_SHIELD < itemStacks.length) itemStack = itemStacks[INDEX_PLAYER_SHIELD];
|
||||
if (itemStack != null)
|
||||
{
|
||||
jsonItemStack = MassiveCore.gson.toJsonTree(itemStack, ItemStack.class);
|
||||
jsonInventory.add(SHIELD, jsonItemStack);
|
||||
}
|
||||
|
||||
// Storage Range (Minecraft 1.9)
|
||||
itemStacks = range(itemStacks, INDEX_PLAYER_STORAGE_FROM, INDEX_PLAYER_STORAGE_TO);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add the size *length*
|
||||
jsonInventory.addProperty(SIZE, itemStacks.length);
|
||||
}
|
||||
|
||||
// Add the content at the end since we like to have it at the bottom of return json.
|
||||
for (Entry<Integer, DataItemStack> entry : DataItemStack.fromBukkitContents(itemStacks).entrySet())
|
||||
{
|
||||
index = String.valueOf(entry.getKey());
|
||||
jsonItemStack = MassiveCore.gson.toJsonTree(entry.getValue());
|
||||
jsonInventory.add(index, jsonItemStack);
|
||||
}
|
||||
|
||||
// Add version
|
||||
int version = MigratorUtil.getTargetVersion(DataItemStack.class);
|
||||
jsonInventory.addProperty(MigratorUtil.VERSION_FIELD_NAME, version);
|
||||
|
||||
return jsonInventory;
|
||||
}
|
||||
|
||||
public static Inventory fromJson(JsonElement json)
|
||||
{
|
||||
// If must be an object!
|
||||
if ( ! json.isJsonObject()) return null;
|
||||
JsonObject jsonInventory = json.getAsJsonObject();
|
||||
|
||||
// The return value
|
||||
Inventory ret = null;
|
||||
|
||||
// These variables are used in loops and repetitive logic.
|
||||
ItemStack itemStack = null;
|
||||
JsonElement jsonItemStack = null;
|
||||
|
||||
// There must be a size entry!
|
||||
if ( ! jsonInventory.has(SIZE)) return null;
|
||||
|
||||
JsonPrimitive jsonSize = jsonInventory.get(SIZE).getAsJsonPrimitive();
|
||||
int size = 0;
|
||||
|
||||
// What size/type is it?
|
||||
if (jsonSize.isString() && jsonSize.getAsString().equals(PLAYER))
|
||||
{
|
||||
// We use 36 here since it's the size of the player inventory (without armor)
|
||||
size = SIZE_PLAYER_STORAGE;
|
||||
|
||||
// This is a PlayerInventory
|
||||
ret = MixinInventory.get().createPlayerInventory();
|
||||
PlayerInventory pret = (PlayerInventory)ret;
|
||||
|
||||
// Helmet
|
||||
if (jsonInventory.has(HELMET))
|
||||
{
|
||||
itemStack = getItemStack(jsonInventory, HELMET);
|
||||
pret.setHelmet(itemStack);
|
||||
}
|
||||
|
||||
// Chestplate
|
||||
if (jsonInventory.has(CHESTPLATE))
|
||||
{
|
||||
itemStack = getItemStack(jsonInventory, CHESTPLATE);
|
||||
pret.setChestplate(itemStack);
|
||||
}
|
||||
|
||||
// Leggings
|
||||
if (jsonInventory.has(LEGGINGS))
|
||||
{
|
||||
jsonItemStack = jsonInventory.get(LEGGINGS);
|
||||
itemStack = MassiveCore.gson.fromJson(jsonItemStack, ItemStack.class);
|
||||
pret.setLeggings(itemStack);
|
||||
}
|
||||
|
||||
// Boots
|
||||
if (jsonInventory.has(BOOTS))
|
||||
{
|
||||
itemStack = getItemStack(jsonInventory, BOOTS);
|
||||
pret.setBoots(itemStack);
|
||||
}
|
||||
|
||||
// Shield (Minecraft 1.9)
|
||||
if (jsonInventory.has(SHIELD) && INDEX_PLAYER_SHIELD < pret.getSize())
|
||||
{
|
||||
itemStack = getItemStack(jsonInventory, SHIELD);
|
||||
pret.setItem(INDEX_PLAYER_SHIELD, itemStack);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// A custom size were specified
|
||||
size = jsonSize.getAsInt();
|
||||
|
||||
// This is a "Custom" Inventory (content only).
|
||||
ret = MixinInventory.get().createInventory(null, size, "");
|
||||
}
|
||||
|
||||
// Now process content
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
String stackIdx = String.valueOf(i);
|
||||
itemStack = getItemStack(jsonInventory, stackIdx);
|
||||
if (itemStack == null) continue;
|
||||
ret.setItem(i, itemStack);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static ItemStack getItemStack(JsonObject jsonInventory, String idx)
|
||||
{
|
||||
// Get jsonItemStack
|
||||
JsonElement jsonItemStack = jsonInventory.get(idx);
|
||||
if (jsonItemStack == null) return null;
|
||||
|
||||
ItemStack ret = MassiveCore.gson.fromJson(jsonItemStack, ItemStack.class);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
// This is a modified copyOfRange implementation.
|
||||
// Both boundaries are inclusive.
|
||||
// It returns the original when possible.
|
||||
public static <T> T[] range(T[] original, int from, int to)
|
||||
{
|
||||
if (from == 0 && to == original.length - 1) return original;
|
||||
return Arrays.copyOfRange(original, from, to + 1);
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* This is a GSON serializer/deserializer for the Bukkit ItemStack. Why not use
|
||||
* the built in Bukkit serializer/deserializer? I would have loved to do that :)
|
||||
* but sadly that one is YAML centric and cannot be used with json in a good
|
||||
* way. This serializer requires manual updating to work but produces clean
|
||||
* json. See the file itemstackformat.txt for more info.
|
||||
*/
|
||||
public class AdapterItemStack implements JsonDeserializer<ItemStack>, JsonSerializer<ItemStack>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final AdapterItemStack i = new AdapterItemStack();
|
||||
public static AdapterItemStack get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
DataItemStack dataItemStack = new DataItemStack(src);
|
||||
return context.serialize(dataItemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
DataItemStack dataItemStack = context.deserialize(json, DataItemStack.class);
|
||||
return dataItemStack.toBukkit();
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class AdapterPlayerInventory implements JsonDeserializer<PlayerInventory>, JsonSerializer<PlayerInventory>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final AdapterPlayerInventory i = new AdapterPlayerInventory();
|
||||
public static AdapterPlayerInventory get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(PlayerInventory src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return AdapterInventory.toJson(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerInventory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return (PlayerInventory) AdapterInventory.fromJson(json);
|
||||
}
|
||||
|
||||
}
|
@ -7,10 +7,7 @@ import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.WorldExceptionSet;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner;
|
||||
import com.massivecraft.massivecore.command.type.combined.TypeDataBannerPattern;
|
||||
import com.massivecraft.massivecore.command.type.combined.TypeDataPotionEffect;
|
||||
import com.massivecraft.massivecore.command.type.combined.TypeEntry;
|
||||
import com.massivecraft.massivecore.command.type.combined.TypePotionEffectWrap;
|
||||
import com.massivecraft.massivecore.command.type.combined.TypeSoundEffect;
|
||||
import com.massivecraft.massivecore.command.type.container.TypeBackstringSet;
|
||||
import com.massivecraft.massivecore.command.type.container.TypeExceptionSet;
|
||||
@ -275,9 +272,6 @@ public class RegistryType
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
// NOTE: As of 2016-05-17 about 15% of all servers are still using 1.7.x.
|
||||
// With this in mind there are some try catch clauses.
|
||||
// We catch NoClassDefFoundError and silently move along on those servers.
|
||||
|
||||
public static void registerAll()
|
||||
{
|
||||
@ -319,44 +313,10 @@ public class RegistryType
|
||||
register(TypeOcelotType.get());
|
||||
register(TypeParticleEffect.get());
|
||||
register(TypeSpawnReason.get());
|
||||
|
||||
// 1.7 Compat
|
||||
try
|
||||
{
|
||||
register(TypeRabbitType.get());
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
register(TypeDamageModifier.get());
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
register(TypeLlamaColor.get());
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
register(TypeParrotVariant.get());
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
register(TypeRabbitType.get());
|
||||
register(TypeDamageModifier.get());
|
||||
register(TypeLlamaColor.get());
|
||||
register(TypeParrotVariant.get());
|
||||
register(TypeSkeletonType.get());
|
||||
register(TypeSound.get());
|
||||
register(TypeVillagerProfession.get());
|
||||
@ -366,16 +326,10 @@ public class RegistryType
|
||||
register(TypeDestination.get());
|
||||
register(TypeItemStack.get());
|
||||
|
||||
register(TypeDataBannerPattern.get());
|
||||
register(TypeDataPotionEffect.get());
|
||||
register(TypeDataFireworkEffect.get());
|
||||
register(TypeDataItemStack.get());
|
||||
|
||||
register(TypePermission.get());
|
||||
register(TypePotionEffectType.get());
|
||||
register(TypePS.get());
|
||||
register(TypeWorld.get());
|
||||
register(TypePotionEffectWrap.get());
|
||||
register(TypeSoundEffect.get());
|
||||
|
||||
// Sender
|
||||
|
@ -1,19 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeObject;
|
||||
import com.massivecraft.massivecore.item.DataFireworkEffect;
|
||||
|
||||
public class TypeDataFireworkEffect extends TypeObject<DataFireworkEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeDataFireworkEffect i = new TypeDataFireworkEffect();
|
||||
public static TypeDataFireworkEffect get() { return i; }
|
||||
public TypeDataFireworkEffect()
|
||||
{
|
||||
super(DataFireworkEffect.class);
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeObject;
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TypeDataItemStack extends TypeTransformer<ItemStack, DataItemStack>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final TypeDataItemStack i = new TypeDataItemStack();
|
||||
public static TypeDataItemStack get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public TypeDataItemStack(Type<ItemStack> typeInner)
|
||||
{
|
||||
super(typeInner, TypeObject.get(DataItemStack.class));
|
||||
}
|
||||
|
||||
public TypeDataItemStack()
|
||||
{
|
||||
this(TypeItemStack.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataItemStack innerToOuter(ItemStack inner, CommandSender sender)
|
||||
{
|
||||
return DataItemStack.fromBukkit(inner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack outerToInner(DataItemStack outer)
|
||||
{
|
||||
return DataItemStack.toBukkit(outer);
|
||||
}
|
||||
|
||||
}
|
@ -2,14 +2,11 @@ package com.massivecraft.massivecore.command.type;
|
||||
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeEnchantment extends TypeAbstractChoice<Enchantment>
|
||||
{
|
||||
@ -71,17 +68,14 @@ public class TypeEnchantment extends TypeAbstractChoice<Enchantment>
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String getNameInner(Enchantment enchantment)
|
||||
{
|
||||
String rawname = enchantment.getName();
|
||||
List<String> rawnames = ID_TO_RAWNAMES.get(enchantment.getId());
|
||||
if (rawnames != null) rawname = rawnames.get(0);
|
||||
return Txt.getNicedEnumString(rawname);
|
||||
return enchantment.getKey().getNamespace();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
// TODO: this needs to be changed, so all the expected names work
|
||||
/*
|
||||
@Override
|
||||
public Set<String> getNamesInner(Enchantment enchantment)
|
||||
{
|
||||
@ -100,13 +94,12 @@ public class TypeEnchantment extends TypeAbstractChoice<Enchantment>
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
}*/
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String getIdInner(Enchantment enchantment)
|
||||
{
|
||||
return String.valueOf(enchantment.getId());
|
||||
return enchantment.getKey().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.enumeration.TypeMaterial;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class TypeMaterialId extends TypeTransformer<Material, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeMaterialId i = new TypeMaterialId();
|
||||
public static TypeMaterialId get() { return i; }
|
||||
|
||||
public TypeMaterialId()
|
||||
{
|
||||
super(TypeMaterial.get(), TypeInteger.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
|
||||
@Override
|
||||
public Integer innerToOuter(Material inner, CommandSender sender)
|
||||
{
|
||||
if (inner == null) return null;
|
||||
return inner.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material outerToInner(Integer outer)
|
||||
{
|
||||
if (outer == null) return null;
|
||||
return Material.getMaterial(outer);
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.combined;
|
||||
|
||||
import com.massivecraft.massivecore.item.DataBannerPattern;
|
||||
|
||||
public class TypeDataBannerPattern extends TypeCombined<DataBannerPattern>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeDataBannerPattern i = new TypeDataBannerPattern();
|
||||
public static TypeDataBannerPattern get() { return i; }
|
||||
|
||||
public TypeDataBannerPattern()
|
||||
{
|
||||
super(DataBannerPattern.class);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.combined;
|
||||
|
||||
import com.massivecraft.massivecore.item.DataPotionEffect;
|
||||
|
||||
public class TypeDataPotionEffect extends TypeCombined<DataPotionEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeDataPotionEffect i = new TypeDataPotionEffect();
|
||||
public static TypeDataPotionEffect get() { return i; }
|
||||
public TypeDataPotionEffect()
|
||||
{
|
||||
super(DataPotionEffect.class);
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.combined;
|
||||
|
||||
import com.massivecraft.massivecore.PotionEffectWrap;
|
||||
|
||||
public class TypePotionEffectWrap extends TypeCombined<PotionEffectWrap>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypePotionEffectWrap i = new TypePotionEffectWrap();
|
||||
public static TypePotionEffectWrap get() { return i; }
|
||||
|
||||
public TypePotionEffectWrap()
|
||||
{
|
||||
super(PotionEffectWrap.class);
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.Type;
|
||||
import com.massivecraft.massivecore.command.type.TypeTransformer;
|
||||
import com.massivecraft.massivecore.item.Converter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class TypeConverter<A, B> extends TypeTransformer<A, B>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Converter<A, B> a2b;
|
||||
public Converter<A, B> getA2b() { return this.a2b; }
|
||||
|
||||
private final Converter<B, A> b2a;
|
||||
public Converter<B, A> getB2a() { return this.b2a; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public TypeConverter(Type<A> typeA, Type<B> typeB, Converter<A, B> a2b, Converter<B, A> b2a)
|
||||
{
|
||||
super(typeA, typeB);
|
||||
this.a2b = a2b;
|
||||
this.b2a = b2a;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
|
||||
@Override
|
||||
public B innerToOuter(A inner, CommandSender sender)
|
||||
{
|
||||
return this.getA2b().convert(inner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public A outerToInner(B outer)
|
||||
{
|
||||
return this.getB2a().convert(outer);
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.Type;
|
||||
import com.massivecraft.massivecore.command.type.enumeration.TypePatternType;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.item.Converter;
|
||||
import com.massivecraft.massivecore.item.ConverterFromBannerPatternType;
|
||||
import com.massivecraft.massivecore.item.ConverterToBannerPatternType;
|
||||
|
||||
// Minecraft 1.7 Compatibility
|
||||
public class TypeConverterBannerPatternType<A> extends TypeConverter<A, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeConverterBannerPatternType<?> i = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> TypeConverterBannerPatternType<T> get()
|
||||
{
|
||||
if (i == null) i = new TypeConverterBannerPatternType<>(TypePatternType.get(), ConverterFromBannerPatternType.get(), ConverterToBannerPatternType.get());
|
||||
return (TypeConverterBannerPatternType<T>) i;
|
||||
}
|
||||
|
||||
public TypeConverterBannerPatternType(Type<A> typeA, Converter<A, String> a2b, Converter<String, A> b2a)
|
||||
{
|
||||
super(typeA, TypeString.get(), a2b, b2a);
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.TypeColor;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.item.ConverterFromColor;
|
||||
import com.massivecraft.massivecore.item.ConverterToColor;
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class TypeConverterColor extends TypeConverter<Color, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeConverterColor i = new TypeConverterColor();
|
||||
public static TypeConverterColor get() { return i; }
|
||||
|
||||
public TypeConverterColor()
|
||||
{
|
||||
super(TypeColor.get(), TypeInteger.get(), ConverterFromColor.get(), ConverterToColor.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.item.ConverterFromDyeColor;
|
||||
import com.massivecraft.massivecore.item.ConverterToDyeColor;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
public class TypeConverterDyeColor extends TypeConverter<DyeColor, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeConverterDyeColor i = new TypeConverterDyeColor();
|
||||
public static TypeConverterDyeColor get() { return i; }
|
||||
|
||||
public TypeConverterDyeColor()
|
||||
{
|
||||
super(TypeDyeColor.get(), TypeInteger.get(), ConverterFromDyeColor.get(), ConverterToDyeColor.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.TypeEnchantment;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.item.ConverterFromEnchant;
|
||||
import com.massivecraft.massivecore.item.ConverterToEnchant;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class TypeConverterEnchant extends TypeConverter<Enchantment, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeConverterEnchant i = new TypeConverterEnchant();
|
||||
public static TypeConverterEnchant get() { return i; }
|
||||
|
||||
public TypeConverterEnchant()
|
||||
{
|
||||
super(TypeEnchantment.get(), TypeInteger.get(), ConverterFromEnchant.get(), ConverterToEnchant.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.enumeration.TypeFireworkEffectType;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.item.ConverterFromFireworkEffectType;
|
||||
import com.massivecraft.massivecore.item.ConverterToFireworkEffectType;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
|
||||
public class TypeConverterFireworkEffectType extends TypeConverter<Type, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeConverterFireworkEffectType i = new TypeConverterFireworkEffectType();
|
||||
public static TypeConverterFireworkEffectType get() { return i; }
|
||||
|
||||
public TypeConverterFireworkEffectType()
|
||||
{
|
||||
super(TypeFireworkEffectType.get(), TypeString.get(), ConverterFromFireworkEffectType.get(), ConverterToFireworkEffectType.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.enumeration.TypeItemFlag;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.item.ConverterFromItemFlag;
|
||||
import com.massivecraft.massivecore.item.ConverterToItemFlag;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public class TypeConverterItemFlag extends TypeConverter<ItemFlag, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeConverterItemFlag i = new TypeConverterItemFlag();
|
||||
public static TypeConverterItemFlag get() { return i; }
|
||||
|
||||
public TypeConverterItemFlag()
|
||||
{
|
||||
super(TypeItemFlag.get(), TypeString.get(), ConverterFromItemFlag.get(), ConverterToItemFlag.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.type.convert;
|
||||
|
||||
import com.massivecraft.massivecore.command.type.TypePotionEffectType;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.item.ConverterFromPotionEffectType;
|
||||
import com.massivecraft.massivecore.item.ConverterToPotionEffectType;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class TypeConverterPotionEffectType extends TypeConverter<PotionEffectType, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeConverterPotionEffectType i = new TypeConverterPotionEffectType();
|
||||
public static TypeConverterPotionEffectType get() { return i; }
|
||||
|
||||
public TypeConverterPotionEffectType()
|
||||
{
|
||||
super(TypePotionEffectType.get(), TypeInteger.get(), ConverterFromPotionEffectType.get(), ConverterToPotionEffectType.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,522 +0,0 @@
|
||||
package com.massivecraft.massivecore.entity.migrator;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MigratorDataItemStack001StringId extends MigratorRoot
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MigratorDataItemStack001StringId i = new MigratorDataItemStack001StringId();
|
||||
public static MigratorDataItemStack001StringId get() { return i; }
|
||||
private MigratorDataItemStack001StringId()
|
||||
{
|
||||
super(DataItemStack.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONVERSION
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void migrateInner(JsonObject json)
|
||||
{
|
||||
// Get the id
|
||||
JsonElement id = json.get("id");
|
||||
if (id == null || id.isJsonNull()) return;
|
||||
|
||||
// The id is either a number or string, always a JsonPrimitive
|
||||
JsonPrimitive primitive = id.getAsJsonPrimitive();
|
||||
|
||||
// Only convert if number
|
||||
if (!primitive.isNumber()) return;
|
||||
int typeId = primitive.getAsInt();
|
||||
String name = id2name.get(typeId);
|
||||
if (name == null) throw new RuntimeException(String.valueOf(typeId));
|
||||
JsonElement newValue = new JsonPrimitive(name);
|
||||
json.add("id", newValue);
|
||||
}
|
||||
|
||||
private static final Map<Integer, String> id2name;
|
||||
|
||||
static
|
||||
{
|
||||
Map<Integer, String> map = new MassiveMap<>();
|
||||
|
||||
map.put(0, "AIR");
|
||||
map.put(1, "STONE");
|
||||
map.put(2, "GRASS");
|
||||
map.put(3, "DIRT");
|
||||
map.put(4, "COBBLESTONE");
|
||||
map.put(5, "WOOD");
|
||||
map.put(6, "SAPLING");
|
||||
map.put(7, "BEDROCK");
|
||||
map.put(8, "WATER");
|
||||
map.put(9, "STATIONARY_WATER");
|
||||
map.put(10, "LAVA");
|
||||
map.put(11, "STATIONARY_LAVA");
|
||||
map.put(12, "SAND");
|
||||
map.put(13, "GRAVEL");
|
||||
map.put(14, "GOLD_ORE");
|
||||
map.put(15, "IRON_ORE");
|
||||
map.put(16, "COAL_ORE");
|
||||
map.put(17, "LOG");
|
||||
map.put(18, "LEAVES");
|
||||
map.put(19, "SPONGE");
|
||||
map.put(20, "GLASS");
|
||||
map.put(21, "LAPIS_ORE");
|
||||
map.put(22, "LAPIS_BLOCK");
|
||||
map.put(23, "DISPENSER");
|
||||
map.put(24, "SANDSTONE");
|
||||
map.put(25, "NOTE_BLOCK");
|
||||
map.put(26, "BED_BLOCK");
|
||||
map.put(27, "POWERED_RAIL");
|
||||
map.put(28, "DETECTOR_RAIL");
|
||||
map.put(29, "PISTON_STICKY_BASE");
|
||||
map.put(30, "WEB");
|
||||
map.put(31, "LONG_GRASS");
|
||||
map.put(32, "DEAD_BUSH");
|
||||
map.put(33, "PISTON_BASE");
|
||||
map.put(34, "PISTON_EXTENSION");
|
||||
map.put(35, "WOOL");
|
||||
map.put(36, "PISTON_MOVING_PIECE");
|
||||
map.put(37, "YELLOW_FLOWER");
|
||||
map.put(38, "RED_ROSE");
|
||||
map.put(39, "BROWN_MUSHROOM");
|
||||
map.put(40, "RED_MUSHROOM");
|
||||
map.put(41, "GOLD_BLOCK");
|
||||
map.put(42, "IRON_BLOCK");
|
||||
map.put(43, "DOUBLE_STEP");
|
||||
map.put(44, "STEP");
|
||||
map.put(45, "BRICK");
|
||||
map.put(46, "TNT");
|
||||
map.put(47, "BOOKSHELF");
|
||||
map.put(48, "MOSSY_COBBLESTONE");
|
||||
map.put(49, "OBSIDIAN");
|
||||
map.put(50, "TORCH");
|
||||
map.put(51, "FIRE");
|
||||
map.put(52, "MOB_SPAWNER");
|
||||
map.put(53, "WOOD_STAIRS");
|
||||
map.put(54, "CHEST");
|
||||
map.put(55, "REDSTONE_WIRE");
|
||||
map.put(56, "DIAMOND_ORE");
|
||||
map.put(57, "DIAMOND_BLOCK");
|
||||
map.put(58, "WORKBENCH");
|
||||
map.put(59, "CROPS");
|
||||
map.put(60, "SOIL");
|
||||
map.put(61, "FURNACE");
|
||||
map.put(62, "BURNING_FURNACE");
|
||||
map.put(63, "SIGN_POST");
|
||||
map.put(64, "WOODEN_DOOR");
|
||||
map.put(65, "LADDER");
|
||||
map.put(66, "RAILS");
|
||||
map.put(67, "COBBLESTONE_STAIRS");
|
||||
map.put(68, "WALL_SIGN");
|
||||
map.put(69, "LEVER");
|
||||
map.put(70, "STONE_PLATE");
|
||||
map.put(71, "IRON_DOOR_BLOCK");
|
||||
map.put(72, "WOOD_PLATE");
|
||||
map.put(73, "REDSTONE_ORE");
|
||||
map.put(74, "GLOWING_REDSTONE_ORE");
|
||||
map.put(75, "REDSTONE_TORCH_OFF");
|
||||
map.put(76, "REDSTONE_TORCH_ON");
|
||||
map.put(77, "STONE_BUTTON");
|
||||
map.put(78, "SNOW");
|
||||
map.put(79, "ICE");
|
||||
map.put(80, "SNOW_BLOCK");
|
||||
map.put(81, "CACTUS");
|
||||
map.put(82, "CLAY");
|
||||
map.put(83, "SUGAR_CANE_BLOCK");
|
||||
map.put(84, "JUKEBOX");
|
||||
map.put(85, "FENCE");
|
||||
map.put(86, "PUMPKIN");
|
||||
map.put(87, "NETHERRACK");
|
||||
map.put(88, "SOUL_SAND");
|
||||
map.put(89, "GLOWSTONE");
|
||||
map.put(90, "PORTAL");
|
||||
map.put(91, "JACK_O_LANTERN");
|
||||
map.put(92, "CAKE_BLOCK");
|
||||
map.put(93, "DIODE_BLOCK_OFF");
|
||||
map.put(94, "DIODE_BLOCK_ON");
|
||||
map.put(95, "STAINED_GLASS");
|
||||
map.put(96, "TRAP_DOOR");
|
||||
map.put(97, "MONSTER_EGGS");
|
||||
map.put(98, "SMOOTH_BRICK");
|
||||
map.put(99, "HUGE_MUSHROOM_1");
|
||||
map.put(100, "HUGE_MUSHROOM_2");
|
||||
map.put(101, "IRON_FENCE");
|
||||
map.put(102, "THIN_GLASS");
|
||||
map.put(103, "MELON_BLOCK");
|
||||
map.put(104, "PUMPKIN_STEM");
|
||||
map.put(105, "MELON_STEM");
|
||||
map.put(106, "VINE");
|
||||
map.put(107, "FENCE_GATE");
|
||||
map.put(108, "BRICK_STAIRS");
|
||||
map.put(109, "SMOOTH_STAIRS");
|
||||
map.put(110, "MYCEL");
|
||||
map.put(111, "WATER_LILY");
|
||||
map.put(112, "NETHER_BRICK");
|
||||
map.put(113, "NETHER_FENCE");
|
||||
map.put(114, "NETHER_BRICK_STAIRS");
|
||||
map.put(115, "NETHER_WARTS");
|
||||
map.put(116, "ENCHANTMENT_TABLE");
|
||||
map.put(117, "BREWING_STAND");
|
||||
map.put(118, "CAULDRON");
|
||||
map.put(119, "ENDER_PORTAL");
|
||||
map.put(120, "ENDER_PORTAL_FRAME");
|
||||
map.put(121, "ENDER_STONE");
|
||||
map.put(122, "DRAGON_EGG");
|
||||
map.put(123, "REDSTONE_LAMP_OFF");
|
||||
map.put(124, "REDSTONE_LAMP_ON");
|
||||
map.put(125, "WOOD_DOUBLE_STEP");
|
||||
map.put(126, "WOOD_STEP");
|
||||
map.put(127, "COCOA");
|
||||
map.put(128, "SANDSTONE_STAIRS");
|
||||
map.put(129, "EMERALD_ORE");
|
||||
map.put(130, "ENDER_CHEST");
|
||||
map.put(131, "TRIPWIRE_HOOK");
|
||||
map.put(132, "TRIPWIRE");
|
||||
map.put(133, "EMERALD_BLOCK");
|
||||
map.put(134, "SPRUCE_WOOD_STAIRS");
|
||||
map.put(135, "BIRCH_WOOD_STAIRS");
|
||||
map.put(136, "JUNGLE_WOOD_STAIRS");
|
||||
map.put(137, "COMMAND");
|
||||
map.put(138, "BEACON");
|
||||
map.put(139, "COBBLE_WALL");
|
||||
map.put(140, "FLOWER_POT");
|
||||
map.put(141, "CARROT");
|
||||
map.put(142, "POTATO");
|
||||
map.put(143, "WOOD_BUTTON");
|
||||
map.put(144, "SKULL");
|
||||
map.put(145, "ANVIL");
|
||||
map.put(146, "TRAPPED_CHEST");
|
||||
map.put(147, "GOLD_PLATE");
|
||||
map.put(148, "IRON_PLATE");
|
||||
map.put(149, "REDSTONE_COMPARATOR_OFF");
|
||||
map.put(150, "REDSTONE_COMPARATOR_ON");
|
||||
map.put(151, "DAYLIGHT_DETECTOR");
|
||||
map.put(152, "REDSTONE_BLOCK");
|
||||
map.put(153, "QUARTZ_ORE");
|
||||
map.put(154, "HOPPER");
|
||||
map.put(155, "QUARTZ_BLOCK");
|
||||
map.put(156, "QUARTZ_STAIRS");
|
||||
map.put(157, "ACTIVATOR_RAIL");
|
||||
map.put(158, "DROPPER");
|
||||
map.put(159, "STAINED_CLAY");
|
||||
map.put(160, "STAINED_GLASS_PANE");
|
||||
map.put(161, "LEAVES_2");
|
||||
map.put(162, "LOG_2");
|
||||
map.put(163, "ACACIA_STAIRS");
|
||||
map.put(164, "DARK_OAK_STAIRS");
|
||||
map.put(165, "SLIME_BLOCK");
|
||||
map.put(166, "BARRIER");
|
||||
map.put(167, "IRON_TRAPDOOR");
|
||||
map.put(168, "PRISMARINE");
|
||||
map.put(169, "SEA_LANTERN");
|
||||
map.put(170, "HAY_BLOCK");
|
||||
map.put(171, "CARPET");
|
||||
map.put(172, "HARD_CLAY");
|
||||
map.put(173, "COAL_BLOCK");
|
||||
map.put(174, "PACKED_ICE");
|
||||
map.put(175, "DOUBLE_PLANT");
|
||||
map.put(176, "STANDING_BANNER");
|
||||
map.put(177, "WALL_BANNER");
|
||||
map.put(178, "DAYLIGHT_DETECTOR_INVERTED");
|
||||
map.put(179, "RED_SANDSTONE");
|
||||
map.put(180, "RED_SANDSTONE_STAIRS");
|
||||
map.put(181, "DOUBLE_STONE_SLAB2");
|
||||
map.put(182, "STONE_SLAB2");
|
||||
map.put(183, "SPRUCE_FENCE_GATE");
|
||||
map.put(184, "BIRCH_FENCE_GATE");
|
||||
map.put(185, "JUNGLE_FENCE_GATE");
|
||||
map.put(186, "DARK_OAK_FENCE_GATE");
|
||||
map.put(187, "ACACIA_FENCE_GATE");
|
||||
map.put(188, "SPRUCE_FENCE");
|
||||
map.put(189, "BIRCH_FENCE");
|
||||
map.put(190, "JUNGLE_FENCE");
|
||||
map.put(191, "DARK_OAK_FENCE");
|
||||
map.put(192, "ACACIA_FENCE");
|
||||
map.put(193, "SPRUCE_DOOR");
|
||||
map.put(194, "BIRCH_DOOR");
|
||||
map.put(195, "JUNGLE_DOOR");
|
||||
map.put(196, "ACACIA_DOOR");
|
||||
map.put(197, "DARK_OAK_DOOR");
|
||||
map.put(198, "END_ROD");
|
||||
map.put(199, "CHORUS_PLANT");
|
||||
map.put(200, "CHORUS_FLOWER");
|
||||
map.put(201, "PURPUR_BLOCK");
|
||||
map.put(202, "PURPUR_PILLAR");
|
||||
map.put(203, "PURPUR_STAIRS");
|
||||
map.put(204, "PURPUR_DOUBLE_SLAB");
|
||||
map.put(205, "PURPUR_SLAB");
|
||||
map.put(206, "END_BRICKS");
|
||||
map.put(207, "BEETROOT_BLOCK");
|
||||
map.put(208, "GRASS_PATH");
|
||||
map.put(209, "END_GATEWAY");
|
||||
map.put(210, "COMMAND_REPEATING");
|
||||
map.put(211, "COMMAND_CHAIN");
|
||||
map.put(212, "FROSTED_ICE");
|
||||
map.put(213, "MAGMA");
|
||||
map.put(214, "NETHER_WART_BLOCK");
|
||||
map.put(215, "RED_NETHER_BRICK");
|
||||
map.put(216, "BONE_BLOCK");
|
||||
map.put(217, "STRUCTURE_VOID");
|
||||
map.put(218, "OBSERVER");
|
||||
map.put(219, "WHITE_SHULKER_BOX");
|
||||
map.put(220, "ORANGE_SHULKER_BOX");
|
||||
map.put(221, "MAGENTA_SHULKER_BOX");
|
||||
map.put(222, "LIGHT_BLUE_SHULKER_BOX");
|
||||
map.put(223, "YELLOW_SHULKER_BOX");
|
||||
map.put(224, "LIME_SHULKER_BOX");
|
||||
map.put(225, "PINK_SHULKER_BOX");
|
||||
map.put(226, "GRAY_SHULKER_BOX");
|
||||
map.put(227, "SILVER_SHULKER_BOX");
|
||||
map.put(228, "CYAN_SHULKER_BOX");
|
||||
map.put(229, "PURPLE_SHULKER_BOX");
|
||||
map.put(230, "BLUE_SHULKER_BOX");
|
||||
map.put(231, "BROWN_SHULKER_BOX");
|
||||
map.put(232, "GREEN_SHULKER_BOX");
|
||||
map.put(233, "RED_SHULKER_BOX");
|
||||
map.put(234, "BLACK_SHULKER_BOX");
|
||||
map.put(235, "WHITE_GLAZED_TERRACOTTA");
|
||||
map.put(236, "ORANGE_GLAZED_TERRACOTTA");
|
||||
map.put(237, "MAGENTA_GLAZED_TERRACOTTA");
|
||||
map.put(238, "LIGHT_BLUE_GLAZED_TERRACOTTA");
|
||||
map.put(239, "YELLOW_GLAZED_TERRACOTTA");
|
||||
map.put(240, "LIME_GLAZED_TERRACOTTA");
|
||||
map.put(241, "PINK_GLAZED_TERRACOTTA");
|
||||
map.put(242, "GRAY_GLAZED_TERRACOTTA");
|
||||
map.put(243, "SILVER_GLAZED_TERRACOTTA");
|
||||
map.put(244, "CYAN_GLAZED_TERRACOTTA");
|
||||
map.put(245, "PURPLE_GLAZED_TERRACOTTA");
|
||||
map.put(246, "BLUE_GLAZED_TERRACOTTA");
|
||||
map.put(247, "BROWN_GLAZED_TERRACOTTA");
|
||||
map.put(248, "GREEN_GLAZED_TERRACOTTA");
|
||||
map.put(249, "RED_GLAZED_TERRACOTTA");
|
||||
map.put(250, "BLACK_GLAZED_TERRACOTTA");
|
||||
map.put(251, "CONCRETE");
|
||||
map.put(252, "CONCRETE_POWDER");
|
||||
map.put(255, "STRUCTURE_BLOCK");
|
||||
map.put(256, "IRON_SPADE");
|
||||
map.put(257, "IRON_PICKAXE");
|
||||
map.put(258, "IRON_AXE");
|
||||
map.put(259, "FLINT_AND_STEEL");
|
||||
map.put(260, "APPLE");
|
||||
map.put(261, "BOW");
|
||||
map.put(262, "ARROW");
|
||||
map.put(263, "COAL");
|
||||
map.put(264, "DIAMOND");
|
||||
map.put(265, "IRON_INGOT");
|
||||
map.put(266, "GOLD_INGOT");
|
||||
map.put(267, "IRON_SWORD");
|
||||
map.put(268, "WOOD_SWORD");
|
||||
map.put(269, "WOOD_SPADE");
|
||||
map.put(270, "WOOD_PICKAXE");
|
||||
map.put(271, "WOOD_AXE");
|
||||
map.put(272, "STONE_SWORD");
|
||||
map.put(273, "STONE_SPADE");
|
||||
map.put(274, "STONE_PICKAXE");
|
||||
map.put(275, "STONE_AXE");
|
||||
map.put(276, "DIAMOND_SWORD");
|
||||
map.put(277, "DIAMOND_SPADE");
|
||||
map.put(278, "DIAMOND_PICKAXE");
|
||||
map.put(279, "DIAMOND_AXE");
|
||||
map.put(280, "STICK");
|
||||
map.put(281, "BOWL");
|
||||
map.put(282, "MUSHROOM_SOUP");
|
||||
map.put(283, "GOLD_SWORD");
|
||||
map.put(284, "GOLD_SPADE");
|
||||
map.put(285, "GOLD_PICKAXE");
|
||||
map.put(286, "GOLD_AXE");
|
||||
map.put(287, "STRING");
|
||||
map.put(288, "FEATHER");
|
||||
map.put(289, "SULPHUR");
|
||||
map.put(290, "WOOD_HOE");
|
||||
map.put(291, "STONE_HOE");
|
||||
map.put(292, "IRON_HOE");
|
||||
map.put(293, "DIAMOND_HOE");
|
||||
map.put(294, "GOLD_HOE");
|
||||
map.put(295, "SEEDS");
|
||||
map.put(296, "WHEAT");
|
||||
map.put(297, "BREAD");
|
||||
map.put(298, "LEATHER_HELMET");
|
||||
map.put(299, "LEATHER_CHESTPLATE");
|
||||
map.put(300, "LEATHER_LEGGINGS");
|
||||
map.put(301, "LEATHER_BOOTS");
|
||||
map.put(302, "CHAINMAIL_HELMET");
|
||||
map.put(303, "CHAINMAIL_CHESTPLATE");
|
||||
map.put(304, "CHAINMAIL_LEGGINGS");
|
||||
map.put(305, "CHAINMAIL_BOOTS");
|
||||
map.put(306, "IRON_HELMET");
|
||||
map.put(307, "IRON_CHESTPLATE");
|
||||
map.put(308, "IRON_LEGGINGS");
|
||||
map.put(309, "IRON_BOOTS");
|
||||
map.put(310, "DIAMOND_HELMET");
|
||||
map.put(311, "DIAMOND_CHESTPLATE");
|
||||
map.put(312, "DIAMOND_LEGGINGS");
|
||||
map.put(313, "DIAMOND_BOOTS");
|
||||
map.put(314, "GOLD_HELMET");
|
||||
map.put(315, "GOLD_CHESTPLATE");
|
||||
map.put(316, "GOLD_LEGGINGS");
|
||||
map.put(317, "GOLD_BOOTS");
|
||||
map.put(318, "FLINT");
|
||||
map.put(319, "PORK");
|
||||
map.put(320, "GRILLED_PORK");
|
||||
map.put(321, "PAINTING");
|
||||
map.put(322, "GOLDEN_APPLE");
|
||||
map.put(323, "SIGN");
|
||||
map.put(324, "WOOD_DOOR");
|
||||
map.put(325, "BUCKET");
|
||||
map.put(326, "WATER_BUCKET");
|
||||
map.put(327, "LAVA_BUCKET");
|
||||
map.put(328, "MINECART");
|
||||
map.put(329, "SADDLE");
|
||||
map.put(330, "IRON_DOOR");
|
||||
map.put(331, "REDSTONE");
|
||||
map.put(332, "SNOW_BALL");
|
||||
map.put(333, "BOAT");
|
||||
map.put(334, "LEATHER");
|
||||
map.put(335, "MILK_BUCKET");
|
||||
map.put(336, "CLAY_BRICK");
|
||||
map.put(337, "CLAY_BALL");
|
||||
map.put(338, "SUGAR_CANE");
|
||||
map.put(339, "PAPER");
|
||||
map.put(340, "BOOK");
|
||||
map.put(341, "SLIME_BALL");
|
||||
map.put(342, "STORAGE_MINECART");
|
||||
map.put(343, "POWERED_MINECART");
|
||||
map.put(344, "EGG");
|
||||
map.put(345, "COMPASS");
|
||||
map.put(346, "FISHING_ROD");
|
||||
map.put(347, "WATCH");
|
||||
map.put(348, "GLOWSTONE_DUST");
|
||||
map.put(349, "RAW_FISH");
|
||||
map.put(350, "COOKED_FISH");
|
||||
map.put(351, "INK_SACK");
|
||||
map.put(352, "BONE");
|
||||
map.put(353, "SUGAR");
|
||||
map.put(354, "CAKE");
|
||||
map.put(355, "BED");
|
||||
map.put(356, "DIODE");
|
||||
map.put(357, "COOKIE");
|
||||
map.put(358, "MAP");
|
||||
map.put(359, "SHEARS");
|
||||
map.put(360, "MELON");
|
||||
map.put(361, "PUMPKIN_SEEDS");
|
||||
map.put(362, "MELON_SEEDS");
|
||||
map.put(363, "RAW_BEEF");
|
||||
map.put(364, "COOKED_BEEF");
|
||||
map.put(365, "RAW_CHICKEN");
|
||||
map.put(366, "COOKED_CHICKEN");
|
||||
map.put(367, "ROTTEN_FLESH");
|
||||
map.put(368, "ENDER_PEARL");
|
||||
map.put(369, "BLAZE_ROD");
|
||||
map.put(370, "GHAST_TEAR");
|
||||
map.put(371, "GOLD_NUGGET");
|
||||
map.put(372, "NETHER_STALK");
|
||||
map.put(373, "POTION");
|
||||
map.put(374, "GLASS_BOTTLE");
|
||||
map.put(375, "SPIDER_EYE");
|
||||
map.put(376, "FERMENTED_SPIDER_EYE");
|
||||
map.put(377, "BLAZE_POWDER");
|
||||
map.put(378, "MAGMA_CREAM");
|
||||
map.put(379, "BREWING_STAND_ITEM");
|
||||
map.put(380, "CAULDRON_ITEM");
|
||||
map.put(381, "EYE_OF_ENDER");
|
||||
map.put(382, "SPECKLED_MELON");
|
||||
map.put(383, "MONSTER_EGG");
|
||||
map.put(384, "EXP_BOTTLE");
|
||||
map.put(385, "FIREBALL");
|
||||
map.put(386, "BOOK_AND_QUILL");
|
||||
map.put(387, "WRITTEN_BOOK");
|
||||
map.put(388, "EMERALD");
|
||||
map.put(389, "ITEM_FRAME");
|
||||
map.put(390, "FLOWER_POT_ITEM");
|
||||
map.put(391, "CARROT_ITEM");
|
||||
map.put(392, "POTATO_ITEM");
|
||||
map.put(393, "BAKED_POTATO");
|
||||
map.put(394, "POISONOUS_POTATO");
|
||||
map.put(395, "EMPTY_MAP");
|
||||
map.put(396, "GOLDEN_CARROT");
|
||||
map.put(397, "SKULL_ITEM");
|
||||
map.put(398, "CARROT_STICK");
|
||||
map.put(399, "NETHER_STAR");
|
||||
map.put(400, "PUMPKIN_PIE");
|
||||
map.put(401, "FIREWORK");
|
||||
map.put(402, "FIREWORK_CHARGE");
|
||||
map.put(403, "ENCHANTED_BOOK");
|
||||
map.put(404, "REDSTONE_COMPARATOR");
|
||||
map.put(405, "NETHER_BRICK_ITEM");
|
||||
map.put(406, "QUARTZ");
|
||||
map.put(407, "EXPLOSIVE_MINECART");
|
||||
map.put(408, "HOPPER_MINECART");
|
||||
map.put(409, "PRISMARINE_SHARD");
|
||||
map.put(410, "PRISMARINE_CRYSTALS");
|
||||
map.put(411, "RABBIT");
|
||||
map.put(412, "COOKED_RABBIT");
|
||||
map.put(413, "RABBIT_STEW");
|
||||
map.put(414, "RABBIT_FOOT");
|
||||
map.put(415, "RABBIT_HIDE");
|
||||
map.put(416, "ARMOR_STAND");
|
||||
map.put(417, "IRON_BARDING");
|
||||
map.put(418, "GOLD_BARDING");
|
||||
map.put(419, "DIAMOND_BARDING");
|
||||
map.put(420, "LEASH");
|
||||
map.put(421, "NAME_TAG");
|
||||
map.put(422, "COMMAND_MINECART");
|
||||
map.put(423, "MUTTON");
|
||||
map.put(424, "COOKED_MUTTON");
|
||||
map.put(425, "BANNER");
|
||||
map.put(426, "END_CRYSTAL");
|
||||
map.put(427, "SPRUCE_DOOR_ITEM");
|
||||
map.put(428, "BIRCH_DOOR_ITEM");
|
||||
map.put(429, "JUNGLE_DOOR_ITEM");
|
||||
map.put(430, "ACACIA_DOOR_ITEM");
|
||||
map.put(431, "DARK_OAK_DOOR_ITEM");
|
||||
map.put(432, "CHORUS_FRUIT");
|
||||
map.put(433, "CHORUS_FRUIT_POPPED");
|
||||
map.put(434, "BEETROOT");
|
||||
map.put(435, "BEETROOT_SEEDS");
|
||||
map.put(436, "BEETROOT_SOUP");
|
||||
map.put(437, "DRAGONS_BREATH");
|
||||
map.put(438, "SPLASH_POTION");
|
||||
map.put(439, "SPECTRAL_ARROW");
|
||||
map.put(440, "TIPPED_ARROW");
|
||||
map.put(441, "LINGERING_POTION");
|
||||
map.put(442, "SHIELD");
|
||||
map.put(443, "ELYTRA");
|
||||
map.put(444, "BOAT_SPRUCE");
|
||||
map.put(445, "BOAT_BIRCH");
|
||||
map.put(446, "BOAT_JUNGLE");
|
||||
map.put(447, "BOAT_ACACIA");
|
||||
map.put(448, "BOAT_DARK_OAK");
|
||||
map.put(449, "TOTEM");
|
||||
map.put(450, "SHULKER_SHELL");
|
||||
map.put(452, "IRON_NUGGET");
|
||||
map.put(453, "KNOWLEDGE_BOOK");
|
||||
map.put(2256, "GOLD_RECORD");
|
||||
map.put(2257, "GREEN_RECORD");
|
||||
map.put(2258, "RECORD_3");
|
||||
map.put(2259, "RECORD_4");
|
||||
map.put(2260, "RECORD_5");
|
||||
map.put(2261, "RECORD_6");
|
||||
map.put(2262, "RECORD_7");
|
||||
map.put(2263, "RECORD_8");
|
||||
map.put(2264, "RECORD_9");
|
||||
map.put(2265, "RECORD_10");
|
||||
map.put(2266, "RECORD_11");
|
||||
map.put(2267, "RECORD_12");
|
||||
|
||||
id2name = ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package com.massivecraft.massivecore.entity.migrator;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.adapter.AdapterInventory;
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class MigratorInventory001StringId extends MigratorRoot
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final Set<String> NAMES_EXTRA_FIELDS = MUtil.set(
|
||||
AdapterInventory.HELMET,
|
||||
AdapterInventory.CHESTPLATE,
|
||||
AdapterInventory.LEGGINGS,
|
||||
AdapterInventory.BOOTS,
|
||||
AdapterInventory.SHIELD
|
||||
);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MigratorInventory001StringId i = new MigratorInventory001StringId();
|
||||
public static MigratorInventory001StringId get() { return i; }
|
||||
private MigratorInventory001StringId()
|
||||
{
|
||||
super(Inventory.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONVERSION
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void migrateInner(JsonObject json)
|
||||
{
|
||||
for (Entry<String, JsonElement> entry : json.entrySet())
|
||||
{
|
||||
String name = entry.getKey();
|
||||
boolean updateable = NAMES_EXTRA_FIELDS.contains(name) || StringUtils.isNumeric(name);
|
||||
|
||||
if (!updateable) continue;
|
||||
|
||||
updateField(json, name);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateField(JsonObject json, String name)
|
||||
{
|
||||
JsonElement element = json.get(name);
|
||||
if (element == null) return;
|
||||
if (!element.isJsonObject()) return;
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
MigratorUtil.migrate(DataItemStack.class, object);
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
public abstract class Converter<X, Y>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ABSTRACT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public abstract Y convert(X x);
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
public class ConverterDefault<X, Y> extends Converter<X, Y>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterDefault<Object, Object> i = new ConverterDefault<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <X, Y> ConverterDefault<X, Y> get() { return (ConverterDefault<X, Y>) i; }
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <X, Y> ConverterDefault<X, Y> get(Class<X> cx, Class<Y> cy) { return (ConverterDefault<X, Y>) i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Y convert(X x)
|
||||
{
|
||||
return (Y)x;
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
|
||||
public class ConverterFromBannerPattern extends Converter<Pattern, DataBannerPattern>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromBannerPattern i = new ConverterFromBannerPattern();
|
||||
public static ConverterFromBannerPattern get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataBannerPattern convert(Pattern x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return new DataBannerPattern(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
|
||||
public class ConverterFromBannerPatternType extends Converter<PatternType, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromBannerPatternType i = new ConverterFromBannerPatternType();
|
||||
public static ConverterFromBannerPatternType get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String convert(PatternType x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.getIdentifier();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
|
||||
public class ConverterFromBannerPatterns extends ConverterList<Pattern, DataBannerPattern>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromBannerPatterns i = new ConverterFromBannerPatterns();
|
||||
public static ConverterFromBannerPatterns get() { return i; }
|
||||
public ConverterFromBannerPatterns()
|
||||
{
|
||||
super(ConverterFromBannerPattern.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class ConverterFromColor extends Converter<Color, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromColor i = new ConverterFromColor();
|
||||
public static ConverterFromColor get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer convert(Color x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.asRGB();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class ConverterFromColors extends ConverterList<Color, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromColors i = new ConverterFromColors();
|
||||
public static ConverterFromColors get() { return i; }
|
||||
public ConverterFromColors()
|
||||
{
|
||||
super(ConverterFromColor.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
public class ConverterFromDyeColor extends Converter<DyeColor, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromDyeColor i = new ConverterFromDyeColor();
|
||||
public static ConverterFromDyeColor get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Integer convert(DyeColor x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return Integer.valueOf(x.getDyeData());
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class ConverterFromEnchant extends Converter<Enchantment, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromEnchant i = new ConverterFromEnchant();
|
||||
public static ConverterFromEnchant get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Integer convert(Enchantment x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.getId();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class ConverterFromEnchants extends ConverterMap<Enchantment, Integer, Integer, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromEnchants i = new ConverterFromEnchants();
|
||||
public static ConverterFromEnchants get() { return i; }
|
||||
public ConverterFromEnchants()
|
||||
{
|
||||
super(ConverterFromEnchant.get(), ConverterDefault.get(Integer.class, Integer.class));
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
public class ConverterFromFireworkEffect extends Converter<FireworkEffect, DataFireworkEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromFireworkEffect i = new ConverterFromFireworkEffect();
|
||||
public static ConverterFromFireworkEffect get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataFireworkEffect convert(FireworkEffect x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return new DataFireworkEffect(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
|
||||
public class ConverterFromFireworkEffectType extends Converter<Type, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromFireworkEffectType i = new ConverterFromFireworkEffectType();
|
||||
public static ConverterFromFireworkEffectType get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String convert(Type x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.name();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
public class ConverterFromFireworkEffects extends ConverterList<FireworkEffect, DataFireworkEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromFireworkEffects i = new ConverterFromFireworkEffects();
|
||||
public static ConverterFromFireworkEffects get() { return i; }
|
||||
public ConverterFromFireworkEffects()
|
||||
{
|
||||
super(ConverterFromFireworkEffect.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ConverterFromInventoryContents extends Converter<ItemStack[], Map<Integer, DataItemStack>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromInventoryContents i = new ConverterFromInventoryContents();
|
||||
public static ConverterFromInventoryContents get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Map<Integer, DataItemStack> convert(ItemStack[] x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return DataItemStack.fromBukkitContents(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public class ConverterFromItemFlag extends Converter<ItemFlag, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromItemFlag i = new ConverterFromItemFlag();
|
||||
public static ConverterFromItemFlag get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String convert(ItemFlag x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.name();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public class ConverterFromItemFlags extends ConverterSet<ItemFlag, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromItemFlags i = new ConverterFromItemFlags();
|
||||
public static ConverterFromItemFlags get() { return i; }
|
||||
public ConverterFromItemFlags()
|
||||
{
|
||||
super(ConverterFromItemFlag.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class ConverterFromMaterial extends Converter<Material, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromMaterial i = new ConverterFromMaterial();
|
||||
public static ConverterFromMaterial get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String convert(Material x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.name();
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
public class ConverterFromPotionEffect extends Converter<PotionEffect, DataPotionEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromPotionEffect i = new ConverterFromPotionEffect();
|
||||
public static ConverterFromPotionEffect get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataPotionEffect convert(PotionEffect x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return new DataPotionEffect(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class ConverterFromPotionEffectType extends Converter<PotionEffectType, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromPotionEffectType i = new ConverterFromPotionEffectType();
|
||||
public static ConverterFromPotionEffectType get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Integer convert(PotionEffectType x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.getId();
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
public class ConverterFromPotionEffects extends ConverterList<PotionEffect, DataPotionEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterFromPotionEffects i = new ConverterFromPotionEffects();
|
||||
public static ConverterFromPotionEffects get() { return i; }
|
||||
public ConverterFromPotionEffects()
|
||||
{
|
||||
super(ConverterFromPotionEffect.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConverterList<EX, EY> extends Converter<Iterable<EX>, List<EY>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELD
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Converter<EX, EY> converterElement;
|
||||
public Converter<EX, EY> getConverterElement() { return this.converterElement; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ConverterList(Converter<EX, EY> converterElement)
|
||||
{
|
||||
this.converterElement = converterElement;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<EY> convert(Iterable<EX> exs)
|
||||
{
|
||||
// Null
|
||||
if (exs == null) return null;
|
||||
|
||||
// Create
|
||||
List<EY> eys = new MassiveList<>();
|
||||
|
||||
// Fill
|
||||
for (EX ex : exs)
|
||||
{
|
||||
EY ey = null;
|
||||
try
|
||||
{
|
||||
ey = this.getConverterElement().convert(ex);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
eys.add(ey);
|
||||
}
|
||||
|
||||
// Return
|
||||
return eys;
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
public class ConverterListImmutable<EX, EY> extends Converter<Iterable<EX>, ImmutableList<EY>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELD
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Converter<EX, EY> converterElement;
|
||||
public Converter<EX, EY> getConverterElement() { return this.converterElement; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ConverterListImmutable(Converter<EX, EY> converterElement)
|
||||
{
|
||||
this.converterElement = converterElement;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ImmutableList<EY> convert(Iterable<EX> exs)
|
||||
{
|
||||
// Null
|
||||
if (exs == null) return null;
|
||||
|
||||
// Create
|
||||
Builder<EY> eys = ImmutableList.builder();
|
||||
|
||||
// Fill
|
||||
for (EX ex : exs)
|
||||
{
|
||||
EY ey = null;
|
||||
try
|
||||
{
|
||||
ey = this.getConverterElement().convert(ex);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
eys.add(ey);
|
||||
}
|
||||
|
||||
// Return
|
||||
return eys.build();
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class ConverterMap<KX, VX, KY, VY> extends Converter<Map<KX, VX>, Map<KY, VY>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELD
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Converter<KX, KY> converterKey;
|
||||
public Converter<KX, KY> getConverterKey() { return this.converterKey; }
|
||||
|
||||
private final Converter<VX, VY> converterValue;
|
||||
public Converter<VX, VY> getConverterValue() { return this.converterValue; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ConverterMap(Converter<KX, KY> converterKey, Converter<VX, VY> converterValue)
|
||||
{
|
||||
this.converterKey = converterKey;
|
||||
this.converterValue = converterValue;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Map<KY, VY> convert(Map<KX, VX> mapx)
|
||||
{
|
||||
// Null
|
||||
if (mapx == null) return null;
|
||||
|
||||
// Create
|
||||
Map<KY, VY> mapy = new MassiveMap<>();
|
||||
|
||||
// Fill
|
||||
for (Entry<KX, VX> entry : mapx.entrySet())
|
||||
{
|
||||
KY ky = null;
|
||||
KX kx = entry.getKey();
|
||||
try
|
||||
{
|
||||
ky = this.getConverterKey().convert(kx);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
VY vy = null;
|
||||
VX vx = entry.getValue();
|
||||
try
|
||||
{
|
||||
vy = this.getConverterValue().convert(vx);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
mapy.put(ky, vy);
|
||||
}
|
||||
|
||||
// Return
|
||||
return mapy;
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ConverterSet<EX, EY> extends Converter<Iterable<EX>, Set<EY>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELD
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Converter<EX, EY> converterElement;
|
||||
public Converter<EX, EY> getConverterElement() { return this.converterElement; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ConverterSet(Converter<EX, EY> converterElement)
|
||||
{
|
||||
this.converterElement = converterElement;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Set<EY> convert(Iterable<EX> exs)
|
||||
{
|
||||
// Null
|
||||
if (exs == null) return null;
|
||||
|
||||
// Create
|
||||
Set<EY> eys = new MassiveSet<>();
|
||||
|
||||
// Fill
|
||||
for (EX ex : exs)
|
||||
{
|
||||
EY ey = null;
|
||||
try
|
||||
{
|
||||
ey = this.getConverterElement().convert(ex);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
eys.add(ey);
|
||||
}
|
||||
|
||||
// Return
|
||||
return eys;
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
|
||||
public class ConverterToBannerPattern extends Converter<DataBannerPattern, Pattern>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToBannerPattern i = new ConverterToBannerPattern();
|
||||
public static ConverterToBannerPattern get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Pattern convert(DataBannerPattern x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.toBukkit();
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
|
||||
public class ConverterToBannerPatternType extends Converter<String, PatternType>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToBannerPatternType i = new ConverterToBannerPatternType();
|
||||
public static ConverterToBannerPatternType get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public PatternType convert(String x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return PatternType.getByIdentifier(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
|
||||
public class ConverterToBannerPatterns extends ConverterList<DataBannerPattern, Pattern>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToBannerPatterns i = new ConverterToBannerPatterns();
|
||||
public static ConverterToBannerPatterns get() { return i; }
|
||||
public ConverterToBannerPatterns()
|
||||
{
|
||||
super(ConverterToBannerPattern.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class ConverterToColor extends Converter<Integer, Color>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToColor i = new ConverterToColor();
|
||||
public static ConverterToColor get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Color convert(Integer x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return Color.fromRGB(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class ConverterToColors extends ConverterListImmutable<Integer, Color>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToColors i = new ConverterToColors();
|
||||
public static ConverterToColors get() { return i; }
|
||||
public ConverterToColors()
|
||||
{
|
||||
super(ConverterToColor.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
public class ConverterToDyeColor extends Converter<Integer, DyeColor>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToDyeColor i = new ConverterToDyeColor();
|
||||
public static ConverterToDyeColor get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public DyeColor convert(Integer x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return DyeColor.getByDyeData(x.byteValue());
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class ConverterToEnchant extends Converter<Integer, Enchantment>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToEnchant i = new ConverterToEnchant();
|
||||
public static ConverterToEnchant get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Enchantment convert(Integer x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return Enchantment.getById(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class ConverterToEnchants extends ConverterMap<Integer, Integer, Enchantment, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToEnchants i = new ConverterToEnchants();
|
||||
public static ConverterToEnchants get() { return i; }
|
||||
public ConverterToEnchants()
|
||||
{
|
||||
super(ConverterToEnchant.get(), ConverterDefault.get(Integer.class, Integer.class));
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
public class ConverterToFireworkEffect extends Converter<DataFireworkEffect, FireworkEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToFireworkEffect i = new ConverterToFireworkEffect();
|
||||
public static ConverterToFireworkEffect get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public FireworkEffect convert(DataFireworkEffect x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.toBukkit();
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
|
||||
public class ConverterToFireworkEffectType extends Converter<String, Type>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToFireworkEffectType i = new ConverterToFireworkEffectType();
|
||||
public static ConverterToFireworkEffectType get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Type convert(String x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return Type.valueOf(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
public class ConverterToFireworkEffects extends ConverterList<DataFireworkEffect, FireworkEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToFireworkEffects i = new ConverterToFireworkEffects();
|
||||
public static ConverterToFireworkEffects get() { return i; }
|
||||
public ConverterToFireworkEffects()
|
||||
{
|
||||
super(ConverterToFireworkEffect.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ConverterToInventoryContents extends Converter<Map<Integer, DataItemStack>, ItemStack[]>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToInventoryContents i = new ConverterToInventoryContents();
|
||||
public static ConverterToInventoryContents get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ItemStack[] convert(Map<Integer, DataItemStack> x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return DataItemStack.toBukkitContents(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public class ConverterToItemFlag extends Converter<String, ItemFlag>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToItemFlag i = new ConverterToItemFlag();
|
||||
public static ConverterToItemFlag get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ItemFlag convert(String x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return ItemFlag.valueOf(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public class ConverterToItemFlags extends ConverterSet<String, ItemFlag>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToItemFlags i = new ConverterToItemFlags();
|
||||
public static ConverterToItemFlags get() { return i; }
|
||||
public ConverterToItemFlags()
|
||||
{
|
||||
super(ConverterToItemFlag.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class ConverterToMaterial extends Converter<String, Material>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToMaterial i = new ConverterToMaterial();
|
||||
public static ConverterToMaterial get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Material convert(String x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
Material ret = Material.getMaterial(x);
|
||||
if (ret == null) throw new NullPointerException(x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
public class ConverterToPotionEffect extends Converter<DataPotionEffect, PotionEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToPotionEffect i = new ConverterToPotionEffect();
|
||||
public static ConverterToPotionEffect get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public PotionEffect convert(DataPotionEffect x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return x.toBukkit();
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class ConverterToPotionEffectType extends Converter<Integer, PotionEffectType>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToPotionEffectType i = new ConverterToPotionEffectType();
|
||||
public static ConverterToPotionEffectType get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public PotionEffectType convert(Integer x)
|
||||
{
|
||||
if (x == null) return null;
|
||||
return PotionEffectType.getById(x);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
public class ConverterToPotionEffects extends ConverterList<DataPotionEffect, PotionEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final ConverterToPotionEffects i = new ConverterToPotionEffects();
|
||||
public static ConverterToPotionEffects get() { return i; }
|
||||
public ConverterToPotionEffects()
|
||||
{
|
||||
super(ConverterToPotionEffect.get());
|
||||
}
|
||||
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterBannerPatternType;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterDyeColor;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.massivecraft.massivecore.item.DataItemStack.get;
|
||||
import static com.massivecraft.massivecore.item.DataItemStack.set;
|
||||
|
||||
@EditorMethods(true)
|
||||
public class DataBannerPattern implements Comparable<DataBannerPattern>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final transient String DEFAULT_ID = null;
|
||||
public static final transient Integer DEFAULT_COLOR = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorType(TypeConverterBannerPatternType.class)
|
||||
private String id = null;
|
||||
public String getId() { return get(this.id, DEFAULT_ID); }
|
||||
public DataBannerPattern setId(String id) { this.id = set(id, DEFAULT_ID); return this; }
|
||||
|
||||
@EditorType(TypeConverterDyeColor.class)
|
||||
private Integer color = null;
|
||||
public Integer getColor() { return get(this.color, DEFAULT_COLOR); }
|
||||
public DataBannerPattern setColor(Integer color) { this.color = set(color, DEFAULT_ID); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public DataBannerPattern()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Minecraft 1.7 Compatibility
|
||||
public DataBannerPattern(Object pattern)
|
||||
{
|
||||
if ( ! (pattern instanceof Pattern)) throw new IllegalArgumentException("pattern");
|
||||
this.write((Pattern)pattern, false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Minecraft 1.7 Compatibility
|
||||
public void write(Object pattern, boolean a2b)
|
||||
{
|
||||
if ( ! (pattern instanceof Pattern)) throw new IllegalArgumentException("pattern");
|
||||
WriterBannerPattern.get().write(this, (Pattern)pattern, a2b);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TO BUKKIT
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Minecraft 1.7 Compatibility
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T toBukkit()
|
||||
{
|
||||
// Create
|
||||
Pattern ret = WriterBannerPattern.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
||||
// Return
|
||||
return (T) ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COMPARE & EQUALS & HASHCODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compareTo(DataBannerPattern that)
|
||||
{
|
||||
return ComparatorSmart.get().compare(
|
||||
this.getId(), that.getId(),
|
||||
this.getColor(), that.getColor()
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Use compare instead to avoid bugs?
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if ( ! (object instanceof DataBannerPattern)) return false;
|
||||
DataBannerPattern that = (DataBannerPattern)object;
|
||||
|
||||
return MUtil.equals(
|
||||
this.getId(), that.getId(),
|
||||
this.getColor(), that.getColor()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(
|
||||
this.getId(),
|
||||
this.getColor()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.massivecraft.massivecore.collections.MassiveListDef;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterFireworkEffectType;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.massivecraft.massivecore.item.DataItemStack.get;
|
||||
import static com.massivecraft.massivecore.item.DataItemStack.set;
|
||||
|
||||
@EditorMethods(true)
|
||||
public class DataFireworkEffect implements Comparable<DataFireworkEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final transient Boolean DEFAULT_FLICKER = false;
|
||||
public static final transient Boolean DEFAULT_TRAIL = false;
|
||||
public static final transient List<Integer> DEFAULT_COLORS = Collections.emptyList();
|
||||
public static final transient List<Integer> DEFAULT_FADE_COLORS = Collections.emptyList();
|
||||
public static final transient String DEFAULT_TYPE = "BALL_LARGE";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
// According to Bukkit the colors are indeed lists with explicit order.
|
||||
// I have not researched if that is true. For now I am assuming it is.
|
||||
|
||||
private Boolean flicker = null;
|
||||
public boolean hasFlicker() { return get(this.flicker, DEFAULT_FLICKER); }
|
||||
public DataFireworkEffect setFlicker(boolean flicker) { this.flicker = set(flicker, DEFAULT_FLICKER); return this; }
|
||||
|
||||
private Boolean trail = null;
|
||||
public boolean hasTrail() { return get(this.trail, DEFAULT_TRAIL); }
|
||||
public DataFireworkEffect setTrail(boolean trail) { this.trail = set(trail, DEFAULT_TRAIL); return this; }
|
||||
|
||||
@EditorTypeInner(TypeConverterColor.class)
|
||||
private MassiveListDef<Integer> colors = null;
|
||||
public List<Integer> getColors() { return get(this.colors, DEFAULT_COLORS); }
|
||||
public DataFireworkEffect setColors(List<Integer> colors) { this.colors = set(colors, DEFAULT_COLORS); return this; }
|
||||
|
||||
@EditorTypeInner(TypeConverterColor.class)
|
||||
@SerializedName("fade-colors")
|
||||
private MassiveListDef<Integer> fadeColors = null;
|
||||
public List<Integer> getFadeColors() { return get(this.fadeColors, DEFAULT_FADE_COLORS); }
|
||||
public DataFireworkEffect setFadeColors(List<Integer> fadeColors) { this.fadeColors = set(fadeColors, DEFAULT_FADE_COLORS); return this; }
|
||||
|
||||
@EditorType(TypeConverterFireworkEffectType.class)
|
||||
private String type = null;
|
||||
public String getType() { return get(this.type, DEFAULT_TYPE); }
|
||||
public DataFireworkEffect setType(String type) { this.type = set(type, DEFAULT_TYPE); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public DataFireworkEffect()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DataFireworkEffect(FireworkEffect fireworkEffect)
|
||||
{
|
||||
this.write(fireworkEffect, false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void write(FireworkEffect fireworkEffect, boolean a2b)
|
||||
{
|
||||
WriterFireworkEffect.get().write(this, fireworkEffect, a2b);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TO BUKKIT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FireworkEffect toBukkit()
|
||||
{
|
||||
// Create
|
||||
FireworkEffect ret = WriterFireworkEffect.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COMPARE & EQUALS & HASHCODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compareTo(DataFireworkEffect that)
|
||||
{
|
||||
return ComparatorSmart.get().compare(
|
||||
this.hasFlicker(), that.hasFlicker(),
|
||||
this.hasTrail(), that.hasTrail(),
|
||||
this.getColors(), that.getColors(),
|
||||
this.getColors(), that.getColors(),
|
||||
this.getFadeColors(), that.getFadeColors(),
|
||||
this.getType(), that.getType()
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Use compare instead to avoid bugs?
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if ( ! (object instanceof DataFireworkEffect)) return false;
|
||||
DataFireworkEffect that = (DataFireworkEffect)object;
|
||||
|
||||
return MUtil.equals(
|
||||
this.hasFlicker(), that.hasFlicker(),
|
||||
this.hasTrail(), that.hasTrail(),
|
||||
this.getColors(), that.getColors(),
|
||||
this.getColors(), that.getColors(),
|
||||
this.getFadeColors(), that.getFadeColors(),
|
||||
this.getType(), that.getType()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(
|
||||
this.hasFlicker(),
|
||||
this.hasTrail(),
|
||||
this.getColors(),
|
||||
this.getColors(),
|
||||
this.getFadeColors(),
|
||||
this.getType()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,685 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.collections.MassiveListDef;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveTreeMapDef;
|
||||
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorEditable;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorVisible;
|
||||
import com.massivecraft.massivecore.command.type.TypeMaterialId;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterDyeColor;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterEnchant;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterItemFlag;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.util.InventoryUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class makes use of primitives, collections and maps only.
|
||||
* All Bukkit specific enumerations and classes are avoided.
|
||||
* That means this class itself is compatible with all Bukkit server versions.
|
||||
*
|
||||
* We also make sure to only initialize variables with null as value.
|
||||
* Null means "default" and this way we save database space as well as CPU power on class construction.
|
||||
*
|
||||
* This class acts as a safe intermediary for database storage.
|
||||
* It is mainly used by the ItemStackAdapter and InventoryAdapter.
|
||||
* It can also be used directly, for example in maps, since it provides a stable equals and hash code method (as opposed to Bukkit).
|
||||
*/
|
||||
@EditorMethods(true)
|
||||
public class DataItemStack implements Comparable<DataItemStack>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
// The default values are used in the logic of both getters and setters.
|
||||
// For that reason they are immutable.
|
||||
//
|
||||
// We avoid null in all locations except where Bukkit makes use of null.
|
||||
// Since Bukkit doesn't NPE evade much we save ourselves a lot of trouble that way.
|
||||
// Especially note how all collections default to empty immutables instead of null.
|
||||
|
||||
public static final transient String DEFAULT_ID = Material.AIR.name();
|
||||
public static final transient Integer DEFAULT_COUNT = 1;
|
||||
public static final transient Integer DEFAULT_DAMAGE = 0;
|
||||
public static final transient String DEFAULT_NAME = null;
|
||||
public static final transient List<String> DEFAULT_LORE = Collections.emptyList();
|
||||
public static final transient Map<Integer, Integer> DEFAULT_ENCHANTS = Collections.emptyMap();
|
||||
public static final transient Integer DEFAULT_REPAIRCOST = 0;
|
||||
public static final transient String DEFAULT_TITLE = null;
|
||||
public static final transient String DEFAULT_AUTHOR = null;
|
||||
public static final transient List<String> DEFAULT_PAGES = Collections.emptyList();
|
||||
public static final transient Integer DEFAULT_COLOR = Bukkit.getItemFactory().getDefaultLeatherColor().asRGB();
|
||||
public static final transient Boolean DEFAULT_SCALING = false;
|
||||
public static final transient List<DataPotionEffect> DEFAULT_POTION_EFFECTS = Collections.emptyList();
|
||||
public static final transient String DEFAULT_SKULL = null;
|
||||
public static final transient DataFireworkEffect DEFAULT_FIREWORK_EFFECT = null;
|
||||
public static final transient List<DataFireworkEffect> DEFAULT_FIREWORK_EFFECTS = Collections.emptyList();
|
||||
public static final transient Integer DEFAULT_FIREWORK_FLIGHT = 0;
|
||||
public static final transient Map<Integer, Integer> DEFAULT_STORED_ENCHANTS = Collections.emptyMap();
|
||||
public static final transient Boolean DEFAULT_UNBREAKABLE = false;
|
||||
public static final transient Set<String> DEFAULT_FLAGS = Collections.emptySet();
|
||||
public static final transient Integer DEFAULT_BANNER_BASE = null;
|
||||
public static final transient List<DataBannerPattern> DEFAULT_BANNER_PATTERNS = Collections.emptyList();
|
||||
public static final transient String DEFAULT_POTION = "water";
|
||||
public static final transient Map<Integer, DataItemStack> DEFAULT_INVENTORY = Collections.emptyMap();
|
||||
public static final transient Integer DEFAULT_POTION_COLOR = null;
|
||||
public static final transient Integer DEFAULT_MAP_COLOR = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > VERSION
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorEditable(false)
|
||||
@EditorVisible(false)
|
||||
private int version = 1;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > BASIC
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorType(value = TypeMaterialId.class)
|
||||
private String id = null;
|
||||
public String getId() { return get(this.id, DEFAULT_ID); }
|
||||
public DataItemStack setId(String id) { this.id = set(id, DEFAULT_ID); return this; }
|
||||
|
||||
private Integer count = null;
|
||||
public int getCount() { return get(this.count, DEFAULT_COUNT); }
|
||||
public DataItemStack setCount(int count) { this.count = set(count, DEFAULT_COUNT); return this; }
|
||||
|
||||
private Integer damage = null;
|
||||
public int getDamage() { return get(this.damage, DEFAULT_DAMAGE); }
|
||||
public DataItemStack setDamage(int damage) { this.damage = set(damage, DEFAULT_DAMAGE); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > UNSPECIFIC
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorType(TypeStringParsed.class)
|
||||
private String name = null;
|
||||
public String getName() { return get(this.name, DEFAULT_NAME); }
|
||||
public DataItemStack setName(String name) { this.name = set(name, DEFAULT_NAME); return this; }
|
||||
|
||||
@EditorTypeInner(TypeStringParsed.class)
|
||||
private MassiveListDef<String> lore = null;
|
||||
public List<String> getLore() { return get(this.lore, DEFAULT_LORE); }
|
||||
public DataItemStack setLore(List<String> lore) { this.lore = set(lore, DEFAULT_LORE); return this; }
|
||||
|
||||
// The Bukkit ItemMeta#getEnchants() is not sorted by the enchant id.
|
||||
// There may be some sort of custom sorting order, I'm not sure.
|
||||
// We are however enforcing sorting by the enchant id ourselves to be sure.
|
||||
@EditorTypeInner({TypeConverterEnchant.class, TypeInteger.class})
|
||||
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> enchants = null;
|
||||
public Map<Integer, Integer> getEnchants() { return get(this.enchants, DEFAULT_ENCHANTS); }
|
||||
public DataItemStack setEnchants(Map<Integer, Integer> enchants) { this.enchants = set(enchants, DEFAULT_ENCHANTS); return this; }
|
||||
|
||||
private Integer repaircost = null;
|
||||
public int getRepaircost() { return get(this.repaircost, DEFAULT_REPAIRCOST); }
|
||||
public DataItemStack setRepaircost(int repaircost) { this.repaircost = set(repaircost, DEFAULT_REPAIRCOST); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > BOOK
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorType(TypeStringParsed.class)
|
||||
private String title = null;
|
||||
public String getTitle() { return get(this.title, DEFAULT_TITLE); }
|
||||
public DataItemStack setTitle(String title) { this.title = set(title, DEFAULT_TITLE); return this; }
|
||||
|
||||
private String author = null;
|
||||
public String getAuthor() { return get(this.author, DEFAULT_AUTHOR); }
|
||||
public DataItemStack setAuthor(String author) { this.author = set(author, DEFAULT_AUTHOR); return this; }
|
||||
|
||||
@EditorTypeInner(TypeStringParsed.class)
|
||||
private MassiveListDef<String> pages = null;
|
||||
public List<String> getPages() { return get(this.pages, DEFAULT_PAGES); }
|
||||
public DataItemStack setPages(Collection<String> pages) { this.pages = set(pages, DEFAULT_PAGES); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > LEATHER ARMOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorType(TypeConverterColor.class)
|
||||
private Integer color = null;
|
||||
public Integer getColor() { return get(this.color, DEFAULT_COLOR); }
|
||||
public DataItemStack setColor(int color) { this.color = set(color, DEFAULT_COLOR); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > MAP
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Boolean scaling = null;
|
||||
public boolean isScaling() { return get(this.scaling, DEFAULT_SCALING); }
|
||||
public DataItemStack setScaling(boolean scaling) { this.scaling = set(scaling, DEFAULT_SCALING); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > POTION EFFECTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// TODO: Sorting?
|
||||
@SerializedName("potion-effects")
|
||||
private MassiveListDef<DataPotionEffect> potionEffects = null;
|
||||
public List<DataPotionEffect> getPotionEffects() { return get(this.potionEffects, DEFAULT_POTION_EFFECTS); }
|
||||
public DataItemStack setPotionEffects(List<DataPotionEffect> potionEffects) { this.potionEffects = set(potionEffects, DEFAULT_POTION_EFFECTS); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > SKULL
|
||||
// -------------------------------------------- //
|
||||
|
||||
private String skull = null;
|
||||
public String getSkull() { return get(this.skull, DEFAULT_SKULL); }
|
||||
public DataItemStack setSkull(String skull) { this.skull = set(skull, DEFAULT_SKULL); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > FIREWORK EFFECT
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SerializedName("firework-effect")
|
||||
private DataFireworkEffect fireworkEffect = null;
|
||||
public DataFireworkEffect getFireworkEffect() { return get(this.fireworkEffect, DEFAULT_FIREWORK_EFFECT); }
|
||||
public DataItemStack setFireworkEffect(DataFireworkEffect fireworkEffect) { this.fireworkEffect = set(fireworkEffect, DEFAULT_FIREWORK_EFFECT); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > FIREWORK
|
||||
// -------------------------------------------- //
|
||||
|
||||
// TODO: Sorting?
|
||||
@SerializedName("firework-effects")
|
||||
private MassiveListDef<DataFireworkEffect> fireworkEffects = null;
|
||||
public List<DataFireworkEffect> getFireworkEffects() { return get(this.fireworkEffects, DEFAULT_FIREWORK_EFFECTS); }
|
||||
public DataItemStack setFireworkEffects(List<DataFireworkEffect> fireworkEffects) { this.fireworkEffects = set(fireworkEffects, DEFAULT_FIREWORK_EFFECTS); return this; }
|
||||
|
||||
// NOTE: Did not have a default specified.
|
||||
@SerializedName("firework-flight")
|
||||
private Integer fireworkFlight = null;
|
||||
public int getFireworkFlight() { return get(this.fireworkFlight, DEFAULT_FIREWORK_FLIGHT); }
|
||||
public DataItemStack setFireworkFlight(int fireworkFlight) { this.fireworkFlight = set(fireworkFlight, DEFAULT_FIREWORK_FLIGHT); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > STORED ENCHANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorTypeInner({TypeConverterEnchant.class, TypeInteger.class})
|
||||
@SerializedName("stored-enchants")
|
||||
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> storedEnchants = null;
|
||||
public Map<Integer, Integer> getStoredEnchants() { return get(this.storedEnchants, DEFAULT_STORED_ENCHANTS); }
|
||||
public DataItemStack setStoredEnchants(Map<Integer, Integer> storedEnchants) { this.storedEnchants = set(storedEnchants, DEFAULT_STORED_ENCHANTS); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > UNBREAKABLE
|
||||
// -------------------------------------------- //
|
||||
// SINCE: 1.8
|
||||
|
||||
private Boolean unbreakable = null;
|
||||
public boolean isUnbreakable() { return get(this.unbreakable, DEFAULT_UNBREAKABLE); }
|
||||
public DataItemStack setUnbreakable(boolean unbreakable) { this.unbreakable = set(unbreakable, DEFAULT_UNBREAKABLE); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > FLAGS
|
||||
// -------------------------------------------- //
|
||||
// SINCE: 1.8
|
||||
|
||||
@EditorTypeInner(TypeConverterItemFlag.class)
|
||||
private MassiveTreeSetDef<String, ComparatorSmart> flags = null;
|
||||
public Set<String> getFlags() { return get(this.flags, DEFAULT_FLAGS); }
|
||||
public DataItemStack setFlags(Set<String> flags) { this.flags = set(flags, DEFAULT_FLAGS); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > BANNER BASE
|
||||
// -------------------------------------------- //
|
||||
// SINCE: 1.8
|
||||
// The integer is the dye color byte representation.
|
||||
// Is actually nullable in Bukkit.
|
||||
|
||||
@EditorType(TypeConverterDyeColor.class)
|
||||
@SerializedName("banner-base")
|
||||
private Integer bannerBase = null;
|
||||
public Integer getBannerBase() { return get(this.bannerBase, DEFAULT_BANNER_BASE); }
|
||||
public DataItemStack setBannerBase(Integer bannerBase) { this.bannerBase = set(bannerBase, DEFAULT_BANNER_BASE); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > BANNER PATTERNS
|
||||
// -------------------------------------------- //
|
||||
// SINCE: 1.8
|
||||
// This should really be a list and not a set.
|
||||
// The order matters and is explicitly assigned.
|
||||
|
||||
@SerializedName("banner")
|
||||
private MassiveListDef<DataBannerPattern> bannerPatterns = null;
|
||||
public List<DataBannerPattern> getBannerPatterns() { return get(this.bannerPatterns, DEFAULT_BANNER_PATTERNS); }
|
||||
public DataItemStack setBannerPatterns(List<DataBannerPattern> bannerPatterns) { this.bannerPatterns = set(bannerPatterns, DEFAULT_BANNER_PATTERNS); return this;}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > POTION
|
||||
// -------------------------------------------- //
|
||||
// SINCE: 1.9
|
||||
|
||||
private String potion = null;
|
||||
public String getPotion() { return get(this.potion, DEFAULT_POTION); }
|
||||
public DataItemStack setPotion(String potion) { this.potion = set(potion, DEFAULT_POTION); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > INVENTORY
|
||||
// -------------------------------------------- //
|
||||
// SINCE: 1.8
|
||||
|
||||
@EditorVisible(false)
|
||||
private Map<Integer, DataItemStack> inventory = null;
|
||||
public Map<Integer, DataItemStack> getInventory() { return get(this.inventory, DEFAULT_INVENTORY); }
|
||||
public DataItemStack setInventory(Map<Integer, DataItemStack> inventory) { this.inventory = set(inventory, DEFAULT_INVENTORY); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > POTION COLOR
|
||||
// -------------------------------------------- //
|
||||
// SINCE: 1.11
|
||||
|
||||
@EditorType(TypeConverterColor.class)
|
||||
private Integer potionColor = null;
|
||||
public Integer getPotionColor() { return get(this.potionColor, DEFAULT_POTION_COLOR); }
|
||||
public DataItemStack setPotionColor(Integer potionColor) { this.potionColor = set(potionColor, DEFAULT_POTION_COLOR); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS > MAP COLOR
|
||||
// -------------------------------------------- //
|
||||
// Since 1.11
|
||||
|
||||
@EditorType(TypeConverterColor.class)
|
||||
private Integer mapColor = null;
|
||||
public Integer getMapColor() { return get(this.mapColor, DEFAULT_MAP_COLOR); }
|
||||
public DataItemStack setMapColor(Integer mapColor) { this.mapColor = set(mapColor, DEFAULT_MAP_COLOR); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public DataItemStack()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DataItemStack(ItemStack itemStack)
|
||||
{
|
||||
this.write(itemStack, false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void write(ItemStack itemStack, boolean a2b)
|
||||
{
|
||||
WriterItemStack.get().write(this, itemStack, a2b);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONVERT ONE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static DataItemStack fromBukkit(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack == null) return null;
|
||||
return new DataItemStack(itemStack);
|
||||
}
|
||||
|
||||
public ItemStack toBukkit()
|
||||
{
|
||||
// Create
|
||||
ItemStack ret = WriterItemStack.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ItemStack toBukkit(DataItemStack dataItemStack)
|
||||
{
|
||||
if (dataItemStack == null) return null;
|
||||
return dataItemStack.toBukkit();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONVERT MANY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static void fromBukkit(Iterable<ItemStack> itemStacks, Collection<DataItemStack> dataItemStacks)
|
||||
{
|
||||
for (ItemStack itemStack : itemStacks)
|
||||
{
|
||||
dataItemStacks.add(fromBukkit(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<DataItemStack> fromBukkit(Iterable<ItemStack> itemStacks)
|
||||
{
|
||||
// Create
|
||||
List<DataItemStack> ret = new MassiveList<>();
|
||||
|
||||
// Fill
|
||||
fromBukkit(itemStacks, ret);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <V> void fromBukkitKeys(Map<ItemStack, V> itemStacks, Map<DataItemStack, V> dataItemStacks)
|
||||
{
|
||||
for (Entry<ItemStack, V> entry : itemStacks.entrySet())
|
||||
{
|
||||
dataItemStacks.put(fromBukkit(entry.getKey()), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static <V> Map<DataItemStack, V> fromBukkitKeys(Map<ItemStack, V> itemStacks)
|
||||
{
|
||||
// Create
|
||||
Map<DataItemStack, V> ret = new MassiveMap<>();
|
||||
|
||||
// Fill
|
||||
fromBukkitKeys(itemStacks, ret);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <K> void fromBukkitValues(Map<K, ItemStack> itemStacks, Map<K, DataItemStack> dataItemStacks)
|
||||
{
|
||||
for (Entry<K, ItemStack> entry : itemStacks.entrySet())
|
||||
{
|
||||
dataItemStacks.put(entry.getKey(), fromBukkit(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
public static <K> Map<K, DataItemStack> fromBukkitValues(Map<K, ItemStack> itemStacks)
|
||||
{
|
||||
// Create
|
||||
Map<K, DataItemStack> ret = new MassiveMap<>();
|
||||
|
||||
// Fill
|
||||
fromBukkitValues(itemStacks, ret);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Map<Integer, DataItemStack> fromBukkitContents(ItemStack[] contents)
|
||||
{
|
||||
// Catch NullEmpty
|
||||
if (contents == null || contents.length == 0) return null;
|
||||
|
||||
// Create
|
||||
Map<Integer, DataItemStack> ret = new MassiveMap<>();
|
||||
|
||||
// Fill
|
||||
for (int i = 0; i < contents.length; i++)
|
||||
{
|
||||
ItemStack itemStack = contents[i];
|
||||
if (InventoryUtil.isNothing(itemStack)) continue;
|
||||
|
||||
ret.put(i, DataItemStack.fromBukkit(itemStack));
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ItemStack[] toBukkitContents(Map<Integer, DataItemStack> contents)
|
||||
{
|
||||
// Catch NullEmpty
|
||||
if (contents == null || contents.isEmpty()) return null;
|
||||
|
||||
// Create
|
||||
int max = Collections.max(contents.keySet());
|
||||
ItemStack[] ret = new ItemStack[max+1];
|
||||
|
||||
// Fill
|
||||
for (Entry<Integer, DataItemStack> entry: contents.entrySet())
|
||||
{
|
||||
int index = entry.getKey();
|
||||
DataItemStack item = entry.getValue();
|
||||
ret[index] = item.toBukkit();
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean isSomething(DataItemStack dataItemStack)
|
||||
{
|
||||
if (dataItemStack == null) return false;
|
||||
if (dataItemStack.getId().equals(DEFAULT_ID)) return false;
|
||||
// In Minecraft 1.9 zero quantity is a thing.
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNothing(DataItemStack dataItemStack)
|
||||
{
|
||||
return ! isSomething(dataItemStack);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COMPARE & EQUALS & HASHCODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compareTo(DataItemStack that)
|
||||
{
|
||||
return ComparatorSmart.get().compare(
|
||||
this.getId(), that.getId(),
|
||||
this.getCount(), that.getCount(),
|
||||
this.getDamage(), that.getDamage(),
|
||||
this.getName(), that.getName(),
|
||||
this.getLore(), that.getLore(),
|
||||
this.getEnchants(), that.getEnchants(),
|
||||
this.getRepaircost(), that.getRepaircost(),
|
||||
this.getTitle(), that.getTitle(),
|
||||
this.getAuthor(), that.getAuthor(),
|
||||
this.getPages(), that.getPages(),
|
||||
this.getColor(), that.getColor(),
|
||||
this.isScaling(), that.isScaling(),
|
||||
this.getPotionEffects(), that.getPotionEffects(),
|
||||
this.getSkull(), that.getSkull(),
|
||||
this.getFireworkEffect(), that.getFireworkEffect(),
|
||||
this.getFireworkEffects(), that.getFireworkEffects(),
|
||||
this.getFireworkFlight(), that.getFireworkFlight(),
|
||||
this.getStoredEnchants(), that.getStoredEnchants(),
|
||||
this.isUnbreakable(), that.isUnbreakable(),
|
||||
this.getFlags(), that.getFlags(),
|
||||
this.getBannerBase(), that.getBannerBase(),
|
||||
this.getBannerPatterns(), that.getBannerPatterns(),
|
||||
this.getPotion(), that.getPotion(),
|
||||
this.getInventory(), that.getInventory(),
|
||||
this.getPotionColor(), that.getPotionColor(),
|
||||
this.getMapColor(), that.getMapColor()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if ( ! (object instanceof DataItemStack)) return false;
|
||||
DataItemStack that = (DataItemStack)object;
|
||||
return MUtil.equals(
|
||||
this.getId(), that.getId(),
|
||||
this.getCount(), that.getCount(),
|
||||
this.getDamage(), that.getDamage(),
|
||||
this.getName(), that.getName(),
|
||||
this.getLore(), that.getLore(),
|
||||
this.getEnchants(), that.getEnchants(),
|
||||
this.getRepaircost(), that.getRepaircost(),
|
||||
this.getTitle(), that.getTitle(),
|
||||
this.getAuthor(), that.getAuthor(),
|
||||
this.getPages(), that.getPages(),
|
||||
this.getColor(), that.getColor(),
|
||||
this.isScaling(), that.isScaling(),
|
||||
this.getPotionEffects(), that.getPotionEffects(),
|
||||
this.getSkull(), that.getSkull(),
|
||||
this.getFireworkEffect(), that.getFireworkEffect(),
|
||||
this.getFireworkEffects(), that.getFireworkEffects(),
|
||||
this.getFireworkFlight(), that.getFireworkFlight(),
|
||||
this.getStoredEnchants(), that.getStoredEnchants(),
|
||||
this.isUnbreakable(), that.isUnbreakable(),
|
||||
this.getFlags(), that.getFlags(),
|
||||
this.getBannerBase(), that.getBannerBase(),
|
||||
this.getBannerPatterns(), that.getBannerPatterns(),
|
||||
this.getPotion(), that.getPotion(),
|
||||
this.getInventory(), that.getInventory(),
|
||||
this.getPotionColor(), that.getPotionColor(),
|
||||
this.getMapColor(), that.getMapColor()
|
||||
);
|
||||
}
|
||||
|
||||
public boolean equalsItem(ItemStack item)
|
||||
{
|
||||
if (item == null) return false;
|
||||
DataItemStack that = DataItemStack.fromBukkit(item);
|
||||
return this.equals(that);
|
||||
}
|
||||
|
||||
public boolean isSimilar(DataItemStack that)
|
||||
{
|
||||
// A copy of the equals logic above. However we comment out:
|
||||
// * Count
|
||||
// * Repaircost
|
||||
return MUtil.equals(
|
||||
this.getId(), that.getId(),
|
||||
// this.getCount(), that.getCount(),
|
||||
this.getDamage(), that.getDamage(),
|
||||
this.getName(), that.getName(),
|
||||
this.getLore(), that.getLore(),
|
||||
this.getEnchants(), that.getEnchants(),
|
||||
// this.getRepaircost(), that.getRepaircost(),
|
||||
this.getTitle(), that.getTitle(),
|
||||
this.getAuthor(), that.getAuthor(),
|
||||
this.getPages(), that.getPages(),
|
||||
this.getColor(), that.getColor(),
|
||||
this.isScaling(), that.isScaling(),
|
||||
this.getPotionEffects(), that.getPotionEffects(),
|
||||
this.getSkull(), that.getSkull(),
|
||||
this.getFireworkEffect(), that.getFireworkEffect(),
|
||||
this.getFireworkEffects(), that.getFireworkEffects(),
|
||||
this.getFireworkFlight(), that.getFireworkFlight(),
|
||||
this.getStoredEnchants(), that.getStoredEnchants(),
|
||||
this.isUnbreakable(), that.isUnbreakable(),
|
||||
this.getFlags(), that.getFlags(),
|
||||
this.getBannerBase(), that.getBannerBase(),
|
||||
this.getBannerPatterns(), that.getBannerPatterns(),
|
||||
this.getPotion(), that.getPotion(),
|
||||
this.getInventory(), that.getInventory(),
|
||||
this.getPotionColor(), that.getPotionColor(),
|
||||
this.getMapColor(), that.getMapColor()
|
||||
);
|
||||
}
|
||||
|
||||
public boolean isSimilarItem(ItemStack item)
|
||||
{
|
||||
if (item == null) return false;
|
||||
DataItemStack that = DataItemStack.fromBukkit(item);
|
||||
return this.isSimilar(that);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(
|
||||
this.getId(),
|
||||
this.getCount(),
|
||||
this.getDamage(),
|
||||
this.getName(),
|
||||
this.getLore(),
|
||||
this.getEnchants(),
|
||||
this.getRepaircost(),
|
||||
this.getTitle(),
|
||||
this.getAuthor(),
|
||||
this.getPages(),
|
||||
this.getColor(),
|
||||
this.isScaling(),
|
||||
this.getPotionEffects(),
|
||||
this.getSkull(),
|
||||
this.getFireworkEffect(),
|
||||
this.getFireworkEffects(),
|
||||
this.getFireworkFlight(),
|
||||
this.getStoredEnchants(),
|
||||
this.isUnbreakable(),
|
||||
this.getFlags(),
|
||||
this.getBannerBase(),
|
||||
this.getBannerPatterns(),
|
||||
this.getPotion(),
|
||||
this.getInventory(),
|
||||
this.getPotionColor(),
|
||||
this.getMapColor()
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// GET & SET & NOTHING
|
||||
// -------------------------------------------- //
|
||||
|
||||
// We treat null and empty collections the same.
|
||||
public static boolean isNothing(Object object)
|
||||
{
|
||||
if (object == null) return true;
|
||||
if (object instanceof Collection<?>) return ((Collection<?>)object).isEmpty();
|
||||
if (object instanceof Map<?, ?>) return ((Map<?, ?>)object).isEmpty();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return the value unless the value is nothing then return standard instead.
|
||||
public static <T> T get(T value, T standard)
|
||||
{
|
||||
if (isNothing(value)) return standard;
|
||||
return value;
|
||||
}
|
||||
|
||||
// Return the value unless the value is nothing or standard then return null instead.
|
||||
// Perform shallow copy on supported collections.
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <R, T> R set(T value, T standard)
|
||||
{
|
||||
if (isNothing(value)) return null;
|
||||
if (value.equals(standard)) return null;
|
||||
|
||||
if (value instanceof List<?>)
|
||||
{
|
||||
List<Object> list = (List<Object>)value;
|
||||
return (R) new MassiveListDef<>(list);
|
||||
}
|
||||
else if (value instanceof Set<?>)
|
||||
{
|
||||
Set<Object> set = (Set<Object>)value;
|
||||
return (R) new MassiveTreeSetDef<>(ComparatorSmart.get(), set);
|
||||
}
|
||||
else if (value instanceof Map<?, ?>)
|
||||
{
|
||||
Map<Object, Object> map = (Map<Object, Object>)value;
|
||||
return (R) new MassiveTreeMapDef<>(ComparatorSmart.get(), map);
|
||||
}
|
||||
|
||||
return (R) value;
|
||||
}
|
||||
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
|
||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterPotionEffectType;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.massivecraft.massivecore.item.DataItemStack.get;
|
||||
import static com.massivecraft.massivecore.item.DataItemStack.set;
|
||||
|
||||
@EditorMethods(true)
|
||||
public class DataPotionEffect implements Comparable<DataPotionEffect>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final transient Integer DEFAULT_ID = null;
|
||||
public static final transient Integer DEFAULT_DURATION = 20 * 3 * 60;
|
||||
public static final transient Integer DEFAULT_AMPLIFIER = 0;
|
||||
public static final transient Boolean DEFAULT_AMBIENT = false;
|
||||
public static final transient Boolean DEFAULT_PARTICLES = true;
|
||||
public static final transient Integer DEFAULT_COLOR = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EditorType(value = TypeConverterPotionEffectType.class)
|
||||
private Integer id = null;
|
||||
public Integer getId() { return get(this.id, DEFAULT_ID); }
|
||||
public DataPotionEffect setId(Integer id) { this.id = set(id, DEFAULT_ID); return this; }
|
||||
|
||||
private Integer duration = null;
|
||||
public int getDuration() { return get(this.duration, DEFAULT_DURATION); }
|
||||
public DataPotionEffect setDuration(int duration) { this.duration = set(duration, DEFAULT_DURATION); return this; }
|
||||
|
||||
private Integer amplifier = null;
|
||||
public int getAmplifier() { return get(this.amplifier, DEFAULT_AMPLIFIER); }
|
||||
public DataPotionEffect setAmplifier(int amplifier) { this.amplifier = set(amplifier, DEFAULT_AMPLIFIER); return this; }
|
||||
|
||||
private Boolean ambient = null;
|
||||
public boolean isAmbient() { return get(this.ambient, DEFAULT_AMBIENT); }
|
||||
public DataPotionEffect setAmbient(boolean ambient) { this.ambient = set(ambient, DEFAULT_AMBIENT); return this; }
|
||||
|
||||
// SINCE: 1.8
|
||||
private Boolean particles = null;
|
||||
public boolean isParticles() { return get(this.particles, DEFAULT_PARTICLES); }
|
||||
public DataPotionEffect setParticles(boolean particles) { this.particles = set(particles, DEFAULT_PARTICLES); return this; }
|
||||
|
||||
// SINCE: 1.9
|
||||
@EditorType(TypeConverterColor.class)
|
||||
private Integer color = null;
|
||||
public Integer getColor() { return get(this.color, DEFAULT_COLOR); }
|
||||
public DataPotionEffect setColor(Integer color) { this.color = set(color, DEFAULT_COLOR); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public DataPotionEffect()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DataPotionEffect(PotionEffect potionEffect)
|
||||
{
|
||||
this.write(potionEffect, false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void write(PotionEffect potionEffect, boolean a2b)
|
||||
{
|
||||
WriterPotionEffect.get().write(this, potionEffect, a2b);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TO BUKKIT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public PotionEffect toBukkit()
|
||||
{
|
||||
// Create
|
||||
PotionEffect ret = WriterPotionEffect.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COMPARE & EQUALS & HASHCODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compareTo(DataPotionEffect that)
|
||||
{
|
||||
return ComparatorSmart.get().compare(
|
||||
this.getId(), that.getId(),
|
||||
this.getDuration(), that.getDuration(),
|
||||
this.getAmplifier(), that.getAmplifier(),
|
||||
this.isAmbient(), that.isAmbient(),
|
||||
this.isParticles(), that.isParticles(),
|
||||
this.getColor(), that.getColor()
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Use compare instead to avoid bugs?
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if ( ! (object instanceof DataPotionEffect)) return false;
|
||||
DataPotionEffect that = (DataPotionEffect)object;
|
||||
|
||||
return MUtil.equals(
|
||||
this.getId(), that.getId(),
|
||||
this.getDuration(), that.getDuration(),
|
||||
this.getAmplifier(), that.getAmplifier(),
|
||||
this.isAmbient(), that.isAmbient(),
|
||||
this.isParticles(), that.isParticles(),
|
||||
this.getColor(), that.getColor()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(
|
||||
this.getId(),
|
||||
this.getDuration(),
|
||||
this.getAmplifier(),
|
||||
this.isAmbient(),
|
||||
this.isParticles(),
|
||||
this.getColor()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PotionUtil
|
||||
{
|
||||
public static PotionData toPotionData(int damage)
|
||||
{
|
||||
try
|
||||
{
|
||||
Potion potion = Potion.fromDamage(damage);
|
||||
PotionType type = potion.getType();
|
||||
boolean extended = potion.hasExtendedDuration();
|
||||
boolean upgraded = (potion.getLevel() >= 2);
|
||||
|
||||
// This section serves two purposes:
|
||||
// 1. Avoid slow exceptions over for invalid damage values.
|
||||
// 2. Lenient upgrade to Minecraft 1.9. Keep what we can.
|
||||
// If a potion was both upgraded and extended we keep the upgraded and remove the extended.
|
||||
if (type == null) return null;
|
||||
if (extended && ! type.isExtendable()) return null;
|
||||
if (upgraded && ! type.isUpgradeable()) return null;
|
||||
if (upgraded && extended) extended = false;
|
||||
|
||||
return new PotionData(type, extended, upgraded);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static PotionData toPotionData(String potionString)
|
||||
{
|
||||
if (potionString == null) return null;
|
||||
return POTION_ID_TO_DATA.get(potionString);
|
||||
}
|
||||
|
||||
public static String toPotionString(PotionData potionData)
|
||||
{
|
||||
if (potionData == null) return null;
|
||||
return POTION_ID_TO_DATA.inverse().get(potionData);
|
||||
}
|
||||
|
||||
private static final BiMap<String, PotionData> POTION_ID_TO_DATA = ImmutableBiMap.<String, PotionData>builder()
|
||||
// REGULAR
|
||||
.put("empty", new PotionData(PotionType.UNCRAFTABLE, false, false))
|
||||
.put("water", new PotionData(PotionType.WATER, false, false))
|
||||
.put("mundane", new PotionData(PotionType.MUNDANE, false, false))
|
||||
.put("thick", new PotionData(PotionType.THICK, false, false))
|
||||
.put("awkward", new PotionData(PotionType.AWKWARD, false, false))
|
||||
.put("night_vision", new PotionData(PotionType.NIGHT_VISION, false, false))
|
||||
.put("invisibility", new PotionData(PotionType.INVISIBILITY, false, false))
|
||||
.put("leaping", new PotionData(PotionType.JUMP, false, false))
|
||||
.put("fire_resistance", new PotionData(PotionType.FIRE_RESISTANCE, false, false))
|
||||
.put("swiftness", new PotionData(PotionType.SPEED, false, false))
|
||||
.put("slowness", new PotionData(PotionType.SLOWNESS, false, false))
|
||||
.put("water_breathing", new PotionData(PotionType.WATER_BREATHING, false, false))
|
||||
.put("healing", new PotionData(PotionType.INSTANT_HEAL, false, false))
|
||||
.put("harming", new PotionData(PotionType.INSTANT_DAMAGE, false, false))
|
||||
.put("poison", new PotionData(PotionType.POISON, false, false))
|
||||
.put("regeneration", new PotionData(PotionType.REGEN, false, false))
|
||||
.put("strength", new PotionData(PotionType.STRENGTH, false, false))
|
||||
.put("weakness", new PotionData(PotionType.WEAKNESS, false, false))
|
||||
.put("luck", new PotionData(PotionType.LUCK, false, false))
|
||||
|
||||
// UPGRADABLE
|
||||
.put("strong_leaping", new PotionData(PotionType.JUMP, false, true))
|
||||
.put("strong_swiftness", new PotionData(PotionType.SPEED, false, true))
|
||||
.put("strong_healing", new PotionData(PotionType.INSTANT_HEAL, false, true))
|
||||
.put("strong_harming", new PotionData(PotionType.INSTANT_DAMAGE, false, true))
|
||||
.put("strong_poison", new PotionData(PotionType.POISON, false, true))
|
||||
.put("strong_regeneration", new PotionData(PotionType.REGEN, false, true))
|
||||
.put("strong_strength", new PotionData(PotionType.STRENGTH, false, true))
|
||||
|
||||
// EXTENDABLE
|
||||
.put("long_night_vision", new PotionData(PotionType.NIGHT_VISION, true, false))
|
||||
.put("long_invisibility", new PotionData(PotionType.INVISIBILITY, true, false))
|
||||
.put("long_leaping", new PotionData(PotionType.JUMP, true, false))
|
||||
.put("long_fire_resistance", new PotionData(PotionType.FIRE_RESISTANCE, true, false))
|
||||
.put("long_swiftness", new PotionData(PotionType.SPEED, true, false))
|
||||
.put("long_slowness", new PotionData(PotionType.SLOWNESS, true, false))
|
||||
.put("long_water_breathing", new PotionData(PotionType.WATER_BREATHING, true, false))
|
||||
.put("long_poison", new PotionData(PotionType.POISON, true, false))
|
||||
.put("long_regeneration", new PotionData(PotionType.REGEN, true, false))
|
||||
.put("long_strength", new PotionData(PotionType.STRENGTH, true, false))
|
||||
.put("long_weakness", new PotionData(PotionType.WEAKNESS, true, false))
|
||||
|
||||
// BUILD
|
||||
.build();
|
||||
|
||||
}
|
@ -1,329 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import com.massivecraft.massivecore.MassiveCoreMConf;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// A = What we are writing from.
|
||||
// B = What we are writing to.
|
||||
//
|
||||
// O = The base object. Not yet morphed into specific class.
|
||||
// C = The specific class object. Often the same as O but at times very different.
|
||||
// F = The field class. Used for field writing.
|
||||
//
|
||||
// D = The data class. Used for sending arbitrary data along.
|
||||
//
|
||||
// TIP: Simply set to Object if you are not using a certain generic.
|
||||
//
|
||||
public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstract(Class<CA> classCA, Class<CB> classCB)
|
||||
{
|
||||
this.classCA = classCA;
|
||||
this.classCB = classCB;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITERS
|
||||
// -------------------------------------------- //
|
||||
// Writer have dependencies and child writers.
|
||||
|
||||
// A dependency is another writer that must be successfully activated for this writer to function.
|
||||
// For that reason the dependencies are activated just after the setup logic.
|
||||
// Examples would be WriterPotionEffect and WriterFireworkEffect.
|
||||
// They are implicitly required for some ItemStack field writers.
|
||||
private List<Class<?>> dependencyClasses = new MassiveList<>();
|
||||
public List<Class<?>> getDependencyClasses() { return this.dependencyClasses; }
|
||||
public void addDependencyClasses(Class<?>... dependencyClasses) { this.getDependencyClasses().addAll(Arrays.asList(dependencyClasses)); }
|
||||
|
||||
// This is the writer classes scheduled to be used at setup.
|
||||
// We do not yet know if they are compatible with this Minecraft version.
|
||||
// All, some or none of them may fail.
|
||||
private List<Class<?>> writerClasses = new MassiveList<>();
|
||||
public List<Class<?>> getWriterClasses() { return this.writerClasses; }
|
||||
public void addWriterClasses(Class<?>... writerClasses) { this.getWriterClasses().addAll(Arrays.asList(writerClasses)); }
|
||||
|
||||
// These are the actually functional child writers.
|
||||
// This list should only contain writers that passed the setup routine.
|
||||
private List<WriterAbstract<CA, CB, ?, ?, ?, ?, D>> writers = new MassiveList<>();
|
||||
public List<WriterAbstract<CA, CB, ?, ?, ?, ?, D>> getWriters() { return this.writers; }
|
||||
|
||||
// Here is the logic to perform the dependency and child writer setup.
|
||||
public void setupDependencies()
|
||||
{
|
||||
for (Class<?> dependencyClass : this.getDependencyClasses())
|
||||
{
|
||||
this.setupWriter(dependencyClass, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setupWriters()
|
||||
{
|
||||
for (Class<?> writerClass : this.getWriterClasses())
|
||||
{
|
||||
this.setupWriter(writerClass, true);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setupWriter(Class<?> writerClass, boolean add)
|
||||
{
|
||||
try
|
||||
{
|
||||
WriterAbstract<?, ?, ?, ?, ?, ?, ?> writer = ReflectionUtil.getSingletonInstance(writerClass);
|
||||
|
||||
if ( ! writer.isActive()) writer.setActive(this.getActivePlugin());
|
||||
|
||||
if (add) this.getWriters().add((WriterAbstract<CA, CB, ?, ?, ?, ?, D>)writer);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
this.reportSuccess(false, writerClass.getSimpleName(), t);
|
||||
}
|
||||
}
|
||||
|
||||
public void reportSuccess(boolean success)
|
||||
{
|
||||
this.reportSuccess(success, this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public void reportSuccess(boolean success, String name)
|
||||
{
|
||||
this.reportSuccess(success, name, null);
|
||||
}
|
||||
|
||||
public void reportSuccess(boolean success, String name, Throwable t)
|
||||
{
|
||||
if ( ! MassiveCoreMConf.get().debugEnabled) return;
|
||||
|
||||
// Create
|
||||
List<String> messages = new MassiveList<>();
|
||||
|
||||
// Fill
|
||||
String message;
|
||||
|
||||
// Main
|
||||
message = Txt.parse("<h>%s %s", name, TypeBooleanOn.get().getVisual(success));
|
||||
messages.add(message);
|
||||
|
||||
// Throwable
|
||||
if (t != null)
|
||||
{
|
||||
message = Txt.parse("<b>### %s <i>%s", t.getClass().getSimpleName(), t.getMessage());
|
||||
messages.add(message);
|
||||
for (String s : MUtil.getStackTraceStrings(Arrays.asList(t.getStackTrace()), true))
|
||||
{
|
||||
message = Txt.parse("<b>--> %s", s);
|
||||
messages.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
// Send
|
||||
for (String s : messages)
|
||||
{
|
||||
this.getActivePlugin().log(s);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACTIVE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
// Setup Self
|
||||
this.setupSelf();
|
||||
|
||||
// Setup Dependencies
|
||||
this.setupDependencies();
|
||||
|
||||
// Report This Success
|
||||
this.reportSuccess(true);
|
||||
|
||||
// Setup Writers
|
||||
this.setupWriters();
|
||||
}
|
||||
|
||||
super.setActive(active);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public OA createOA()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public OB createOB()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CLASSES
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Class<CA> classCA;
|
||||
public Class<CA> getClassCA() { return this.classCA; }
|
||||
|
||||
private final Class<CB> classCB;
|
||||
public Class<CB> getClassCB() { return this.classCB; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MORPH
|
||||
// -------------------------------------------- //
|
||||
// Per default the morph is just a secure cast.
|
||||
// If the morph fails it means the writer was not applicable.
|
||||
// In those cases we don't want a crash.
|
||||
// We rather silently continue.
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CA morphA(OA oa)
|
||||
{
|
||||
if (this.getClassCA() != null && ! this.getClassCA().isAssignableFrom(oa.getClass())) return null;
|
||||
return (CA)oa;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CB morphB(OB ob)
|
||||
{
|
||||
if (this.getClassCB() != null && ! this.getClassCB().isAssignableFrom(ob.getClass())) return null;
|
||||
return (CB)ob;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SETUP
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void setupSelf()
|
||||
{
|
||||
// Create O
|
||||
OA oa = this.createOA();
|
||||
OB ob = this.createOB();
|
||||
|
||||
// Demand O
|
||||
if (oa == null) throw new NullPointerException("Couldn't Create OA");
|
||||
if (ob == null) throw new NullPointerException("Couldn't Create OB");
|
||||
|
||||
// Morph
|
||||
CA ca = this.morphA(oa);
|
||||
CB cb = this.morphB(ob);
|
||||
|
||||
// Demand C
|
||||
if (ca == null) throw new NullPointerException("Couldn't Create CA");
|
||||
if (cb == null) throw new NullPointerException("Couldn't Create CB");
|
||||
|
||||
// Write (to provoke extra much)
|
||||
this.write(oa, ob, true);
|
||||
this.write(oa, ob, false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void write(OA oa, OB ob, boolean a2b)
|
||||
{
|
||||
this.write(oa, ob, null, a2b);
|
||||
}
|
||||
|
||||
public void write(OA oa, OB ob, D d, boolean a2b)
|
||||
{
|
||||
// if ( ! this.isActive()) throw new IllegalStateException("not active " + this.getClass().getName());
|
||||
|
||||
if (oa == null) throw new NullPointerException("oa");
|
||||
if (ob == null) throw new NullPointerException("ob");
|
||||
|
||||
CA ca = this.morphA(oa);
|
||||
if (ca == null) return;
|
||||
|
||||
CB cb = this.morphB(ob);
|
||||
if (cb == null) return;
|
||||
|
||||
this.writeInner(oa, ob, ca, cb, d, a2b);
|
||||
}
|
||||
|
||||
public void writeInner(OA oa, OB ob, CA ca, CB cb, D d, boolean a2b)
|
||||
{
|
||||
for (WriterAbstract<CA, CB, ?, ?, ?, ?, D> writer : this.getWriters())
|
||||
{
|
||||
writer.write(ca, cb, d, a2b);
|
||||
}
|
||||
|
||||
if (a2b)
|
||||
{
|
||||
FA fa = getA(ca, d);
|
||||
FB fb = toB(fa);
|
||||
setB(cb, fb, d);
|
||||
}
|
||||
else
|
||||
{
|
||||
FB fb = getB(cb, d);
|
||||
FA fa = toA(fb);
|
||||
setA(ca, fa, d);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FA getA(CA ca, D d)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setA(CA ca, FA fa, D d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FB getB(CB cb, D d)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setB(CB cb, FB fb, D d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONVERT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Converter<? super FA, FB> converterTo = ConverterDefault.get();
|
||||
public Converter<? super FA, FB> getConverterTo() { return this.converterTo; }
|
||||
public void setConverterTo(Converter<? super FA, FB> converterTo) { this.converterTo = converterTo; }
|
||||
|
||||
private Converter<? super FB, FA> converterFrom = ConverterDefault.get();
|
||||
public Converter<? super FB, FA> getConverterFrom() { return this.converterFrom; }
|
||||
public void setConverterFrom(Converter<? super FB, FA> converterFrom) { this.converterFrom = converterFrom; }
|
||||
|
||||
public FA toA(FB fb)
|
||||
{
|
||||
return this.getConverterFrom().convert(fb);
|
||||
}
|
||||
|
||||
public FB toB(FA fa)
|
||||
{
|
||||
return this.getConverterTo().convert(fa);
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
|
||||
|
||||
public abstract class WriterAbstractBannerPattern<FA, FB> extends WriterAbstractReflect<DataBannerPattern, Pattern, DataBannerPattern, Pattern, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractBannerPattern(String fieldName)
|
||||
{
|
||||
super(Pattern.class, fieldName);
|
||||
}
|
||||
|
||||
public WriterAbstractBannerPattern()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataBannerPattern createOA()
|
||||
{
|
||||
return new DataBannerPattern();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern createOB()
|
||||
{
|
||||
return new Pattern(DyeColor.WHITE, PatternType.BASE);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
|
||||
public abstract class WriterAbstractFireworkEffect<FA, FB> extends WriterAbstractReflect<DataFireworkEffect, FireworkEffect, DataFireworkEffect, FireworkEffect, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractFireworkEffect(String fieldName)
|
||||
{
|
||||
super(FireworkEffect.class, fieldName);
|
||||
}
|
||||
|
||||
public WriterAbstractFireworkEffect()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataFireworkEffect createOA()
|
||||
{
|
||||
return new DataFireworkEffect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireworkEffect createOB()
|
||||
{
|
||||
return FireworkEffect.builder().withColor(Color.GREEN).build();
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.nms.NmsItemStackCreate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class WriterAbstractItemStack<OB, CB, FA, FB> extends WriterAbstract<DataItemStack, OB, DataItemStack, CB, FA, FB, ItemStack>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStack(Class<CB> classCB)
|
||||
{
|
||||
super(DataItemStack.class, classCB);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Material material = Material.STONE;
|
||||
public Material getMaterial() { return this.material; }
|
||||
public void setMaterial(Material material) { this.material = material; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataItemStack createOA()
|
||||
{
|
||||
return new DataItemStack();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public OB createOB()
|
||||
{
|
||||
return (OB) this.createItemStack();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE INNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ItemStack createItemStack()
|
||||
{
|
||||
ItemStack ret = NmsItemStackCreate.get().create();
|
||||
ret.setType(this.getMaterial());
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE & WRITE
|
||||
// -------------------------------------------- //
|
||||
// We some times need to access the ItemStack even at deeper levels of writing.
|
||||
// With that in mind we pass it along in the data generic.
|
||||
|
||||
@Override
|
||||
public void writeInner(DataItemStack oa, OB ob, DataItemStack ca, CB cb, ItemStack d, boolean a2b)
|
||||
{
|
||||
// Ensure there is an ItemStack data. Create if necessary (used by setup method).
|
||||
if (d == null) d = (ItemStack)((ob instanceof ItemStack) ? ob : this.createItemStack());
|
||||
super.writeInner(oa, ob, ca, cb, d, a2b);
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class WriterAbstractItemStackField<FA, FB> extends WriterAbstractItemStack<ItemStack, ItemStack, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackField()
|
||||
{
|
||||
super(ItemStack.class);
|
||||
}
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMeta<OB, CB, FA, FB> extends WriterAbstractItemStack<OB, CB, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMeta(Class<CB> classCB)
|
||||
{
|
||||
super(classCB);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE INNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ItemMeta createItemMeta()
|
||||
{
|
||||
return createItemMeta(this.createItemStack());
|
||||
}
|
||||
|
||||
public static ItemMeta createItemMeta(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.getItemMeta();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BANNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static Banner getBanner(BlockStateMeta meta, boolean creative)
|
||||
{
|
||||
// Null
|
||||
if (meta == null) return null;
|
||||
|
||||
// Creative
|
||||
if (!meta.hasBlockState() && !creative) return null;
|
||||
|
||||
// Try
|
||||
try
|
||||
{
|
||||
BlockState ret = meta.getBlockState();
|
||||
if ( ! (ret instanceof Banner)) return null;
|
||||
return (Banner)ret;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Catch errors such as: throw new IllegalStateException("Missing blockState for " + material);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBanner(BlockStateMeta meta, Banner banner)
|
||||
{
|
||||
// Null
|
||||
if (meta == null) return;
|
||||
if (banner == null) return;
|
||||
|
||||
// Dodge Update NPE
|
||||
if (banner.getBaseColor() == null) return;
|
||||
|
||||
// Update with Force without Physics
|
||||
banner.update(true, false);
|
||||
|
||||
// Apply
|
||||
meta.setBlockState(banner);
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaField<CB, FA, FB> extends WriterAbstractItemStackMeta<ItemMeta, CB, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMetaField(Class<CB> classCB)
|
||||
{
|
||||
super(classCB);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ItemMeta createOB()
|
||||
{
|
||||
return this.createItemMeta();
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaMorph<FA, FB> extends WriterAbstractItemStackMeta<ItemStack, ItemMeta, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMetaMorph()
|
||||
{
|
||||
super(ItemMeta.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MORPH
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ItemMeta morphB(ItemStack ob)
|
||||
{
|
||||
return createItemMeta(ob);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void writeInner(DataItemStack oa, ItemStack ob, DataItemStack ca, ItemMeta cb, ItemStack d, boolean a2b)
|
||||
{
|
||||
super.writeInner(oa, ob, ca, cb, d, a2b);
|
||||
|
||||
// Write Back
|
||||
if (a2b) ob.setItemMeta(cb);
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public abstract class WriterAbstractPotionEffect<FA, FB> extends WriterAbstractReflect<DataPotionEffect, PotionEffect, DataPotionEffect, PotionEffect, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractPotionEffect(String fieldName)
|
||||
{
|
||||
super(PotionEffect.class, fieldName);
|
||||
}
|
||||
|
||||
public WriterAbstractPotionEffect()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataPotionEffect createOA()
|
||||
{
|
||||
return new DataPotionEffect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionEffect createOB()
|
||||
{
|
||||
return new PotionEffect(PotionEffectType.SPEED, 1, 1);
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public abstract class WriterAbstractReflect<OA, OB, CA, CB, FA, FB> extends WriterAbstract<OA, OB, CA, CB, FA, FB, Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Field field;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractReflect(Class<?> clazz, String fieldName)
|
||||
{
|
||||
super(null, null);
|
||||
this.field = (fieldName == null ? null : ReflectionUtil.getField(clazz, fieldName));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setB(CB cb, FB fb, Object d)
|
||||
{
|
||||
if (this.field == null) return;
|
||||
ReflectionUtil.setField(this.field, cb, fb);
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
public class WriterBannerPattern extends WriterAbstractBannerPattern<Object, Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterBannerPattern i = new WriterBannerPattern();
|
||||
public static WriterBannerPattern get() { return i; }
|
||||
public WriterBannerPattern()
|
||||
{
|
||||
this.addWriterClasses(
|
||||
WriterBannerPatternId.class,
|
||||
WriterBannerPatternColor.class
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
|
||||
public class WriterBannerPatternColor extends WriterAbstractBannerPattern<Integer, DyeColor>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterBannerPatternColor i = new WriterBannerPatternColor();
|
||||
public static WriterBannerPatternColor get() { return i; }
|
||||
public WriterBannerPatternColor()
|
||||
{
|
||||
super("color");
|
||||
this.setConverterTo(ConverterToDyeColor.get());
|
||||
this.setConverterFrom(ConverterFromDyeColor.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataBannerPattern ca, Object d)
|
||||
{
|
||||
return ca.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataBannerPattern ca, Integer fa, Object d)
|
||||
{
|
||||
ca.setColor(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getB(Pattern cb, Object d)
|
||||
{
|
||||
return cb.getColor();
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
|
||||
public class WriterBannerPatternId extends WriterAbstractBannerPattern<String, PatternType>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterBannerPatternId i = new WriterBannerPatternId();
|
||||
public static WriterBannerPatternId get() { return i; }
|
||||
public WriterBannerPatternId()
|
||||
{
|
||||
super("pattern");
|
||||
this.setConverterTo(ConverterToBannerPatternType.get());
|
||||
this.setConverterFrom(ConverterFromBannerPatternType.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataBannerPattern ca, Object d)
|
||||
{
|
||||
return ca.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataBannerPattern ca, String fa, Object d)
|
||||
{
|
||||
ca.setId(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PatternType getB(Pattern cb, Object d)
|
||||
{
|
||||
return cb.getPattern();
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
public class WriterFireworkEffect extends WriterAbstractFireworkEffect<Object, Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterFireworkEffect i = new WriterFireworkEffect();
|
||||
public static WriterFireworkEffect get() { return i; }
|
||||
public WriterFireworkEffect()
|
||||
{
|
||||
this.addWriterClasses(
|
||||
WriterFireworkEffectFlicker.class,
|
||||
WriterFireworkEffectTrail.class,
|
||||
WriterFireworkEffectColors.class,
|
||||
WriterFireworkEffectFadeColors.class,
|
||||
WriterFireworkEffectType.class
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect<List<Integer>, ImmutableList<Color>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterFireworkEffectColors i = new WriterFireworkEffectColors();
|
||||
public static WriterFireworkEffectColors get() { return i; }
|
||||
public WriterFireworkEffectColors()
|
||||
{
|
||||
super("colors");
|
||||
this.setConverterTo(ConverterToColors.get());
|
||||
this.setConverterFrom(ConverterFromColors.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<Integer> getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.getColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, List<Integer> fa, Object d)
|
||||
{
|
||||
ca.setColors(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Color> getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return (ImmutableList<Color>) cb.getColors();
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect<List<Integer>, ImmutableList<Color>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterFireworkEffectFadeColors i = new WriterFireworkEffectFadeColors();
|
||||
public static WriterFireworkEffectFadeColors get() { return i; }
|
||||
public WriterFireworkEffectFadeColors()
|
||||
{
|
||||
super("fadeColors");
|
||||
this.setConverterTo(ConverterToColors.get());
|
||||
this.setConverterFrom(ConverterFromColors.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<Integer> getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.getFadeColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, List<Integer> fa, Object d)
|
||||
{
|
||||
ca.setFadeColors(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Color> getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return (ImmutableList<Color>) cb.getFadeColors();
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
public class WriterFireworkEffectFlicker extends WriterAbstractFireworkEffect<Boolean, Boolean>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterFireworkEffectFlicker i = new WriterFireworkEffectFlicker();
|
||||
public static WriterFireworkEffectFlicker get() { return i; }
|
||||
public WriterFireworkEffectFlicker()
|
||||
{
|
||||
super("flicker");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.hasFlicker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, Boolean fa, Object d)
|
||||
{
|
||||
ca.setFlicker(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return cb.hasFlicker();
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
|
||||
public class WriterFireworkEffectTrail extends WriterAbstractFireworkEffect<Boolean, Boolean>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterFireworkEffectTrail i = new WriterFireworkEffectTrail();
|
||||
public static WriterFireworkEffectTrail get() { return i; }
|
||||
public WriterFireworkEffectTrail()
|
||||
{
|
||||
super("trail");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.hasTrail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, Boolean fa, Object d)
|
||||
{
|
||||
ca.setTrail(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return cb.hasTrail();
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
|
||||
public class WriterFireworkEffectType extends WriterAbstractFireworkEffect<String, Type>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterFireworkEffectType i = new WriterFireworkEffectType();
|
||||
public static WriterFireworkEffectType get() { return i; }
|
||||
public WriterFireworkEffectType()
|
||||
{
|
||||
super("type");
|
||||
this.setConverterTo(ConverterToFireworkEffectType.get());
|
||||
this.setConverterFrom(ConverterFromFireworkEffectType.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, String fa, Object d)
|
||||
{
|
||||
ca.setType(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return cb.getType();
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
public class WriterItemStack extends WriterAbstractItemStackField<Object, Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStack i = new WriterItemStack();
|
||||
public static WriterItemStack get() { return i; }
|
||||
public WriterItemStack()
|
||||
{
|
||||
this.addWriterClasses(
|
||||
// BASIC
|
||||
WriterItemStackId.class,
|
||||
WriterItemStackCount.class,
|
||||
WriterItemStackDamage.class,
|
||||
|
||||
// META
|
||||
WriterItemStackMeta.class
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WriterItemStackCount extends WriterAbstractItemStackField<Integer, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackCount i = new WriterItemStackCount();
|
||||
public static WriterItemStackCount get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setCount(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(ItemStack cb, ItemStack d)
|
||||
{
|
||||
return cb.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemStack cb, Integer fb, ItemStack d)
|
||||
{
|
||||
cb.setAmount(fb);
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WriterItemStackDamage extends WriterAbstractItemStackField<Integer, Integer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackDamage i = new WriterItemStackDamage();
|
||||
public static WriterItemStackDamage get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setDamage(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(ItemStack cb, ItemStack d)
|
||||
{
|
||||
return Integer.valueOf(cb.getDurability());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemStack cb, Integer fb, ItemStack d)
|
||||
{
|
||||
cb.setDurability(fb.shortValue());
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WriterItemStackId extends WriterAbstractItemStackField<String, Material>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackId i = new WriterItemStackId();
|
||||
public static WriterItemStackId get() { return i; }
|
||||
public WriterItemStackId()
|
||||
{
|
||||
this.setConverterTo(ConverterToMaterial.get());
|
||||
this.setConverterFrom(ConverterFromMaterial.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, String fa, ItemStack d)
|
||||
{
|
||||
ca.setId(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getB(ItemStack cb, ItemStack d)
|
||||
{
|
||||
return cb.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemStack cb, Material fb, ItemStack d)
|
||||
{
|
||||
cb.setType(fb);
|
||||
}
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
public class WriterItemStackMeta extends WriterAbstractItemStackMetaMorph<Object, Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackMeta i = new WriterItemStackMeta();
|
||||
public static WriterItemStackMeta get() { return i; }
|
||||
public WriterItemStackMeta()
|
||||
{
|
||||
this.addWriterClasses(
|
||||
// UNSPECIFIC
|
||||
WriterItemStackMetaName.class,
|
||||
WriterItemStackMetaLore.class,
|
||||
WriterItemStackMetaEnchants.class,
|
||||
WriterItemStackMetaRepaircost.class,
|
||||
|
||||
// BOOK
|
||||
WriterItemStackMetaTitle.class,
|
||||
WriterItemStackMetaAuthor.class,
|
||||
WriterItemStackMetaPages.class,
|
||||
|
||||
// LEATHER ARMOR
|
||||
WriterItemStackMetaColor.class,
|
||||
|
||||
// MAP
|
||||
WriterItemStackMetaScaling.class,
|
||||
WriterItemStackMetaMapColor.class,
|
||||
|
||||
// POTION EFFECTS
|
||||
WriterItemStackMetaPotionEffects.class,
|
||||
|
||||
// SKULL
|
||||
WriterItemStackMetaSkull.class,
|
||||
|
||||
// FIREWORK EFFECT
|
||||
WriterItemStackMetaFireworkEffect.class,
|
||||
|
||||
// FIREWORK
|
||||
WriterItemStackMetaFireworkEffects.class,
|
||||
WriterItemStackMetaFireworkFlight.class,
|
||||
|
||||
// STORED ENCHANTS
|
||||
WriterItemStackMetaStoredEnchants.class,
|
||||
|
||||
// UNBREAKABLE
|
||||
WriterItemStackMetaUnbreakable.class,
|
||||
|
||||
// FLAGS
|
||||
WriterItemStackMetaFlags.class,
|
||||
|
||||
// BANNER
|
||||
WriterItemStackMetaBannerBase.class,
|
||||
WriterItemStackMetaBannerPatterns.class,
|
||||
|
||||
// SHIELD
|
||||
WriterItemStackMetaShieldBase.class,
|
||||
WriterItemStackMetaShieldPatterns.class,
|
||||
|
||||
// POTION
|
||||
WriterItemStackMetaPotion.class,
|
||||
WriterItemStackMetaPotionColor.class,
|
||||
|
||||
// INVENTORY
|
||||
WriterItemStackMetaInventory.class
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
public class WriterItemStackMetaAuthor extends WriterAbstractItemStackMetaField<BookMeta, String, String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackMetaAuthor i = new WriterItemStackMetaAuthor();
|
||||
public static WriterItemStackMetaAuthor get() { return i; }
|
||||
|
||||
public WriterItemStackMetaAuthor()
|
||||
{
|
||||
super(BookMeta.class);
|
||||
this.setMaterial(Material.WRITTEN_BOOK);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getAuthor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, String fa, ItemStack d)
|
||||
{
|
||||
ca.setAuthor(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getB(BookMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getAuthor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BookMeta cb, String fb, ItemStack d)
|
||||
{
|
||||
cb.setAuthor(fb);
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
|
||||
public class WriterItemStackMetaBannerBase extends WriterAbstractItemStackMetaField<BannerMeta, Integer, DyeColor>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackMetaBannerBase i = new WriterItemStackMetaBannerBase();
|
||||
public static WriterItemStackMetaBannerBase get() { return i; }
|
||||
public WriterItemStackMetaBannerBase()
|
||||
{
|
||||
super(BannerMeta.class);
|
||||
this.setMaterial(Material.BANNER);
|
||||
this.setConverterTo(ConverterToDyeColor.get());
|
||||
this.setConverterFrom(ConverterFromDyeColor.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getBannerBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setBannerBase(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getB(BannerMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getBaseColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BannerMeta cb, DyeColor fb, ItemStack d)
|
||||
{
|
||||
cb.setBaseColor(fb);
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMetaField<BannerMeta, List<DataBannerPattern>, List<Pattern>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackMetaBannerPatterns i = new WriterItemStackMetaBannerPatterns();
|
||||
public static WriterItemStackMetaBannerPatterns get() { return i; }
|
||||
public WriterItemStackMetaBannerPatterns()
|
||||
{
|
||||
super(BannerMeta.class);
|
||||
this.setMaterial(Material.BANNER);
|
||||
this.setConverterTo(ConverterToBannerPatterns.get());
|
||||
this.setConverterFrom(ConverterFromBannerPatterns.get());
|
||||
this.addDependencyClasses(
|
||||
WriterBannerPattern.class
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<DataBannerPattern> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getBannerPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, List<DataBannerPattern> fa, ItemStack d)
|
||||
{
|
||||
ca.setBannerPatterns(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pattern> getB(BannerMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BannerMeta cb, List<Pattern> fb, ItemStack d)
|
||||
{
|
||||
cb.setPatterns(fb);
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
public class WriterItemStackMetaColor extends WriterAbstractItemStackMetaField<LeatherArmorMeta, Integer, Color>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackMetaColor i = new WriterItemStackMetaColor();
|
||||
public static WriterItemStackMetaColor get() { return i; }
|
||||
|
||||
public WriterItemStackMetaColor()
|
||||
{
|
||||
super(LeatherArmorMeta.class);
|
||||
this.setMaterial(Material.LEATHER_HELMET);
|
||||
this.setConverterTo(ConverterToColor.get());
|
||||
this.setConverterFrom(ConverterFromColor.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setColor(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getB(LeatherArmorMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(LeatherArmorMeta cb, Color fb, ItemStack d)
|
||||
{
|
||||
cb.setColor(fb);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user