forked from alkarinv/BattleArena
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for use of custom items in BattleArena.
- Loading branch information
Showing
17 changed files
with
377 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
repositories { | ||
maven("https://repo.oraxen.com/releases") | ||
maven("https://repo.codemc.io/repository/maven-public/") | ||
maven("https://jitpack.io") | ||
maven("https://mvn.lumine.io/repository/maven-public/") { | ||
metadataSources { | ||
artifact() | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly("io.th0rgal:oraxen:1.173.0") | ||
compileOnly("me.zombie_striker:QualityArmory:2.0.17") | ||
compileOnly("com.github.LoneDev6:api-itemsadder:3.6.1") | ||
compileOnly("io.lumine:Mythic-Dist:5.6.1") | ||
} |
48 changes: 48 additions & 0 deletions
48
...tems-integration/src/main/java/org/battleplugins/arena/module/items/ItemsIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.battleplugins.arena.module.items; | ||
|
||
import org.battleplugins.arena.event.BattleArenaPostInitializeEvent; | ||
import org.battleplugins.arena.feature.items.Items; | ||
import org.battleplugins.arena.module.ArenaModule; | ||
import org.battleplugins.arena.module.ArenaModuleInitializer; | ||
import org.battleplugins.arena.module.items.itemsadder.ItemsAdderFeature; | ||
import org.battleplugins.arena.module.items.mythiccrucible.MythicCrucibleFeature; | ||
import org.battleplugins.arena.module.items.oraxen.OraxenFeature; | ||
import org.battleplugins.arena.module.items.qualityarmory.QualityArmoryFeature; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
|
||
/** | ||
* A module that allows for hooking into various item provider plugins. | ||
*/ | ||
@ArenaModule(id = ItemsIntegration.ID, priority = 100, name = "Items", description = "Adds support for hooking into various item provider plugins.", authors = "BattlePlugins") | ||
public class ItemsIntegration implements ArenaModuleInitializer { | ||
public static final String ID = "items"; | ||
|
||
@EventHandler(priority = EventPriority.LOWEST) // Load before all other modules listening on this event | ||
public void onPostInitialize(BattleArenaPostInitializeEvent event) { | ||
if (Bukkit.getPluginManager().isPluginEnabled("QualityArmory")) { | ||
Items.register(new QualityArmoryFeature()); | ||
|
||
event.getBattleArena().info("QualityArmory found. Registering item integration."); | ||
} | ||
|
||
if (Bukkit.getPluginManager().isPluginEnabled("Oraxen")) { | ||
Items.register(new OraxenFeature()); | ||
|
||
event.getBattleArena().info("Oraxen found. Registering item integration."); | ||
} | ||
|
||
if (Bukkit.getPluginManager().isPluginEnabled("ItemsAdder")) { | ||
Items.register(new ItemsAdderFeature()); | ||
|
||
event.getBattleArena().info("ItemsAdder found. Registering item integration."); | ||
} | ||
|
||
if (Bukkit.getPluginManager().isPluginEnabled("MythicCrucible")) { | ||
Items.register(new MythicCrucibleFeature()); | ||
|
||
event.getBattleArena().info("MythicCrucible found. Registering item integration."); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...tion/src/main/java/org/battleplugins/arena/module/items/itemsadder/ItemsAdderFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.battleplugins.arena.module.items.itemsadder; | ||
|
||
import dev.lone.itemsadder.api.CustomStack; | ||
import org.battleplugins.arena.feature.PluginFeature; | ||
import org.battleplugins.arena.feature.items.ItemsFeature; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class ItemsAdderFeature extends PluginFeature<ItemsFeature> implements ItemsFeature { | ||
|
||
public ItemsAdderFeature() { | ||
super("ItemsAdder"); | ||
} | ||
|
||
@Override | ||
public ItemStack createItem(NamespacedKey key) { | ||
CustomStack customStack = CustomStack.getInstance(key.value()); | ||
return customStack == null ? null : customStack.getItemStack(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../main/java/org/battleplugins/arena/module/items/mythiccrucible/MythicCrucibleFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.battleplugins.arena.module.items.mythiccrucible; | ||
|
||
import io.lumine.mythic.bukkit.BukkitAdapter; | ||
import io.lumine.mythic.bukkit.MythicBukkit; | ||
import org.battleplugins.arena.feature.PluginFeature; | ||
import org.battleplugins.arena.feature.items.ItemsFeature; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class MythicCrucibleFeature extends PluginFeature<ItemsFeature> implements ItemsFeature { | ||
|
||
public MythicCrucibleFeature() { | ||
super("MythicCrucible"); | ||
} | ||
|
||
@Override | ||
public ItemStack createItem(NamespacedKey key) { | ||
return MythicBukkit.inst().getItemManager().getItem(key.value()) | ||
.map(item -> BukkitAdapter.adapt(item.generateItemStack(1))) | ||
.orElse(null); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...-integration/src/main/java/org/battleplugins/arena/module/items/oraxen/OraxenFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.battleplugins.arena.module.items.oraxen; | ||
|
||
import io.th0rgal.oraxen.api.OraxenItems; | ||
import io.th0rgal.oraxen.items.ItemBuilder; | ||
import org.battleplugins.arena.feature.PluginFeature; | ||
import org.battleplugins.arena.feature.items.ItemsFeature; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class OraxenFeature extends PluginFeature<ItemsFeature> implements ItemsFeature { | ||
|
||
public OraxenFeature() { | ||
super("Oraxen"); | ||
} | ||
|
||
@Override | ||
public ItemStack createItem(NamespacedKey key) { | ||
return OraxenItems.getOptionalItemById(key.value()) | ||
.map(ItemBuilder::build) | ||
.orElse(null); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...rc/main/java/org/battleplugins/arena/module/items/qualityarmory/QualityArmoryFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.battleplugins.arena.module.items.qualityarmory; | ||
|
||
import me.zombie_striker.qg.api.QualityArmory; | ||
import org.battleplugins.arena.feature.PluginFeature; | ||
import org.battleplugins.arena.feature.items.ItemsFeature; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class QualityArmoryFeature extends PluginFeature<ItemsFeature> implements ItemsFeature { | ||
|
||
public QualityArmoryFeature() { | ||
super("QualityArmory"); | ||
} | ||
|
||
@Override | ||
public ItemStack createItem(NamespacedKey key) { | ||
return QualityArmory.getCustomItemAsItemStack(key.value()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
plugin/src/main/java/org/battleplugins/arena/feature/items/Items.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.battleplugins.arena.feature.items; | ||
|
||
import org.battleplugins.arena.config.SingularValueParser; | ||
import org.battleplugins.arena.feature.FeatureController; | ||
import org.battleplugins.arena.feature.PluginFeature; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
/** | ||
* API for items used in BattleArena. | ||
* <p> | ||
* This API serves as a service provider to allow for | ||
* accessing and creating items from Minecraft as well | ||
* as third parties. | ||
*/ | ||
@ApiStatus.Experimental | ||
public final class Items extends FeatureController<PluginFeature<ItemsFeature>> { | ||
|
||
/** | ||
* Creates an {@link ItemStack} from the given key and arguments. | ||
* | ||
* @param key the key of the item | ||
* @param arguments the arguments to create the item with | ||
* @return the created item | ||
*/ | ||
public static ItemStack createItem(NamespacedKey key, SingularValueParser.ArgumentBuffer arguments) { | ||
return getFeature(key).createItem(key, arguments); | ||
} | ||
|
||
/** | ||
* Registers a {@link ItemsFeature} to the feature controller. | ||
* | ||
* @param feature the feature to register | ||
*/ | ||
public static <T extends PluginFeature<ItemsFeature> & ItemsFeature> void register(T feature) { | ||
registerFeature(ItemsFeature.class, feature); | ||
} | ||
|
||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
private static <T extends PluginFeature<ItemsFeature> & ItemsFeature> ItemsFeature getFeature(NamespacedKey key) { | ||
// Fast-track vanilla | ||
if (key.getNamespace().equals(NamespacedKey.MINECRAFT)) { | ||
return VanillaItemsFeature.INSTANCE; | ||
} | ||
|
||
List<T> features = (List) getFeatures(ItemsFeature.class); | ||
for (T feature : features) { | ||
if (!feature.isEnabled()) { | ||
continue; | ||
} | ||
|
||
String pluginNamespace = feature.getPlugin().getName().toLowerCase(Locale.ROOT); | ||
if (key.getNamespace().equals(pluginNamespace)) { | ||
return feature; | ||
} | ||
} | ||
|
||
return VanillaItemsFeature.INSTANCE; | ||
} | ||
} |
Oops, something went wrong.