107 lines
2.2 KiB
Java
107 lines
2.2 KiB
Java
|
package mineplex.game.clans.items;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.HashSet;
|
||
|
import java.util.List;
|
||
|
import java.util.Set;
|
||
|
|
||
|
import mineplex.game.clans.items.attributes.ItemAttribute;
|
||
|
|
||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||
|
import org.bukkit.inventory.ItemStack;
|
||
|
|
||
|
/**
|
||
|
* Represents a customizable wrapper for an {@link ItemStack}, enabling the possession
|
||
|
* of special abilities, attributes, and triggers on item.
|
||
|
* @author MrTwiggy
|
||
|
*
|
||
|
*/
|
||
|
public class CustomItem
|
||
|
{
|
||
|
|
||
|
private ItemAttribute superPrefix;
|
||
|
private ItemAttribute prefix;
|
||
|
private ItemAttribute suffix;
|
||
|
|
||
|
private String _displayName;
|
||
|
|
||
|
/**
|
||
|
* @return the name displayed to players for the item.
|
||
|
*/
|
||
|
public String getDisplayName()
|
||
|
{
|
||
|
// Concatenate attribute prefixes/suffixes to display name.
|
||
|
String display = _displayName;
|
||
|
|
||
|
if (prefix != null)
|
||
|
{
|
||
|
display = prefix.getDisplayName() + " " + display;
|
||
|
}
|
||
|
|
||
|
if (superPrefix != null)
|
||
|
{
|
||
|
display = superPrefix.getDisplayName() + " " + display;
|
||
|
}
|
||
|
|
||
|
if (suffix != null)
|
||
|
{
|
||
|
display += " of " + suffix.getDisplayName();
|
||
|
}
|
||
|
|
||
|
return display;
|
||
|
}
|
||
|
|
||
|
public List<String> getLore()
|
||
|
{
|
||
|
List<String> lore = new ArrayList<String>();
|
||
|
|
||
|
// TODO: Add decorative stat lore (and hidden json-encoding/uuid info)
|
||
|
lore.add("Custom stat lore string!");
|
||
|
|
||
|
return lore;
|
||
|
}
|
||
|
|
||
|
public ItemStack toItemStack()
|
||
|
{
|
||
|
// TODO: Generate an item stack representing this CustomItem
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public void onInteract(PlayerInteractEvent event)
|
||
|
{
|
||
|
for (ItemAttribute attribute : getAttributes())
|
||
|
{
|
||
|
attribute.onInteract(event);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void onAttack(EntityDamageByEntityEvent event)
|
||
|
{
|
||
|
for (ItemAttribute attribute : getAttributes())
|
||
|
{
|
||
|
attribute.onAttack(event);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void onAttacked(EntityDamageByEntityEvent event)
|
||
|
{
|
||
|
for (ItemAttribute attribute : getAttributes())
|
||
|
{
|
||
|
attribute.onAttacked(event);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return the (possibly empty) set of {@link ItemAttribute}s attached to this item.
|
||
|
*/
|
||
|
public Set<ItemAttribute> getAttributes()
|
||
|
{
|
||
|
Set<ItemAttribute> attributes = new HashSet<ItemAttribute>();
|
||
|
attributes.add(superPrefix);
|
||
|
attributes.add(prefix);
|
||
|
attributes.add(suffix);
|
||
|
return attributes;
|
||
|
}
|
||
|
}
|