Skip to content

Commit

Permalink
Add support for ItemsAdder.
Browse files Browse the repository at this point in the history
TODO: finish readme with instructions for itemsadder.

Closes #141.
  • Loading branch information
LlmDl committed Jan 24, 2024
1 parent f7973a5 commit b76c1a6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<version>6.9.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.LoneDev6</groupId>
<artifactId>api-itemsadder</artifactId>
<version>3.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.bsideup.jabel</groupId>
<artifactId>jabel-javac-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class TownyResources extends JavaPlugin {
private static boolean slimeFunInstalled;
private static boolean mythicMobsInstalled;
private static boolean mmmoItemsInstalled;

private static boolean itemsAdderInstalled;

public TownyResources() {
plugin = this;
Expand Down Expand Up @@ -222,6 +222,10 @@ public boolean isMythicMobsV5() {
return mythicMobsInstalled;
}

public boolean isItemsAdderInstalled() {
return itemsAdderInstalled;
}

public boolean isMMOItemsInstalled() {
return mmmoItemsInstalled;
}
Expand Down Expand Up @@ -264,6 +268,11 @@ private void setupIntegrationsWithOtherPlugins() {
}
}

Plugin itemsAdder = Bukkit.getPluginManager().getPlugin("ItemsAdder");
itemsAdderInstalled = itemsAdder != null;
if (itemsAdderInstalled)
info(" ItemsAdder Integration Enabled");

Plugin mmmoItems = Bukkit.getPluginManager().getPlugin("MMOItems");
mmmoItemsInstalled = mmmoItems != null;
if (mmmoItemsInstalled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.townyadvanced.townyresources.TownyResources;
import io.github.townyadvanced.townyresources.metadata.TownyResourcesGovernmentMetaDataController;
import io.github.townyadvanced.townyresources.util.ItemsAdderUtil;
import io.github.townyadvanced.townyresources.util.MMOItemsUtil;
import io.github.townyadvanced.townyresources.util.MythicMobsUtil;
import io.github.townyadvanced.townyresources.util.TownyResourcesMessagingUtil;
Expand Down Expand Up @@ -139,6 +140,17 @@ private static List<ItemStack> buildItemStackList(Player player, Set<Entry<Strin
continue;
}
}

// ItemsAdder integration
if (TownyResources.getPlugin().isItemsAdderInstalled()) {
ItemStack itemsAdderItem = ItemsAdderUtil.getItemStack(materialName, amount);
if (itemsAdderItem != null) {
itemStack = itemsAdderItem;
itemStackList.add(itemStack);
continue;
}
}

//Unknown material. Send error message
TownyResourcesMessagingUtil.sendErrorMsg(player, Translatable.of("townyresources.msg_err_cannot_collect_unknown_material", materialName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.townyadvanced.townyresources.TownyResources;
import io.github.townyadvanced.townyresources.objects.ResourceExtractionCategory;
import io.github.townyadvanced.townyresources.objects.ResourceOfferCategory;
import io.github.townyadvanced.townyresources.util.ItemsAdderUtil;
import io.github.townyadvanced.townyresources.util.MMOItemsUtil;
import io.github.townyadvanced.townyresources.util.MythicMobsUtil;

Expand Down Expand Up @@ -264,6 +265,11 @@ private static boolean isValidMaterial(String materialName) {
&& MMOItemsUtil.isValidItem(materialName))
return true;

// ItemsAdder integration
if (TownyResources.getPlugin().isItemsAdderInstalled()
&& ItemsAdderUtil.isValidItem(materialName))
return true;

return false; //Unknown material
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.townyadvanced.townyresources.util;

import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import dev.lone.itemsadder.api.CustomStack;

public class ItemsAdderUtil {

@Nullable
public static ItemStack getItemStack(String materialName, int amount) {
CustomStack itemsAdderItem = CustomStack.getInstance(materialName);
if (itemsAdderItem == null)
return null;
ItemStack itemStack = itemsAdderItem.getItemStack();
itemStack.setAmount(amount);
return itemStack;
}

public static String getMaterialNameForDisplay(String materialName) {
CustomStack itemsAdderItem = CustomStack.getInstance(materialName);
if (itemsAdderItem == null)
return null;
return itemsAdderItem.getDisplayName();
}

public static boolean isValidItem(String materialName) {
return CustomStack.getInstance(materialName) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ public static String formatMaterialNameForDisplay(String materialName) {
if (miName != null)
return miName;
}

// ItemsAdder integration
if(TownyResources.getPlugin().isItemsAdderInstalled()) {
String mmName = ItemsAdderUtil.getMaterialNameForDisplay(materialName);
if (mmName != null) {
return mmName;
}
}
} else {
if(TownyResources.getPlugin().isLanguageUtilsInstalled()) {
ItemStack fakeItemStack = new ItemStack(material);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ author: 'Goosius, LlmDL'
website: 'https://github.com/TownyAdvanced/TownyResources'
prefix: ${project.artifactId}
depend: [Towny]
softdepend: [SiegeWar,Dynmap-Towny,LangUtils,Slimefun,MythicMobs,MMOItems]
softdepend: [SiegeWar,Dynmap-Towny,LangUtils,Slimefun,MythicMobs,MMOItems,ItemsAdder]
folia-supported: true

description: This is an add-on plugin for Towny, which gives each town a unique set of automatically-extracted resources, and then protects the economic value of those resources with moderate limits to player resource extraction.
Expand Down

0 comments on commit b76c1a6

Please sign in to comment.