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 "github-actions@github.com"

- 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"
}
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ plugins {
// id("com.github.johnrengelman.shadow") version "8.1.1"
}

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

repositories {
mavenLocal()
mavenCentral()
Expand All @@ -33,6 +29,10 @@ repositories {
name = "bstats"
url = URI("https://oss.sonatype.org/content/groups/public/")
}
maven {
name = "codemc-repo"
url = URI("https://repo.codemc.io/repository/maven-public/")
}
}

java {
Expand All @@ -44,6 +44,7 @@ dependencies {
// paperweight.foliaDevBundle("1.21-R0.1-SNAPSHOT")
// paperweight.devBundle("com.example.paperfork", "1.21-R0.1-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:3.0.2")
implementation("com.griefcraft:lwc:2.4.1")

// Add ASM dependency to support Java 21 class files
implementation("org.ow2.asm:asm:9.7")
Expand Down Expand Up @@ -76,6 +77,7 @@ bukkitPluginYaml {
load = BukkitPluginYaml.PluginLoadOrder.STARTUP
authors = listOf("Chaws", "Pugabyte", "AllTheCode", "RoboMWM", "Big_Scary")
apiVersion = "1.21"
softDepend = listOf("LWC")
commands.register("autosort") {
description = "Toggles auto-sorting options."
permission = "automaticinventory.sortchests"
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group=dev.chaws.automaticinventory
version=4.1.0
description=Automatic Inventory PaperMC Plugin
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.chaws.automaticinventory.configuration.Features;
import dev.chaws.automaticinventory.configuration.GlobalConfig;
import dev.chaws.automaticinventory.configuration.PlayerConfig;
import dev.chaws.automaticinventory.hooks.LWCHook;
import dev.chaws.automaticinventory.listeners.*;
import dev.chaws.automaticinventory.messaging.LocalizedMessages;
import dev.chaws.automaticinventory.utilities.Metrics;
Expand Down Expand Up @@ -45,6 +46,10 @@ public void onEnable() {
this.registerCommand("depositall", new DepositAllCommand());
this.registerCommand("quickdeposit", new QuickDepositCommand());

if (pluginManager.getPlugin("LWC") != null) {
LWCHook.enable();
}

try {
new Metrics(this, 16822);
} catch (Throwable ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.chaws.automaticinventory.messaging.Messages;
import dev.chaws.automaticinventory.utilities.Chat;
import dev.chaws.automaticinventory.utilities.Level;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -25,6 +26,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

var playerConfig = PlayerConfig.fromPlayer(player);

// Guard to prevent out of index error
if (args.length < 1) {
Chat.sendMessage(player, NamedTextColor.GOLD, "Usage: /autosort [chest|inv]");
return false;
}

var optionName = args[0].toLowerCase();
if (optionName.startsWith("chest")) {
if (!AutomaticInventory.hasPermission(Features.SortChests, player)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.chaws.automaticinventory.tasks.AsyncChestDepositTask;
import dev.chaws.automaticinventory.utilities.Chat;
import dev.chaws.automaticinventory.utilities.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -28,6 +29,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 All @@ -51,9 +54,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
var startY = player.getEyeLocation().getBlockY();
var startX = player.getEyeLocation().getBlockX();
var startZ = player.getEyeLocation().getBlockZ();
Thread thread = new AsyncChestDepositTask(world, snapshots, minY, maxY, startX, startY, startZ, player);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
Bukkit.getScheduler().runTaskAsynchronously(AutomaticInventory.instance, () -> new AsyncChestDepositTask(world, snapshots, minY, maxY, startX, startY, startZ, player).start());

if (!playerConfig.hasUsedDepositAll()) {
playerConfig.setUsedDepositAll(true);
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
33 changes: 33 additions & 0 deletions src/main/java/dev/chaws/automaticinventory/hooks/LWCHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.chaws.automaticinventory.hooks;

import com.griefcraft.lwc.LWC;
import org.bukkit.Location;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.BlockInventoryHolder;
import org.bukkit.inventory.Inventory;

public class LWCHook {

private static boolean enabled = false;

public static void enable() {
enabled = true;
}

public static boolean canUseContainer(Inventory inventory, Player player) {
if (inventory.getHolder() instanceof BlockInventoryHolder || inventory.getHolder() instanceof DoubleChest) {
Location location = inventory.getLocation();
return canUseContainer(location, player);
}
return false;
}

public static boolean canUseContainer(Location location, Player player) {
if (enabled) {
var protection = LWC.getInstance().findProtection(location);
return protection != null && protection.isRealOwner(player);
}
return true;
}
}
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 @@ -3,6 +3,7 @@
import dev.chaws.automaticinventory.AutomaticInventory;
import dev.chaws.automaticinventory.configuration.Features;
import dev.chaws.automaticinventory.configuration.PlayerConfig;
import dev.chaws.automaticinventory.hooks.LWCHook;
import dev.chaws.automaticinventory.messaging.Messages;
import dev.chaws.automaticinventory.tasks.InventorySorter;
import dev.chaws.automaticinventory.utilities.Chat;
Expand Down Expand Up @@ -31,16 +32,18 @@ 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())) {
return;
}
if (LWCHook.canUseContainer(topInventory, player)) {
if (!InventoryUtilities.isSortableChestInventory(topInventory, event.getView().title().examinableName())) {
return;
}

var sorter = new InventorySorter(topInventory, 0);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(AutomaticInventory.instance, sorter, 1L);
var sorter = new InventorySorter(topInventory, 0);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(AutomaticInventory.instance, sorter, 1L);

if (!playerConfig.hasReceivedChestSortInfo()) {
Chat.sendMessage(player, Level.Info, Messages.ChestSortEducation3);
playerConfig.setReceivedChestSortInfo(true);
if (!playerConfig.hasReceivedChestSortInfo()) {
Chat.sendMessage(player, Level.Info, Messages.ChestSortEducation3);
playerConfig.setReceivedChestSortInfo(true);
}
}
}
}
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,
}
Loading