forked from Sefiraat/Networks
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/JustAHuman-xD/feature/slim…
…e-hud-integration' # Conflicts: # .github/workflows/maven.yml # pom.xml # src/main/java/io/github/sefiraat/networks/Networks.java
- Loading branch information
Showing
7 changed files
with
142 additions
and
8 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,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 |
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,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 }} |
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
59 changes: 59 additions & 0 deletions
59
src/main/java/io/github/sefiraat/networks/slimefun/HudCallbacks.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,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; | ||
} | ||
} |
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