Skip to content
Open
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
77 changes: 63 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:

steps:
- name: Checkout Git repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Restore Gradle cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

Expand All @@ -35,24 +35,73 @@ jobs:
java-version: 21

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/actions/wrapper-validation@v3

- name: Build with Gradle
run: |
chmod +x gradlew
./gradlew build --stacktrace

- name: Install rename
run: sudo apt-get install -y rename

# This is only needed when using shadow jar
# - name: Rename file
# run: |
# cd ./build/libs/
# rename -f 's/-all//;' '' *

- name: Archive plugin jars on GitHub
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: AutomaticInventory
path: build/libs
overwrite: 'true'

release:
name: Release
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

permissions:
contents: write # Required to create/delete tags and releases

steps:
- name: Checkout Git repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Git user
run: |
git config user.name "github-actions"
git config user.email "[email protected]"

- name: Get short commit SHA
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

- name: Delete previous release (if exists)
continue-on-error: true
run: |
gh release delete latest --yes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete previous tag (if exists)
continue-on-error: true
run: |
git tag -d latest || true
git push origin :refs/tags/latest || true

- name: Create new tag
run: |
git tag latest
git push origin latest

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: AutomaticInventory
path: artifacts

- name: Create GitHub Release
run: |
ls artifacts # optional: see what's there
gh release create latest artifacts/* \
--title "Latest Build (${{ steps.vars.outputs.sha_short }})" \
--notes "Automated build from commit ${{ steps.vars.outputs.sha_short }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
"java.configuration.updateBuildConfiguration": "automatic",
"java.compile.nullAnalysis.mode": "automatic"
}
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
}

group = "dev.chaws.automaticinventory"
version = "4.0.0"
version = "4.1.0"
description = "Automatic Inventory PaperMC Plugin"

repositories {
Expand Down Expand Up @@ -74,7 +74,7 @@ bukkitPluginYaml {
main = "dev.chaws.automaticinventory.AutomaticInventory"
// TODO: Try POSTWORLD
load = BukkitPluginYaml.PluginLoadOrder.STARTUP
authors = listOf("Chaws", "Pugabyte", "AllTheCode", "RoboMWM", "Big_Scary")
authors = listOf("Bittiez", "Chaws", "Pugabyte", "AllTheCode", "RoboMWM", "Big_Scary")
apiVersion = "1.21"
commands.register("autosort") {
description = "Toggles auto-sorting options."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class AutoSortCommand extends AutomaticInventoryCommand {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
if (!(sender instanceof Player player) || args.length == 0) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}

Chat.sendMessage(player, Level.Info, Messages.StartingDepositAll);

//gather snapshots of adjacent chunks
var location = player.getLocation();
var centerChunk = location.getChunk();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static PlayerConfig fromPlayer(Player player) {
if (data.isEmpty()) {
return new PlayerConfig(player);
} else {
return (PlayerConfig)data.get(0).value();
return (PlayerConfig) data.get(0).value();
}
}

Expand Down Expand Up @@ -176,9 +176,9 @@ public void setGotQuickDepositInfo(boolean newValue) {
}

public void saveChanges() {
if (!this.isDirty) {
return;
}
if (!this.isDirty) {
return;
}

this.waitForLoadComplete();
this.savingThread = new Thread(new DataSaver());
Expand Down Expand Up @@ -242,17 +242,21 @@ private void readDataFromFile() {
needRetry = false;
FileConfiguration config = YamlConfiguration.loadConfiguration(this.playerConfigFile);
this.sortChests = config.getBoolean("Sort Chests", GlobalConfig.autosortEnabledByDefault);
this.sortInventory = config.getBoolean("Sort Personal Inventory", GlobalConfig.autosortEnabledByDefault);
this.quickDepositEnabled = config.getBoolean("Quick Deposit Enabled", GlobalConfig.quickDepositEnabledByDefault);
this.autoRefillEnabled = config.getBoolean("Auto Refill Enabled", GlobalConfig.autoRefillEnabledByDefault);
this.sortInventory = config.getBoolean("Sort Personal Inventory",
GlobalConfig.autosortEnabledByDefault);
this.quickDepositEnabled = config.getBoolean("Quick Deposit Enabled",
GlobalConfig.quickDepositEnabledByDefault);
this.autoRefillEnabled = config.getBoolean("Auto Refill Enabled",
GlobalConfig.autoRefillEnabledByDefault);
this.usedQuickDeposit = config.getBoolean("Used Quick Deposit", false);
this.receivedChestSortInfo = config.getBoolean("Received Messages.Chest Inventory", false);
this.receivedInventorySortInfo = config.getBoolean("Received Messages.Personal Inventory", false);
this.receivedRestackInfo = config.getBoolean("Received Messages.Restacker", false);
this.receivedDepositAllInfo = config.getBoolean("Received Messages.Deposit All", false);
}

//if there's any problem with the file's content, retry up to 5 times with 5 milliseconds between
// if there's any problem with the file's content, retry up to 5 times with 5
// milliseconds between
catch (Exception e) {
latestException = e;
needRetry = true;
Expand All @@ -268,10 +272,11 @@ private void readDataFromFile() {

} while (needRetry && retriesRemaining >= 0);

//if last attempt failed, log information about the problem
// if last attempt failed, log information about the problem
if (needRetry) {
var errors = new StringWriter();
latestException.printStackTrace(new PrintWriter(errors));
if (latestException != null)
latestException.printStackTrace(new PrintWriter(errors));
AutomaticInventory.log.info("Failed to load data for " + playerID + " " + errors);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.chaws.automaticinventory.configuration.GlobalConfig;
import dev.chaws.automaticinventory.configuration.PlayerConfig;
import dev.chaws.automaticinventory.tasks.AutoRefillHotBarTask;
import dev.chaws.automaticinventory.utilities.ItemUtilities;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onInventoryOpen(InventoryOpenEvent event) {

if (!player.isSneaking() && PlayerConfig.featureEnabled(Features.SortChests, player)) {
var topInventory = event.getView().getTopInventory();
if (!InventoryUtilities.isSortableChestInventory(topInventory, event.getView().getTitle())) {
if (!InventoryUtilities.isSortableChestInventory(topInventory, event.getView().title().examinableName())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void initialize(File dataFolder) {
instance.addDefault(defaults, Messages.AutoRefillHelp, "Options are /autorefill toggle, /autorefill enable, and /autorefill disable.");
instance.addDefault(defaults, Messages.AutoRefillEnabled, "Auto refill enabled.");
instance.addDefault(defaults, Messages.AutoRefillDisabled, "Auto refill disabled.");
instance.addDefault(defaults, Messages.StartingDepositAll, "Checking for items to deposit.. This may take a moment.");

//load the configuration file
FileConfiguration config = YamlConfiguration.loadConfiguration(localizationFile);
Expand Down Expand Up @@ -108,12 +109,10 @@ synchronized public String getMessage(Messages messageID, String... args) {
}

private static class LocalizedMessage {
public Messages id;
public String text;
public String notes;

public LocalizedMessage(Messages id, String text, String notes) {
this.id = id;
this.text = text;
this.notes = notes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public enum Messages {
QuickDepositDisabled,
AutoRefillHelp,
AutoRefillEnabled,
AutoRefillDisabled
AutoRefillDisabled,
StartingDepositAll,
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ public void run() {
var state = block.getState();
if (state instanceof InventoryHolder chest) {
var chestInventory = chest.getInventory();
if (!this.respectExclusions || InventoryUtilities.isSortableChestInventory(chestInventory, state instanceof Nameable nameable ? nameable.getCustomName() : null)) {
String name = chest.getClass().getSimpleName();
if (state instanceof Nameable nameable && nameable.customName() != null) {
name = nameable.customName().toString();
}
if (!this.respectExclusions || InventoryUtilities.isSortableChestInventory(chestInventory, name)) {
var playerInventory = player.getInventory();

var deposits = InventoryUtilities.depositMatching(playerInventory, chestInventory, false);
Expand All @@ -195,7 +199,7 @@ public void run() {
}

var chain = new QuickDepositChain(this.remainingChestLocations, this.runningDepositRecord, this.player, this.respectExclusions);
Bukkit.getScheduler().runTaskLater(AutomaticInventory.instance, chain, 1L);
Bukkit.getScheduler().runTaskLater(AutomaticInventory.instance, chain, 5L);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.chaws.automaticinventory.configuration.PlayerConfig;
import dev.chaws.automaticinventory.messaging.Messages;
import dev.chaws.automaticinventory.utilities.Chat;
import dev.chaws.automaticinventory.utilities.ItemUtilities;
import dev.chaws.automaticinventory.utilities.Level;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package dev.chaws.automaticinventory.tasks;

import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class InventorySorter implements Runnable {
Expand Down Expand Up @@ -73,18 +71,11 @@ public int compare(ItemStack a, ItemStack b) {
return result;
}

//noinspection removal
var aData = a.getData();
//noinspection removal
var bData = b.getData();
var aMeta = a.getItemMeta();
var bMeta = b.getItemMeta();

//noinspection deprecation
var aDataData = aData == null ? null : aData.getData();
//noinspection deprecation
var bDataData = bData == null ? null : bData.getData();

if (aDataData != null && bDataData != null) {
result = Byte.compare(bDataData, aDataData);
if (aMeta != null && bMeta != null) {
result = bMeta.toString().compareTo(aMeta.toString());
if (result != 0) {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.chaws.automaticinventory.utilities;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Barrel;
import org.bukkit.block.Block;
Expand Down
Loading