Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
api:start [2019/10/21 16:32]
indyuce
api:start [2020/07/01 03:13] (current)
Line 1: Line 1:
 +======Plugin API======
 ===== Checking if an ItemStack is from MI===== ===== Checking if an ItemStack is from MI=====
 First, get the NBTItem of your ItemStack using ''​NBTItem.get(ItemStack)''​. This class lets you manipulate NBTTags from your item easily (1.14 has a new API which lets you do that using the ItemMeta, but for <1.14 support MI handles NBTs using NMS code). Use ''​nbtItem.hasType()''​ to see if the NBTItem can find the tag which corresponds to an MMOItems type. This method basically checks whether or not the plugin is from MI. First, get the NBTItem of your ItemStack using ''​NBTItem.get(ItemStack)''​. This class lets you manipulate NBTTags from your item easily (1.14 has a new API which lets you do that using the ItemMeta, but for <1.14 support MI handles NBTs using NMS code). Use ''​nbtItem.hasType()''​ to see if the NBTItem can find the tag which corresponds to an MMOItems type. This method basically checks whether or not the plugin is from MI.
Line 5: Line 6:
  
 ===== Generating an item===== ===== Generating an item=====
-Since 4.6 you now have to load an item before generating it. Loaded items are stored into ''​MMOItem''​ instances. By using the ''​newBuilder()''​ method (from the _MMOItem_ ​class), you can create an _MMOItemBuilder_ ​which can build an ItemStack instance out of an ''​MMOItem''​. Items may be loaded & generated using the ''​ItemManager''​ instance saved in the main java plugin class. You can access the item manager using ''​MMOItems.plugin.getItems()''​.+Since 4.6 you now have to load an item before generating it. Loaded items are stored into ''​MMOItem''​ instances. By using the ''​newBuilder()''​ method (from the ''​MMOItem'' ​class), you can create an ''​MMOItemBuilder'' ​which can build an ItemStack instance out of an ''​MMOItem''​. Items may be loaded & generated using the ''​ItemManager''​ instance saved in the main java plugin class. You can access the item manager using ''​MMOItems.plugin.getItems()''​.
 <​code>​ <​code>​
 ItemManager itemManager = MMOItems.plugin.getItems();​ ItemManager itemManager = MMOItems.plugin.getItems();​
Line 11: Line 12:
 ItemStack item = mmoitem.newBuilder().build();​ ItemStack item = mmoitem.newBuilder().build();​
 </​code>​ </​code>​
-Make sure you don't use the same ''​MMOItemBuilder''​ twice to build an ''​ItemStack''​ using the ''​build()''​ method. This method scrambles a lot of item data and thus can't be used twice. However you can use the same ''​MMOItem''​ instance to generate as many _MMOItemBuilders_ ​as you want.+Make sure you don't use the same ''​MMOItemBuilder''​ twice to build an ''​ItemStack''​ using the ''​build()''​ method. This method scrambles a lot of item data and thus can't be used twice. However you can use the same ''​MMOItem''​ instance to generate as many ''​MMOItemBuilders'' ​as you want.
  
 The following method directly returns the ItemStack instance: The following method directly returns the ItemStack instance:
Line 49: Line 50:
  
 ===== Getting an ability instance===== ===== Getting an ability instance=====
-Abilities are stored in an instance of the _AbilityManager_ ​class that is accessible using a static method from the _MMOItems_ ​class. To get the ability class instance, simply use the get(String) method from the _AbilityManager_ ​class and specify the ability ID as argument. ​`Ability ability = MMOItems.plugin.getAbilities().get("​FIREBOLT"​);​`+Abilities are stored in an instance of the ''​AbilityManager'' ​class that is accessible using a static method from the ''​MMOItems'' ​class. To get the ability class instance, simply use the get(String) method from the ''​AbilityManager'' ​class and specify the ability ID as argument. 
 +<​code>​Ability ability = MMOItems.plugin.getAbilities().get("​FIREBOLT"​);​</​code>​
  
 ===== Opening plugin GUIs===== ===== Opening plugin GUIs=====
Line 60: Line 62:
  
 ===== Checking if a GUI is from MI===== ===== Checking if a GUI is from MI=====
-Every GUI from MMOItems is created used a custom inventory holder which extends ​_PluginInventory_. To check if a GUI is a GUI for MI, just retrieve the inventory holder and check if it's an instance of that class: ​`inventory.getHolder() instanceof PluginInventory`+Every GUI from MMOItems is created used a custom inventory holder which extends ​''​PluginInventory''​. To check if a GUI is a GUI for MI, just retrieve the inventory holder and check if it's an instance of that class: ​<​code>​inventory.getHolder() instanceof PluginInventory</​code>​
  
 ===== Adding extra stats===== ===== Adding extra stats=====
-You may add temporary numeric stats like crit chance, attack damage, etc. to players. These stats function a bit like attribute modifiers but are reset on server restart. Extra stats can be added using the **PlayerStats** class which can be obtained by first accessing the player'​s **PlayerData** using `PlayerData.get(Player)and then using the `PlayerDara#​getStats()method.+You may add temporary numeric stats like crit chance, attack damage, etc. to players. These stats function a bit like attribute modifiers but are reset on server restart. Extra stats can be added using the **PlayerStats** class which can be obtained by first accessing the player'​s **PlayerData** using ''​PlayerData.get(Player)'' ​and then using the ''​PlayerDara#​getStats()'' ​method.
  
 If you were to add 10 Atk Damage to a player, you would use ''​pstats.getInstance(ItemStat.ATTACK_DAMAGE).setValue("<​externalSourceName>",​ 10);''​ which essentially stores the value 10 in a map using a specific key. When calculating stats, MMOItems simply sums up every value in the map. If you want something like per-level stat rewards, you will have to handle calculations on your end and then apply the stats everytime the player data is loaded (e.g on login). If you were to add 10 Atk Damage to a player, you would use ''​pstats.getInstance(ItemStat.ATTACK_DAMAGE).setValue("<​externalSourceName>",​ 10);''​ which essentially stores the value 10 in a map using a specific key. When calculating stats, MMOItems simply sums up every value in the map. If you want something like per-level stat rewards, you will have to handle calculations on your end and then apply the stats everytime the player data is loaded (e.g on login).
  
 The ''​PlayerStats#​getInstance(ItemStat)''​ **always** returns a **StatInstance** (no need of null checks). If the stat isn't load in the map yet, it creates a new one and saves it for you. Just make sure you **only use this system for numeric stats, because other stats are not supported.** The ''​PlayerStats#​getInstance(ItemStat)''​ **always** returns a **StatInstance** (no need of null checks). If the stat isn't load in the map yet, it creates a new one and saves it for you. Just make sure you **only use this system for numeric stats, because other stats are not supported.**

api/start.1571675542.txt.gz · Last modified: 2020/07/01 03:13 (external edit)