2015-05-05 21:33:42 +02:00
|
|
|
package mineplex.game.clans.items;
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
import java.util.ArrayList;
|
2015-05-05 21:33:42 +02:00
|
|
|
import java.util.HashMap;
|
2015-06-01 18:25:20 +02:00
|
|
|
import java.util.HashSet;
|
2015-05-25 20:22:06 +02:00
|
|
|
import java.util.List;
|
2015-05-05 21:33:42 +02:00
|
|
|
import java.util.Map;
|
2015-06-01 18:25:20 +02:00
|
|
|
import java.util.Random;
|
|
|
|
import java.util.Set;
|
2015-05-05 21:33:42 +02:00
|
|
|
|
|
|
|
import mineplex.core.MiniPlugin;
|
|
|
|
import mineplex.core.account.CoreClientManager;
|
2015-05-25 20:22:06 +02:00
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.core.packethandler.IPacketHandler;
|
|
|
|
import mineplex.core.packethandler.PacketHandler;
|
|
|
|
import mineplex.core.packethandler.PacketInfo;
|
2015-05-05 21:33:42 +02:00
|
|
|
import mineplex.core.portal.TransferHandler;
|
|
|
|
import mineplex.core.portal.Commands.SendCommand;
|
|
|
|
import mineplex.core.portal.Commands.ServerCommand;
|
2015-06-22 22:20:20 +02:00
|
|
|
import mineplex.game.clans.items.attributes.AttributeContainer;
|
2015-05-25 20:22:06 +02:00
|
|
|
import mineplex.game.clans.items.attributes.ItemAttribute;
|
2015-06-01 18:25:20 +02:00
|
|
|
import mineplex.game.clans.items.attributes.weapon.*;
|
|
|
|
import mineplex.game.clans.items.attributes.armor.*;
|
2015-06-22 22:20:20 +02:00
|
|
|
import mineplex.game.clans.items.attributes.bow.*;
|
2015-05-05 21:33:42 +02:00
|
|
|
import mineplex.game.clans.items.commands.GearCommand;
|
2015-06-06 01:18:06 +02:00
|
|
|
import mineplex.game.clans.items.economy.GoldToken;
|
2015-05-05 21:33:42 +02:00
|
|
|
import mineplex.game.clans.items.generation.Weight;
|
|
|
|
import mineplex.game.clans.items.generation.WeightSet;
|
2015-06-01 18:25:20 +02:00
|
|
|
import mineplex.game.clans.items.legendaries.*;
|
2015-05-25 20:22:06 +02:00
|
|
|
import mineplex.game.clans.items.smelting.SmeltingListener;
|
2015-05-05 21:33:42 +02:00
|
|
|
import mineplex.serverdata.Region;
|
2015-05-16 18:58:58 +02:00
|
|
|
import mineplex.serverdata.Utility;
|
2015-05-05 21:33:42 +02:00
|
|
|
import mineplex.serverdata.commands.ServerCommandManager;
|
|
|
|
import mineplex.serverdata.commands.TransferCommand;
|
2015-05-25 20:22:06 +02:00
|
|
|
import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory;
|
2015-05-05 21:33:42 +02:00
|
|
|
import mineplex.serverdata.servers.ServerManager;
|
2015-05-25 20:22:06 +02:00
|
|
|
import net.minecraft.server.v1_7_R4.Packet;
|
|
|
|
import net.minecraft.server.v1_7_R4.PacketPlayOutSetSlot;
|
2015-06-01 18:25:20 +02:00
|
|
|
import net.minecraft.util.com.google.common.collect.Sets;
|
2015-05-05 21:33:42 +02:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2015-06-01 18:25:20 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2015-06-01 21:51:22 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
|
2015-05-05 21:33:42 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2015-05-25 20:22:06 +02:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2015-05-05 21:33:42 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2015-05-25 20:22:06 +02:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
|
2015-05-05 21:33:42 +02:00
|
|
|
/**
|
|
|
|
* Manages creation and retrieval of associated {@link PlayerGear}s with online players, as well
|
|
|
|
* as offering methods for parsing and handling {@link CustomItem}s.
|
|
|
|
* @author MrTwiggy
|
|
|
|
*
|
|
|
|
*/
|
2015-06-01 18:25:20 +02:00
|
|
|
public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
|
2015-05-05 21:33:42 +02:00
|
|
|
{
|
2015-05-25 20:22:06 +02:00
|
|
|
private static final String ITEM_SERIALIZATION_TAG = "-JSON-";
|
2015-06-01 18:25:20 +02:00
|
|
|
private static Gson _gson;
|
2015-05-05 21:33:42 +02:00
|
|
|
private static GearManager _instance; // Singleton instance
|
2015-05-25 20:22:06 +02:00
|
|
|
|
2015-05-05 21:33:42 +02:00
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
private Map<String, PlayerGear> _playerGears; // Mapping of player names (key) to cached gear set (value).
|
2015-05-05 21:33:42 +02:00
|
|
|
private WeightSet<Integer> _attributeWeights; // Weightings for randomly selecting number of attributes (1, 2, 3)
|
2015-06-01 18:25:20 +02:00
|
|
|
private WeightSet<ItemType> _typeWeights; // Weightings for randomly selecting item type (legendary/weapon/armour/bow)
|
|
|
|
|
|
|
|
// Legendary generation
|
|
|
|
private WeightSet<Class<? extends LegendaryItem>> _legendaryWeights;
|
|
|
|
|
|
|
|
// Weapon generation
|
|
|
|
private WeightSet<Material> _weaponTypes;
|
|
|
|
|
|
|
|
// Armour generation
|
|
|
|
private WeightSet<Material> _armourTypes;
|
|
|
|
|
|
|
|
// Attribute generation
|
|
|
|
private WeightSet<Class<? extends ItemAttribute>> _weaponAttributes;
|
|
|
|
private WeightSet<Class<? extends ItemAttribute>> _armourAttributes;
|
|
|
|
private WeightSet<Class<? extends ItemAttribute>> _bowAttributes;
|
2015-05-05 21:33:42 +02:00
|
|
|
|
2015-05-25 20:22:06 +02:00
|
|
|
public GearManager(JavaPlugin plugin, PacketHandler packetHandler)
|
2015-05-05 21:33:42 +02:00
|
|
|
{
|
|
|
|
super("CustomGear", plugin);
|
|
|
|
|
|
|
|
_instance = this;
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
_playerGears = new HashMap<String, PlayerGear>();
|
2015-05-25 20:22:06 +02:00
|
|
|
// TODO: Introduce configurable non-hardcoded values for generation weights?
|
2015-06-03 02:01:42 +02:00
|
|
|
_attributeWeights = new WeightSet<Integer>(new Weight<Integer>(3, 3), new Weight<Integer>(20, 2), new Weight<Integer>(77, 1));
|
|
|
|
_typeWeights = new WeightSet<ItemType>(new Weight<ItemType>(10, ItemType.LEGENDARY),
|
2015-06-01 18:25:20 +02:00
|
|
|
new Weight<ItemType>(45, ItemType.ARMOUR),
|
2015-06-22 22:20:20 +02:00
|
|
|
new Weight<ItemType>(23, ItemType.WEAPON),
|
|
|
|
new Weight<ItemType>(22, ItemType.BOW));
|
2015-06-01 18:25:20 +02:00
|
|
|
|
|
|
|
// Weapon-based attributes
|
|
|
|
_weaponAttributes = new WeightSet<Class<? extends ItemAttribute>>(FrostedAttribute.class, SharpAttribute.class,
|
|
|
|
JaggedAttribute.class, HasteAttribute.class, FlamingAttribute.class, ConqueringAttribute.class);
|
|
|
|
|
|
|
|
// Armour-based attributes
|
|
|
|
_armourAttributes = new WeightSet<Class<? extends ItemAttribute>>(SlantedAttribute.class, ReinforcedAttribute.class,
|
|
|
|
ProtectionAttribute.class, PaddedAttribute.class, LavaAttribute.class);
|
2015-05-16 18:58:58 +02:00
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
// Bow-based attributes
|
2015-06-22 22:20:20 +02:00
|
|
|
_bowAttributes = new WeightSet<Class<? extends ItemAttribute>>(HeavyArrowsAttribute.class, HuntingAttribute.class, InverseAttribute.class,
|
|
|
|
LeechingAttribute.class, RecursiveAttribute.class, ScorchingAttribute.class, SlayingAttribute.class);
|
2015-06-01 18:25:20 +02:00
|
|
|
|
|
|
|
// Weapon material types
|
|
|
|
_weaponTypes = new WeightSet<Material>(Material.DIAMOND_SWORD, Material.GOLD_SWORD, Material.IRON_SWORD, Material.STONE_SWORD,
|
|
|
|
Material.DIAMOND_AXE, Material.GOLD_AXE, Material.IRON_AXE, Material.STONE_AXE);
|
|
|
|
|
|
|
|
// Armour material types
|
|
|
|
_armourTypes = new WeightSet<Material>(Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS,
|
|
|
|
Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS,
|
|
|
|
Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS);
|
|
|
|
|
|
|
|
// TODO: Initialize list of attributes and types
|
|
|
|
|
|
|
|
// Initialize various LegendaryItem types
|
|
|
|
_legendaryWeights = new WeightSet<Class<? extends LegendaryItem>>(AlligatorsTooth.class, WindBlade.class,
|
|
|
|
GiantsBroadsword.class, HyperBlade.class, MagneticBlade.class);
|
|
|
|
// TODO: Add rest of legendaries, find better way?
|
2015-05-25 20:22:06 +02:00
|
|
|
|
|
|
|
// Register listeners
|
2015-06-22 22:20:20 +02:00
|
|
|
UtilServer.getServer().getPluginManager().registerEvents(new ItemListener(getPlugin()), getPlugin());
|
2015-05-25 20:22:06 +02:00
|
|
|
UtilServer.getServer().getPluginManager().registerEvents(new SmeltingListener(), getPlugin());
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
// Initialize attribute types factory for JSON handling of polymorphism.
|
|
|
|
RuntimeTypeAdapterFactory<ItemAttribute> attributeFactory = RuntimeTypeAdapterFactory
|
|
|
|
.of(ItemAttribute.class);
|
|
|
|
|
|
|
|
for (Class<? extends ItemAttribute> attributeType : _armourAttributes.elements())
|
|
|
|
{
|
|
|
|
attributeFactory.registerSubtype(attributeType);
|
|
|
|
}
|
|
|
|
for (Class<? extends ItemAttribute> attributeType : _weaponAttributes.elements())
|
|
|
|
{
|
|
|
|
attributeFactory.registerSubtype(attributeType);
|
|
|
|
}
|
2015-06-22 22:20:20 +02:00
|
|
|
for (Class<? extends ItemAttribute> attributeType : _bowAttributes.elements())
|
|
|
|
{
|
|
|
|
attributeFactory.registerSubtype(attributeType);
|
|
|
|
}
|
2015-05-25 20:22:06 +02:00
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
// Initialize legendary item type factory for JSON handling of polymorphism.
|
2015-05-25 20:22:06 +02:00
|
|
|
RuntimeTypeAdapterFactory<CustomItem> customItemType = RuntimeTypeAdapterFactory
|
2015-06-01 18:25:20 +02:00
|
|
|
.of(CustomItem.class);
|
|
|
|
customItemType.registerSubtype(CustomItem.class);
|
|
|
|
customItemType.registerSubtype(LegendaryItem.class);
|
2015-06-06 01:18:06 +02:00
|
|
|
customItemType.registerSubtype(GoldToken.class);
|
2015-06-01 18:25:20 +02:00
|
|
|
for (Class<? extends CustomItem> itemType : _legendaryWeights.elements())
|
|
|
|
{
|
|
|
|
customItemType.registerSubtype(itemType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build GSON instance off factories for future serialization of items.
|
|
|
|
_gson = new GsonBuilder()
|
|
|
|
.registerTypeAdapterFactory(attributeFactory)
|
|
|
|
.registerTypeAdapterFactory(customItemType)
|
|
|
|
.create();
|
2015-05-25 20:22:06 +02:00
|
|
|
|
|
|
|
packetHandler.addPacketHandler(this);
|
2015-06-01 18:25:20 +02:00
|
|
|
|
|
|
|
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1l, 1l);
|
2015-05-05 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addCommands()
|
|
|
|
{
|
|
|
|
addCommand(new GearCommand(this));
|
|
|
|
}
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
/**
|
|
|
|
* Tick & update internal logic for {@link GearManager}. Called once per tick.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
for (PlayerGear gear : _playerGears.values())
|
|
|
|
{
|
|
|
|
gear.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 21:33:42 +02:00
|
|
|
/**
|
|
|
|
* @param player - the player whose {@link PlayerGear} set is to be fetched.
|
|
|
|
* @return the cached or newly instantiated {@link PlayerGear} associated with {@code player}.
|
|
|
|
*/
|
|
|
|
public PlayerGear getPlayerGear(Player player)
|
|
|
|
{
|
|
|
|
String playerName = player.getName();
|
2015-06-01 18:25:20 +02:00
|
|
|
if (!_playerGears.containsKey(playerName))
|
2015-05-05 21:33:42 +02:00
|
|
|
{
|
|
|
|
PlayerGear gear = new PlayerGear(playerName);
|
2015-06-01 18:25:20 +02:00
|
|
|
_playerGears.put(playerName, gear);
|
2015-05-05 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
return _playerGears.get(playerName);
|
2015-05-05 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public CustomItem generateItem()
|
|
|
|
{
|
|
|
|
int attributeCount = _attributeWeights.generateRandom();
|
2015-06-01 18:25:20 +02:00
|
|
|
ItemType itemType = _typeWeights.generateRandom();
|
2015-05-05 21:33:42 +02:00
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
System.out.println("Generating item of type " + itemType.toString() + " with attribute count of " + attributeCount);
|
|
|
|
CustomItem item = generateItem(itemType);
|
|
|
|
System.out.println("Generated item!");
|
|
|
|
|
|
|
|
if (itemType != ItemType.LEGENDARY) // Only non-legendaries have attributes
|
|
|
|
{
|
|
|
|
for (ItemAttribute attribute : generateAttributes(itemType, attributeCount))
|
|
|
|
{
|
|
|
|
item.addAttribute(attribute);
|
|
|
|
}
|
|
|
|
// Add up to attributeCount attributes
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
private CustomItem generateItem(ItemType itemType)
|
|
|
|
{
|
|
|
|
switch(itemType)
|
|
|
|
{
|
|
|
|
case LEGENDARY: // Legendary weapon
|
|
|
|
Class<? extends LegendaryItem> legendaryClass = _legendaryWeights.generateRandom();
|
|
|
|
System.out.println("Legendary: " + legendaryClass.getName());
|
|
|
|
return instantiate(legendaryClass);
|
|
|
|
case WEAPON: // Sword or axe
|
|
|
|
return new CustomItem(_weaponTypes.generateRandom());
|
|
|
|
case ARMOUR: // Helmet, chestplate, leggings, or boots
|
|
|
|
return new CustomItem(_armourTypes.generateRandom());
|
|
|
|
case BOW: // A bow
|
|
|
|
return new CustomItem(Material.BOW);
|
|
|
|
default:
|
|
|
|
return null;// Never reached, yet required for compilation purposes.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Set<ItemAttribute> generateAttributes(ItemType type, int count)
|
|
|
|
{
|
|
|
|
Set<ItemAttribute> attributes = new HashSet<ItemAttribute>();
|
2015-05-05 21:33:42 +02:00
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ARMOUR:
|
|
|
|
attributes.add(instantiate(_armourAttributes.generateRandom()));
|
|
|
|
break;
|
|
|
|
case WEAPON:
|
|
|
|
attributes.add(instantiate(_weaponAttributes.generateRandom()));
|
|
|
|
break;
|
2015-06-22 22:20:20 +02:00
|
|
|
case BOW:
|
|
|
|
attributes.add(instantiate(_bowAttributes.generateRandom()));
|
|
|
|
break;
|
2015-06-01 18:25:20 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void spawnItem(Location location)
|
|
|
|
{
|
|
|
|
CustomItem item = generateItem();
|
|
|
|
location.getWorld().dropItem(location, item.toItemStack());
|
2015-05-05 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomItem parseItem(ItemStack item)
|
|
|
|
{
|
2015-05-25 20:22:06 +02:00
|
|
|
String serialization = getItemSerialization(item);
|
|
|
|
|
|
|
|
if (serialization != null)
|
|
|
|
{
|
|
|
|
CustomItem customItem = deserialize(serialization);
|
|
|
|
return customItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null; // No serialization found in item's lore, not a custom item!
|
2015-05-05 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isCustomItem(ItemStack item)
|
|
|
|
{
|
2015-05-25 20:22:06 +02:00
|
|
|
return getItemSerialization(item) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getItemSerialization(CustomItem customItem)
|
|
|
|
{
|
2015-06-01 21:51:22 +02:00
|
|
|
String serialization = serialize(customItem);
|
2015-05-25 20:22:06 +02:00
|
|
|
|
2015-06-01 21:51:22 +02:00
|
|
|
return ITEM_SERIALIZATION_TAG + serialization;
|
2015-05-25 20:22:06 +02:00
|
|
|
}
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
/**
|
|
|
|
* @param type - the class-type of the object to be instantiated. (must have zero-argument constructor)
|
|
|
|
* @return a newly instantiated instance of {@code type} class-type. Instantied with zero argument constructor.
|
|
|
|
*/
|
|
|
|
private static <T> T instantiate(Class<T> type)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return type.newInstance();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-25 20:22:06 +02:00
|
|
|
private static String getItemSerialization(ItemStack item)
|
|
|
|
{
|
|
|
|
if (item == null || item.getItemMeta() == null
|
|
|
|
|| item.getItemMeta().getLore() == null) return null;
|
|
|
|
|
|
|
|
ItemMeta meta = item.getItemMeta();
|
|
|
|
|
2015-06-01 21:51:22 +02:00
|
|
|
for (String lore : meta.getLore())
|
2015-05-25 20:22:06 +02:00
|
|
|
{
|
|
|
|
if (lore.startsWith(ITEM_SERIALIZATION_TAG)) // Found serialization lore-line
|
|
|
|
{
|
|
|
|
int tagLength = ITEM_SERIALIZATION_TAG.length();
|
|
|
|
String serialization = lore.substring(tagLength);
|
|
|
|
|
|
|
|
return serialization;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null; // Unable to find any serialized lore lines, hence not a CustomItem.
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String serialize(CustomItem customItem)
|
|
|
|
{
|
2015-06-01 18:25:20 +02:00
|
|
|
return _gson.toJson(customItem, CustomItem.class);
|
2015-05-25 20:22:06 +02:00
|
|
|
}
|
|
|
|
|
2015-06-22 22:20:20 +02:00
|
|
|
public static String serialize(AttributeContainer attributes)
|
|
|
|
{
|
|
|
|
return _gson.toJson(attributes, AttributeContainer.class);
|
|
|
|
}
|
|
|
|
|
2015-05-25 20:22:06 +02:00
|
|
|
public static CustomItem deserialize(String serialization)
|
|
|
|
{
|
|
|
|
return _gson.fromJson(serialization, CustomItem.class);
|
2015-05-05 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
2015-06-22 22:20:20 +02:00
|
|
|
public static <T> T deserialize(String serialization, Class<T> type)
|
|
|
|
{
|
|
|
|
return _gson.fromJson(serialization, type);
|
|
|
|
}
|
|
|
|
|
2015-05-05 21:33:42 +02:00
|
|
|
/**
|
|
|
|
* @return singleton instance of {@link GearManager}.
|
|
|
|
*/
|
|
|
|
public static GearManager getInstane()
|
|
|
|
{
|
|
|
|
return _instance;
|
|
|
|
}
|
2015-05-25 20:22:06 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handle(PacketInfo packetInfo)
|
|
|
|
{
|
|
|
|
Packet packet = packetInfo.getPacket();
|
|
|
|
|
|
|
|
if (packet instanceof PacketPlayOutSetSlot)
|
|
|
|
{
|
|
|
|
System.out.println("Item slot packet!");
|
|
|
|
PacketPlayOutSetSlot slotPacket = (PacketPlayOutSetSlot) packet;
|
|
|
|
|
2015-06-01 21:51:22 +02:00
|
|
|
net.minecraft.server.v1_7_R4.ItemStack original = slotPacket.c;
|
|
|
|
CraftItemStack originalItem = CraftItemStack.asCraftMirror(original);
|
|
|
|
ItemMeta originalMeta = originalItem.getItemMeta();
|
|
|
|
if (originalMeta == null || originalMeta.getLore() == null) return; // No need to modify item packets with no lore
|
|
|
|
|
|
|
|
List<String> lore = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (String line : originalMeta.getLore())
|
|
|
|
{
|
|
|
|
if (!line.startsWith(ITEM_SERIALIZATION_TAG)) // Remove serialization lines from out-going lore
|
|
|
|
{
|
|
|
|
lore.add(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
net.minecraft.server.v1_7_R4.ItemStack newItem = CraftItemStack.asNMSCopy(originalItem);
|
|
|
|
CraftItemStack newCopy = CraftItemStack.asCraftMirror(newItem);
|
|
|
|
ItemMeta newMeta = newCopy.getItemMeta();
|
|
|
|
newMeta.setLore(lore);
|
|
|
|
newCopy.setItemMeta(newMeta);
|
2015-06-03 02:01:42 +02:00
|
|
|
slotPacket.c = newItem;
|
2015-06-01 21:51:22 +02:00
|
|
|
//CraftItemStack.setItemMeta(slotPacket.c, meta);
|
2015-06-01 18:25:20 +02:00
|
|
|
// TODO: Modify spigot build so that slotPacket's itemstack lore can be modified
|
|
|
|
// to 'hide' json-encoded lore from players.
|
2015-05-25 20:22:06 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-05 21:33:42 +02:00
|
|
|
}
|