Package org.kikikan.deadbymoonlight.game
Class Item
- java.lang.Object
-
- org.kikikan.deadbymoonlight.Configurable
-
- org.kikikan.deadbymoonlight.game.Item
-
- All Implemented Interfaces:
java.lang.Comparable<Configurable>
public abstract class Item extends Configurable
Represents an Item.
-
-
Constructor Summary
Constructors Constructor Description Item(org.bukkit.plugin.java.JavaPlugin plugin, Survivor generatorSurvivor)
This constructor will get called when a Survivor finishes opening a Chest, so it's important that you have it.Item(org.bukkit.plugin.java.JavaPlugin plugin, Tiers tier, Survivor generatorSurvivor)
This constructor will never be called by Dead by Moonlight.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addLore(org.bukkit.inventory.meta.ItemMeta im)
Adds the Modifier and the Durability values to the Item.boolean
allowsSelfHeal()
Determines if this Item enables the Survivor to heal themselves.void
breakItem()
Instantly breaks the Item, making it unusable for the rest of the Game.protected abstract void
calculateStats()
Sets the durability and the modifier values.protected void
editItemMeta(org.bukkit.inventory.meta.ItemMeta im)
Empty method by default.protected org.bukkit.ChatColor
getColor()
Returns the color code of the name of the ItemStack.java.lang.String
getDisplayName()
The name that will be shown to playersfloat
getDurability()
Gets the durability of the Item.protected java.lang.String
getFileName()
Gets the name of the config file.org.bukkit.inventory.ItemStack
getItemStack()
Generates the ItemStack representing the Item.protected abstract org.bukkit.Material
getMaterial()
Gets the material of the ItemStack.float
getMaxDurability()
Gets the maximum durability of the Item.float
getModifier()
Gets the modifier of the Item.abstract java.lang.String
getName()
Gets the default name of the Item.protected Survivor
getOwner()
Gets the Survivor who currently has the Item.Tiers
getTier()
Gets the tier of the Item.boolean
isBroken()
Checks whether this Item is broken.protected void
removeDurability()
Removes Durability.protected void
setDurability(float durability)
Sets the durability of the Item.protected void
setModifier(float modifier)
Sets the modifier of the Item.-
Methods inherited from class org.kikikan.deadbymoonlight.Configurable
compareTo, equals, getAllValuesFromConfig, getDefaultEnabled, getDescription, getFormattedName, getPlugin, getRequirements, getValueFromConfig, hashCode, isEnabled, toTextComponent
-
-
-
-
Constructor Detail
-
Item
public Item(org.bukkit.plugin.java.JavaPlugin plugin, Survivor generatorSurvivor)
This constructor will get called when a Survivor finishes opening a Chest, so it's important that you have it. This is where the Item generation takes place.- Parameters:
plugin
- Your plugin's main class.generatorSurvivor
- The Survivor who opened the Chest.
-
Item
public Item(org.bukkit.plugin.java.JavaPlugin plugin, Tiers tier, Survivor generatorSurvivor)
This constructor will never be called by Dead by Moonlight. However, you can use it to create an Item with whichever Tier you fancy.GetItemStatsEvent
will still be called if the generator Survivor is not null.- Parameters:
plugin
- Your plugin's main class.tier
- The Tier of the Item.generatorSurvivor
- The Survivor who opened the Chest. If it is not null,GetItemStatsEvent
will run with this Survivor.
-
-
Method Detail
-
getName
public abstract java.lang.String getName()
Gets the default name of the Item.- Specified by:
getName
in classConfigurable
- Returns:
- The default, most generic name of the Item.
-
getFileName
protected final java.lang.String getFileName()
Description copied from class:Configurable
Gets the name of the config file.- Specified by:
getFileName
in classConfigurable
- Returns:
- The name of the config file.
-
calculateStats
protected abstract void calculateStats()
Sets the durability and the modifier values. If either of these values are less than or equal to zero after this method has been called IllegalStateException will be thrown, and the opened Chest remains empty.- Throws:
java.lang.IllegalStateException
- If the durability and/or the modifier is smaller than or equal to 0 after this method has been called.
-
allowsSelfHeal
public boolean allowsSelfHeal()
Determines if this Item enables the Survivor to heal themselves. Default value: false- Returns:
- True if the Survivor can heal themselves using this Item
-
getMaterial
protected abstract org.bukkit.Material getMaterial()
Gets the material of the ItemStack.- Returns:
- The material of the ItemStack.
-
getColor
protected org.bukkit.ChatColor getColor()
Returns the color code of the name of the ItemStack.- Returns:
- The ChatColor (hopefully depending on the Tier).
-
getDisplayName
public final java.lang.String getDisplayName()
Description copied from class:Configurable
The name that will be shown to players- Specified by:
getDisplayName
in classConfigurable
- Returns:
- The (translated) name that will be shown to players
-
getItemStack
public final org.bukkit.inventory.ItemStack getItemStack()
Generates the ItemStack representing the Item.- Returns:
- The ItemStack of the Item.
-
addLore
protected final void addLore(org.bukkit.inventory.meta.ItemMeta im)
Adds the Modifier and the Durability values to the Item.- Parameters:
im
- The ItemMeta of the ItemStack.
-
editItemMeta
protected void editItemMeta(org.bukkit.inventory.meta.ItemMeta im)
Empty method by default. Does whatever you want.- Parameters:
im
- The ItemMeta of the ItemStack of the Item. Called right afteraddLore()
, so the display name is already set, and the Modifier and Durability values are added.
-
removeDurability
protected final void removeDurability()
Removes Durability. It is not called automatically, you should call it whenever you want to, otherwise the Item will be usable for eternity.
-
isBroken
public final boolean isBroken()
Checks whether this Item is broken.- Returns:
- True, if the Item is broken.
-
getMaxDurability
public final float getMaxDurability()
Gets the maximum durability of the Item.- Returns:
- The maximum durability of the Item.
-
getDurability
public final float getDurability()
Gets the durability of the Item.- Returns:
- The durability of the Item.
-
getModifier
public final float getModifier()
Gets the modifier of the Item.- Returns:
- The modifier of the Item.
-
getTier
public final Tiers getTier()
Gets the tier of the Item.- Returns:
- The tier of the Item.
-
setDurability
protected final void setDurability(float durability)
Sets the durability of the Item. Should be called fromcalculateStats()
, and only once.- Parameters:
durability
- The durability of the Item.- Throws:
java.lang.IllegalStateException
- If durability was already set.java.lang.IllegalArgumentException
- If the argument is less than or equal to 0.
-
setModifier
protected final void setModifier(float modifier)
Sets the modifier of the Item. Should be called fromcalculateStats()
, and only once.- Parameters:
modifier
- The modifier of the Item.- Throws:
java.lang.IllegalStateException
- If durability was already set.java.lang.IllegalArgumentException
- If the argument is less than or equal to 0.
-
getOwner
protected final Survivor getOwner()
Gets the Survivor who currently has the Item.- Returns:
- The owner of the Item.
-
breakItem
public final void breakItem()
Instantly breaks the Item, making it unusable for the rest of the Game.
-
-