Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/JustAHuman-xD/feature/slim…
Browse files Browse the repository at this point in the history
…e-hud-integration'

# Conflicts:
#	.github/workflows/maven.yml
#	pom.xml
#	src/main/java/io/github/sefiraat/networks/Networks.java
  • Loading branch information
ybw0014 committed Jul 14, 2024
2 parents 1514bf7 + 63e6e4d commit 4904af6
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 8 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test Build

on:
pull_request:
branches:
- master

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]

- name: Set up JDK 16
uses: actions/[email protected]
with:
java-version: 16
distribution: adopt

- name: Build with Maven
run: mvn package
31 changes: 31 additions & 0 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and Upload

on:
push:
branches:
- master

jobs:
build:
name: Build and Upload
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, '[ci skip]') == false

steps:
- uses: actions/[email protected]

- name: Set up JDK 16
uses: actions/[email protected]
with:
java-version: 16
distribution: adopt

- name: Build with Maven
run: mvn package

- name: Upload to Builds
uses: WalshyDev/blob-builds/gh-action@main
with:
project: Networks
apiToken: ${{ secrets.BLOB_BUILDS_API_TOKEN }}
releaseNotes: ${{ github.event.head_commit.message }}
16 changes: 11 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.sefiraat</groupId>
<artifactId>Networks</artifactId>
<version>MODIFIED_1.2.0</version>
<version>MODIFIED</version>

<distributionManagement>
<repository>
Expand Down Expand Up @@ -58,7 +58,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
Expand Down Expand Up @@ -171,7 +171,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -194,16 +194,22 @@
<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>
<version>2023.2</version>
<version>2024.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.221</version>
<version>2.2.012</version>
<scope>provided</scope>
</dependency>

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,6 +3,7 @@
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.HudCallbacks;
import io.github.sefiraat.networks.slimefun.NetheoPlants;
import io.github.sefiraat.networks.slimefun.NetworkSlimefunItems;
import io.github.sefiraat.networks.slimefun.network.NetworkController;
Expand Down Expand Up @@ -35,7 +36,7 @@ public class Networks extends JavaPlugin implements SlimefunAddon {
private SupportedPluginManager supportedPluginManager;

public Networks() {
this.username = "ybw0014";
this.username = "SlimefunGuguProject";
this.repo = "Networks";
this.branch = "master";
}
Expand Down Expand Up @@ -78,11 +79,18 @@ public void tryUpdate() {
public void setupSlimefun() {
NetworkSlimefunItems.setup();
WikiUtils.setupJson(this);
if (supportedPluginManager.isNetheopoiesis()){
if (supportedPluginManager.isNetheopoiesis()) {
try {
NetheoPlants.setup();
} catch (NoClassDefFoundError e) {
getLogger().severe("你必须更新下界乌托邦才能让网络添加相关功能.");
getLogger().severe("你必须更新下界乌托邦才能让网络添加相关功能。");
}
}
if (supportedPluginManager.isSlimeHud()) {
try {
HudCallbacks.setup();
} catch (NoClassDefFoundError e) {
getLogger().severe("你必须更新 SlimeHUD 才能让网络添加相关功能。");
}
}
}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.sefiraat.networks.slimefun;

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;
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ softdepend:
- GuizhanLibPlugin
- InfinityExpansion
- Netheopoiesis
- SlimeHUD
- WildChests
commands:
networks:
Expand Down

0 comments on commit 4904af6

Please sign in to comment.