Addons
Create your own ItemsCore addon plugin or make it support another plugin
You can your own methods to ItemsCore or make it support another plugin's methods.
Making your own addon or support lets you add categories, methods, actions and attributes to the item editor!
You can also modify item on creation!
If you want ItemsCore to show the methods argument names you have to change the maven-compiler-plugin to this (Please not that your project should already have this plugin, you have to replace it, not add it.)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
<configuration>
<source>8</source>
<target>8</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>// Get the addon provider
AddonProvider addonProvider = AddonProvider.get();// Register
try { // Use try-catch incase the server doesn't have the required plugin classes.
addonProvider.addAddon(new PluginAddon("Name") // The name of the plugin in the .yml, ItemsCore will check if the plugin is on the server before using the addon.
.register(new AddonRegister<>(ClassName::getMethod)) // Can add as many registeres as you need, mosty be the main api class of that plugin
.addon("name", (Player player) -> new ClassWithMethods() // Add as many addons as you want, name is the name of the category that will show up in ItemsCore and you have to return an Object and it will use all its methods
)
);
} catch(Exception ignore) {
}// Example: Adding support to another plugin (AuraSkills)
try {
addonProvider.addAddon(new PluginAddon("AuraSkills") // Plugin name most be written correctly, you can check it using /plugins in your server.
.register(new AddonRegister<>(AuraSkillsApi::get)) // AuraSkills provides 2 usefull classes in their api so ill register both.
.register(new AddonRegister<>(AuraSkillsBukkit::get))
.addon(new Addon<>("skillsUser",
(Player player) ->
((AuraSkillsApi) getAddonByName("AuraSkills").getRegisters().get(0).getRegister()).getUser(player.getUniqueId()))) // Looks a bit complicated but I basically created a new ItemsCore category that uses the first register and basically returns SkillsUser (getUser())
.addon(new Addon<>("auraSkillsHelper",
(Player player) ->
new AuraSkillsHelper() // I added an helper too so it would be possible to insert Skill, Trait, etc values which aren't obtainable without this helper class.
)
)
);
} catch (Exception ignore) {
}
// Helper class (Not required of course but its good to have if ItemsCore can't handle the other plugin without.
public class AuraSkillsHelper {
public Skill getSkillByName(String name) {
return Skills.valueOf(name.toUpperCase());
}
public Trait getTraitByName(String name) {
return Traits.valueOf(name.toUpperCase());
}
public Ability getAbilityByName(String name) {
return Abilities.valueOf(name.toUpperCase());
}
public ManaAbility getManaAbilityByName(String name) {
return ManaAbilities.valueOf(name.toUpperCase());
}
public dev.aurelium.auraskills.api.stat.Stat getStatByName(String name) {
return Stats.valueOf(name.toUpperCase());
}
}// Creating your own addon plugin
try { // Basically the same as the helper class from before.
addonProvider.addAddon(new PluginAddon("YourPluginName") // Plugin name most be written correctly, you can check it using /plugins in your server.
.addon(new Addon<>("itemsCoreCategoryName",
(Player player) ->
new MyPluginAddon() // Return your new class with all the methods here.
)
)
);
} catch (Exception ignore) {
}// Creating new item attributes (PowerScrolls example)
provider.addAddon(
new PluginAddon("PowerScrolls", XMaterial.WRITABLE_BOOK.get())
.attribute(
new AddonAttribute<>(
"Is a scroll", // Attribute name
XMaterial.WRITTEN_BOOK.get(), // GUI material
false, // Default value
(player, gui, editor, callback) -> {
Boolean current = (Boolean) editor
.getAttributeSerializableByName("PowerScrolls_Is a scroll") // Name format is "%AddonName%_%AttributeName%"
.getValue();
callback.result(!current); // Callback the new value
editor.createAddonGui(provider.getAddonByName("PowerScrolls"))
.openInventory(player); // Create a new gui for the addon and open it to the player
},
"&7If true, the item will be used to upgrade",
"&7other items and add abilities to them.",
"",
"&aClick to toggle" // Some lore to explain what this attribute does.
)
)
);
// Adding listeners
provider.addAddon(
new PluginAddon("PowerScrolls", XMaterial.WRITABLE_BOOK.get())
.listener(new Listener())
);
public class Listener implements ItemsCoreListener {
@Override
public ItemEventResult itemEvent(Player player, Item item, String action, Event event) {
// Do whatever
return new ItemEventResult(false, null); // Return true if you want the event to be cancelled (the item won't do its ability)
}
}// Adding actions
AddonAction action = new AddonAction("TestAction", // Action name
Material.REDSTONE, // Action gui material
new String[] { "&7This is a test" }) // Action lore
provider.addAddon(
new PluginAddon("PluginName", XMaterial.WRITABLE_BOOK.get())
.action(action)
);
// Call the action (will run the action for the item if the item has actions for it.)
action.call(player, // The player
itemStack, // The item (as ItemStack)
new HashMap<String, Object>() {{ // Custom variables that would be avaiable when running
put("exampleVariable", player.getDisplayName());
}})// Modify item creation, return the modified item, in the params you get the Item used to generated the ItemStack and the newest ItemStack generated.
provider.addAddon(
new PluginAddon("PluginName", XMaterial.WRITABLE_BOOK.get())
.onItemCreate(new ItemCreationRunnable() {
@Override
public ItemStack onCreate(Item used, ItemStack created) {
return created;
}
})
);Last updated