Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] SlimeHUD Integration #185

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@
<version>8d1af6c570</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.schntgaispock</groupId>
<artifactId>SlimeHUD</artifactId>
<version>1.2.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bgsoftware</groupId>
<artifactId>WildChestsAPI</artifactId>
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/io/github/sefiraat/networks/Networks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import io.github.sefiraat.networks.commands.NetworksMain;
import io.github.sefiraat.networks.managers.ListenerManager;
import io.github.sefiraat.networks.managers.SupportedPluginManager;
import io.github.sefiraat.networks.slimefun.NetheoPlants;
import io.github.sefiraat.networks.integrations.HudCallbacks;
import io.github.sefiraat.networks.integrations.NetheoPlants;
import io.github.sefiraat.networks.slimefun.NetworkSlimefunItems;
import io.github.sefiraat.networks.slimefun.network.NetworkController;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.BlobBuildUpdater;
import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater;

import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
import org.bukkit.plugin.PluginManager;
Expand Down Expand Up @@ -67,13 +68,20 @@ public void tryUpdate() {

public void setupSlimefun() {
NetworkSlimefunItems.setup();
if (supportedPluginManager.isNetheopoiesis()){
if (supportedPluginManager.isNetheopoiesis()) {
try {
NetheoPlants.setup();
} catch (NoClassDefFoundError e) {
getLogger().severe("Netheopoiesis must be updated to meet Networks' requirements.");
}
}
if (supportedPluginManager.isSlimeHud()) {
try {
HudCallbacks.setup();
} catch (NoClassDefFoundError e) {
getLogger().severe("SlimeHUD must be updated to meet Networks' requirements.");
}
}
}

public void setupMetrics() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.sefiraat.networks.integrations;

import io.github.schntgaispock.slimehud.SlimeHUD;
import io.github.schntgaispock.slimehud.util.HudBuilder;
import io.github.schntgaispock.slimehud.waila.HudController;
import io.github.sefiraat.networks.network.stackcaches.QuantumCache;
import io.github.sefiraat.networks.slimefun.network.NetworkGreedyBlock;
import io.github.sefiraat.networks.slimefun.network.NetworkQuantumStorage;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class HudCallbacks {
private static final String EMPTY = "&7| Empty";
public static void setup() {
HudController controller = SlimeHUD.getHudController();

controller.registerCustomHandler(NetworkQuantumStorage.class, request -> {
Location location = request.getLocation();
QuantumCache cache = NetworkQuantumStorage.getCaches().get(location);
if (cache == null || cache.getItemStack() == null) {
return EMPTY;
}

return format(cache.getItemStack(), cache.getAmount(), cache.getLimit());
});

controller.registerCustomHandler(NetworkGreedyBlock.class, request -> {
Location location = request.getLocation();
BlockMenu menu = BlockStorage.getInventory(location);
if (menu == null) {
return EMPTY;
}

ItemStack templateStack = menu.getItemInSlot(NetworkGreedyBlock.TEMPLATE_SLOT);
if (templateStack == null || templateStack.getType().isAir()) {
return EMPTY;
}

ItemStack itemStack = menu.getItemInSlot(NetworkGreedyBlock.INPUT_SLOT);
int amount = itemStack == null || itemStack.getType() != templateStack.getType() ? 0 : itemStack.getAmount();
return format(templateStack, amount, templateStack.getMaxStackSize());
});
}

private static String format(ItemStack itemStack, int amount, int limit) {
ItemMeta meta = itemStack.getItemMeta();
String amountStr = HudBuilder.getAbbreviatedNumber(amount);
String limitStr = HudBuilder.getAbbreviatedNumber(limit);
String itemName = meta != null && meta.hasDisplayName()
? meta.getDisplayName()
: ChatUtils.humanize(itemStack.getType().name());

return "&7| &f" + itemName + " &7| " + amountStr + "/" + limitStr;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sefiraat.networks.slimefun;
package io.github.sefiraat.networks.integrations;

import dev.sefiraat.netheopoiesis.api.items.DoNothingSeed;
import dev.sefiraat.netheopoiesis.api.items.HarvestableSeed;
Expand All @@ -9,6 +9,7 @@
import dev.sefiraat.netheopoiesis.utils.Skulls;
import dev.sefiraat.netheopoiesis.utils.Theme;
import io.github.sefiraat.networks.Networks;
import io.github.sefiraat.networks.slimefun.NetworksSlimefunItemStacks;
import io.github.sefiraat.networks.utils.StackUtils;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class SupportedPluginManager {

private final boolean infinityExpansion;
private final boolean netheopoiesis;
private final boolean slimeHud;

// region First Tick Only Registrations
private boolean mcMMO;
Expand All @@ -22,6 +23,7 @@ public SupportedPluginManager() {
instance = this;
this.infinityExpansion = Bukkit.getPluginManager().isPluginEnabled("InfinityExpansion");
this.netheopoiesis = Bukkit.getPluginManager().isPluginEnabled("Netheopoiesis");
this.slimeHud = Bukkit.getPluginManager().isPluginEnabled("SlimeHUD");
Networks.getInstance()
.getServer()
.getScheduler()
Expand All @@ -41,6 +43,10 @@ public boolean isNetheopoiesis() {
return netheopoiesis;
}

public boolean isSlimeHud() {
return slimeHud;
}

public boolean isMcMMO() {
return mcMMO;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ depend:
softdepend:
- InfinityExpansion
- Netheopoiesis
- SlimeHUD
- WildChests
commands:
networks:
Expand Down