From f45d33272787bb3d92840cdc68a331008f443fbf Mon Sep 17 00:00:00 2001 From: Jikoo Date: Sun, 15 Nov 2020 12:22:25 -0500 Subject: [PATCH 1/7] Clarify download locations for older versions Hopefully this will help people figure out where they've gone wrong. Maybe I should be stating supported versions in release notes too. --- .../main/java/com/lishid/openinv/OpenInv.java | 13 ++++--- .../lishid/openinv/util/InternalAccessor.java | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/com/lishid/openinv/OpenInv.java b/plugin/src/main/java/com/lishid/openinv/OpenInv.java index b0a5a87..b8b524f 100644 --- a/plugin/src/main/java/com/lishid/openinv/OpenInv.java +++ b/plugin/src/main/java/com/lishid/openinv/OpenInv.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.function.Consumer; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -364,13 +365,16 @@ public class OpenInv extends JavaPlugin implements IOpenInv { this.setCommandExecutor("anycontainer", settingCommand); } else { - this.getLogger().info("Your version of CraftBukkit (" + this.accessor.getVersion() + ") is not supported."); - this.getLogger().info("If this version is a recent release, check for an update."); - this.getLogger().info("If this is an older version, ensure that you've downloaded the legacy support version."); + this.sendVersionError(this.getLogger()::warning); } } + private void sendVersionError(Consumer messageMethod) { + messageMethod.accept("Your server version (" + this.accessor.getVersion() + ") is not supported."); + messageMethod.accept("Please obtain an appropriate version here: " + accessor.getReleasesLink()); + } + private void setCommandExecutor(String commandName, CommandExecutor executor) { PluginCommand command = this.getCommand(commandName); if (command != null) { @@ -381,8 +385,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!this.accessor.isSupported()) { - sender.sendMessage("Your server version (" + this.accessor.getVersion() + ") is not supported."); - sender.sendMessage("Please check https://github.com/lishid/OpenInv/releases for an update."); + this.sendVersionError(sender::sendMessage); return true; } return false; diff --git a/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java b/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java index bd50289..f7e2648 100644 --- a/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java +++ b/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java @@ -48,6 +48,45 @@ public class InternalAccessor { } catch (Exception ignored) {} } + public String getReleasesLink() { + switch (version) { + case "1_4_5": + case "1_4_6": + case "v1_4_R1": + case "v1_5_R2": + case "v1_5_R3": + case "v1_6_R1": + case "v1_6_R2": + case "v1_6_R3": + case "v1_7_R1": + case "v1_7_R2": + case "v1_7_R3": + case "v1_7_R4": + case "v1_8_R1": + case "v1_8_R2": + case "v1_9_R1": + case "v1_9_R2": + case "v1_10_R1": + case "v1_11_R1": + case "v1_12_R1": + return "https://github.com/lishid/OpenInv/releases/tag/4.0.0 (OpenInv-legacy)"; + case "v1_13_R1": + return "https://github.com/lishid/OpenInv/releases/tag/4.0.0"; + case "v1_13_R2": + return "https://github.com/lishid/OpenInv/releases/tag/4.0.7"; + case "v1_14_R1": + return "https://github.com/lishid/OpenInv/releases/tag/4.1.1"; + case "v1_16_R1": + return "https://github.com/lishid/OpenInv/releases/tag/4.1.4"; + case "v1_8_R3": + case "v1_15_R1": + case "v1_16_R2": + case "v1_16_R3": + default: + return "https://github.com/lishid/OpenInv/releases"; + } + } + private T createObject(final Class assignableClass, final String className, final Object... params) throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, From 45de49569904273505f0695a8afb5fa5a83a0df3 Mon Sep 17 00:00:00 2001 From: Jikoo Date: Sun, 15 Nov 2020 12:26:36 -0500 Subject: [PATCH 2/7] Simplify command executor assignment a little more --- .../main/java/com/lishid/openinv/OpenInv.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/plugin/src/main/java/com/lishid/openinv/OpenInv.java b/plugin/src/main/java/com/lishid/openinv/OpenInv.java index b8b524f..ba33e94 100644 --- a/plugin/src/main/java/com/lishid/openinv/OpenInv.java +++ b/plugin/src/main/java/com/lishid/openinv/OpenInv.java @@ -352,17 +352,11 @@ public class OpenInv extends JavaPlugin implements IOpenInv { pm.registerEvents(new InventoryListener(this), this); // Register commands to their executors - OpenInvCommand openInv = new OpenInvCommand(this); - this.setCommandExecutor("openinv", openInv); - this.setCommandExecutor("openender", openInv); - this.setCommandExecutor("searchcontainer", new SearchContainerCommand(this)); - SearchInvCommand searchInv = new SearchInvCommand(this); - this.setCommandExecutor("searchinv", searchInv); - this.setCommandExecutor("searchender", searchInv); - this.setCommandExecutor("searchenchant", new SearchEnchantCommand(this)); - ContainerSettingCommand settingCommand = new ContainerSettingCommand(this); - this.setCommandExecutor("silentcontainer", settingCommand); - this.setCommandExecutor("anycontainer", settingCommand); + this.setCommandExecutor(new OpenInvCommand(this), "openinv", "openender"); + this.setCommandExecutor(new SearchContainerCommand(this), "searchcontainer"); + this.setCommandExecutor(new SearchInvCommand(this), "searchinv", "searchender"); + this.setCommandExecutor(new SearchEnchantCommand(this), "searchenchant"); + this.setCommandExecutor(new ContainerSettingCommand(this), "silentcontainer", "anycontainer"); } else { this.sendVersionError(this.getLogger()::warning); @@ -375,10 +369,12 @@ public class OpenInv extends JavaPlugin implements IOpenInv { messageMethod.accept("Please obtain an appropriate version here: " + accessor.getReleasesLink()); } - private void setCommandExecutor(String commandName, CommandExecutor executor) { - PluginCommand command = this.getCommand(commandName); - if (command != null) { - command.setExecutor(executor); + private void setCommandExecutor(CommandExecutor executor, String... commands) { + for (String commandName : commands) { + PluginCommand command = this.getCommand(commandName); + if (command != null) { + command.setExecutor(executor); + } } } From b2156edcc791a95c35bb853e5dc52d8e0f6aea90 Mon Sep 17 00:00:00 2001 From: Jikoo Date: Sun, 15 Nov 2020 12:59:59 -0500 Subject: [PATCH 3/7] Fix mistake in InventoryAccess grabbing ender chest --- api/src/main/java/com/lishid/openinv/util/InventoryAccess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java b/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java index 2f65dec..8a4afe5 100644 --- a/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java +++ b/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java @@ -73,7 +73,7 @@ public class InventoryAccess implements IInventoryAccess { } catch (ReflectiveOperationException ignored) {} } - inv = grabFieldOfTypeFromObject(ISpecialPlayerInventory.class, inventory); + inv = grabFieldOfTypeFromObject(expected, inventory); if (expected.isInstance(inv)) { return expected.cast(inv); From db8b67082ba01ec2688f9e16b9720b505b079e5f Mon Sep 17 00:00:00 2001 From: Jikoo Date: Sun, 15 Nov 2020 13:25:50 -0500 Subject: [PATCH 4/7] Fix up .gitignore a bit --- .gitignore | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index fc1dd97..b48a477 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,10 @@ **/.settings -**/.gitignore **/.project **/.classpath -**/.idea +**/.idea/ **.iml -**/target -**/bin -**/out -**dependency-reduced-pom.xml -**pom.xml.versionsBackup +**/target/ +**/bin/ +**/out/ +**/dependency-reduced-pom.xml +**/pom.xml.versionsBackup From 804d30bcc70d4508642d506f5fc40eb928628ecc Mon Sep 17 00:00:00 2001 From: Jikoo Date: Sun, 15 Nov 2020 13:26:59 -0500 Subject: [PATCH 5/7] tpyo --- .../java/com/lishid/openinv/util/InventoryAccess.java | 8 ++++++++ .../java/com/lishid/openinv/util/InternalAccessor.java | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java b/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java index 8a4afe5..9c2ffd7 100644 --- a/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java +++ b/api/src/main/java/com/lishid/openinv/util/InventoryAccess.java @@ -42,7 +42,15 @@ public class InventoryAccess implements IInventoryAccess { } catch (NoSuchMethodException ignored) {} } + /** + * @deprecated use {@link #isUsable()} + */ + @Deprecated public static boolean isUseable() { + return isUsable(); + } + + public static boolean isUsable() { return craftInventory != null && getInventory != null; } diff --git a/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java b/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java index f7e2648..96f3b7b 100644 --- a/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java +++ b/plugin/src/main/java/com/lishid/openinv/util/InternalAccessor.java @@ -44,7 +44,7 @@ public class InternalAccessor { Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest"); this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager"); this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer"); - this.supported = InventoryAccess.isUseable(); + this.supported = InventoryAccess.isUsable(); } catch (Exception ignored) {} } From 502f661be39ee85d300851dd571f3da226f12345 Mon Sep 17 00:00:00 2001 From: Jikoo Date: Wed, 25 Nov 2020 15:24:39 -0500 Subject: [PATCH 6/7] fix: Update 1.15 adapter to 1.15.2 --- internal/v1_15_R1/pom.xml | 2 +- .../internal/v1_15_R1/SpecialEnderChest.java | 5 +++-- .../v1_15_R1/SpecialPlayerInventory.java | 20 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/internal/v1_15_R1/pom.xml b/internal/v1_15_R1/pom.xml index eddab53..2000c76 100644 --- a/internal/v1_15_R1/pom.xml +++ b/internal/v1_15_R1/pom.xml @@ -32,7 +32,7 @@ org.spigotmc spigot - 1.15.1-R0.1-SNAPSHOT + 1.15.2-R0.1-SNAPSHOT provided diff --git a/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialEnderChest.java b/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialEnderChest.java index 52a5546..de70b04 100644 --- a/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialEnderChest.java +++ b/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialEnderChest.java @@ -33,6 +33,7 @@ import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEnderChest { @@ -115,7 +116,7 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn } @Override - public Location getLocation() { + public @Nullable Location getLocation() { return null; } @@ -204,7 +205,7 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn } @Override - public boolean isNotEmpty() { + public boolean isEmpty() { for (ItemStack itemstack : this.items) { if (!itemstack.isEmpty()) { diff --git a/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialPlayerInventory.java b/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialPlayerInventory.java index 19d2de6..ff59d3c 100644 --- a/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialPlayerInventory.java +++ b/internal/v1_15_R1/src/main/java/com/lishid/openinv/internal/v1_15_R1/SpecialPlayerInventory.java @@ -326,7 +326,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP } if (!this.a(itemstack, itemstack1)) { - remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount(); + remains -= Math.min(itemstack1.getMaxStackSize(), this.getMaxStackSize()) - itemstack1.getCount(); } if (remains <= 0) { @@ -461,14 +461,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP k = this.getMaxStackSize() - itemstack1.getCount(); } - if (k == 0) { - return j; - } else { + if (k != 0) { j -= k; itemstack1.add(k); itemstack1.d(5); - return j; } + return j; } @Override @@ -656,12 +654,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP } @Override - public boolean isNotEmpty() { - Iterator iterator = this.items.iterator(); + public boolean isEmpty() { + Iterator iterator = this.items.iterator(); ItemStack itemstack; while (iterator.hasNext()) { - itemstack = (ItemStack)iterator.next(); + itemstack = iterator.next(); if (!itemstack.isEmpty()) { return false; } @@ -670,7 +668,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP iterator = this.armor.iterator(); while (iterator.hasNext()) { - itemstack = (ItemStack)iterator.next(); + itemstack = iterator.next(); if (!itemstack.isEmpty()) { return false; } @@ -679,7 +677,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP iterator = this.extraSlots.iterator(); while (iterator.hasNext()) { - itemstack = (ItemStack)iterator.next(); + itemstack = iterator.next(); if (!itemstack.isEmpty()) { return false; } @@ -711,7 +709,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP ItemStack itemstack = this.armor.get(0); int index = i; if (itemstack.getItem() instanceof ItemArmor) { - itemstack.damage((int) f, this.player, (entityhuman) -> entityhuman.c(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, index))); + itemstack.damage((int) f, this.player, (entityhuman) -> entityhuman.broadcastItemBreak(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, index))); } } } From dad00d2d9c86981e0c24c9fb7af72985b1403412 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 26 Nov 2020 11:05:45 -0500 Subject: [PATCH 7/7] build: Add action to build and automatically release files (#170) Auto-release is gonna get a nice live test at a later date. --- .github/workflows/ci.yml | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6489274 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,93 @@ +name: OpenInv CI + +on: + push: + create: + types: [tag] + pull_request_target: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: true + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set Up Java + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + # Use cache to speed up build + - name: Cache Maven Repo + uses: actions/cache@v2 + id: cache + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + + # If the cache was not present, run BuildTools to install the relevant versions to Maven. + # This will take approximately forever. + - name: Install Spigot Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: | + mkdir ~/buildtools + cd ~/buildtools + wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar + java -jar BuildTools.jar --rev 1.8.8 + java -jar BuildTools.jar --rev 1.15.2 + java -jar BuildTools.jar --rev 1.16.3 + java -jar BuildTools.jar --rev 1.16.4 + + - name: Build With Maven + run: mvn -e clean package -am -P all + + # Upload artifacts + - name: Upload Distributable Jar + id: upload-final + uses: actions/upload-artifact@v2 + with: + name: dist + path: ./target/OpenInv.jar + - name: Upload API Jar + id: upload-api + uses: actions/upload-artifact@v2 + with: + name: api + path: ./api/target/openinvapi*.jar + + release: + name: Create Github Release + needs: [ build ] + if: github.event_name == 'create' && github.event.ref_type == 'tag' + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Download Artifacts + uses: actions/download-artifact@v2 + + - name: Create Release + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: true + prerelease: false + + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create-release.outputs.upload_url }} + asset_path: ./OpenInv.jar + asset_name: OpenInv.jar + asset_content_type: application/java-archive \ No newline at end of file