This commit is contained in:
Telesphoreo 2020-12-19 14:15:48 -06:00
commit c8d16a590f
No known key found for this signature in database
GPG key ID: 50B67E055A6F167C
8 changed files with 180 additions and 43 deletions

93
.github/workflows/ci.yml vendored Normal file
View file

@ -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

13
.gitignore vendored
View file

@ -1,11 +1,10 @@
**/.settings **/.settings
**/.gitignore
**/.project **/.project
**/.classpath **/.classpath
**/.idea **/.idea/
**.iml **.iml
**/target **/target/
**/bin **/bin/
**/out **/out/
**dependency-reduced-pom.xml **/dependency-reduced-pom.xml
**pom.xml.versionsBackup **/pom.xml.versionsBackup

View file

@ -42,7 +42,15 @@ public class InventoryAccess implements IInventoryAccess {
} catch (NoSuchMethodException ignored) {} } catch (NoSuchMethodException ignored) {}
} }
/**
* @deprecated use {@link #isUsable()}
*/
@Deprecated
public static boolean isUseable() { public static boolean isUseable() {
return isUsable();
}
public static boolean isUsable() {
return craftInventory != null && getInventory != null; return craftInventory != null && getInventory != null;
} }
@ -73,7 +81,7 @@ public class InventoryAccess implements IInventoryAccess {
} catch (ReflectiveOperationException ignored) {} } catch (ReflectiveOperationException ignored) {}
} }
inv = grabFieldOfTypeFromObject(ISpecialPlayerInventory.class, inventory); inv = grabFieldOfTypeFromObject(expected, inventory);
if (expected.isInstance(inv)) { if (expected.isInstance(inv)) {
return expected.cast(inv); return expected.cast(inv);

View file

@ -32,7 +32,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version> <version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -33,6 +33,7 @@ import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEnderChest { public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEnderChest {
@ -115,7 +116,7 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
} }
@Override @Override
public Location getLocation() { public @Nullable Location getLocation() {
return null; return null;
} }
@ -204,7 +205,7 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
} }
@Override @Override
public boolean isNotEmpty() { public boolean isEmpty() {
for (ItemStack itemstack : this.items) { for (ItemStack itemstack : this.items) {
if (!itemstack.isEmpty()) { if (!itemstack.isEmpty()) {

View file

@ -326,7 +326,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
if (!this.a(itemstack, itemstack1)) { 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) { if (remains <= 0) {
@ -461,14 +461,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
k = this.getMaxStackSize() - itemstack1.getCount(); k = this.getMaxStackSize() - itemstack1.getCount();
} }
if (k == 0) { if (k != 0) {
return j;
} else {
j -= k; j -= k;
itemstack1.add(k); itemstack1.add(k);
itemstack1.d(5); itemstack1.d(5);
return j;
} }
return j;
} }
@Override @Override
@ -656,12 +654,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public boolean isNotEmpty() { public boolean isEmpty() {
Iterator iterator = this.items.iterator(); Iterator<ItemStack> iterator = this.items.iterator();
ItemStack itemstack; ItemStack itemstack;
while (iterator.hasNext()) { while (iterator.hasNext()) {
itemstack = (ItemStack)iterator.next(); itemstack = iterator.next();
if (!itemstack.isEmpty()) { if (!itemstack.isEmpty()) {
return false; return false;
} }
@ -670,7 +668,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
iterator = this.armor.iterator(); iterator = this.armor.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
itemstack = (ItemStack)iterator.next(); itemstack = iterator.next();
if (!itemstack.isEmpty()) { if (!itemstack.isEmpty()) {
return false; return false;
} }
@ -679,7 +677,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
iterator = this.extraSlots.iterator(); iterator = this.extraSlots.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
itemstack = (ItemStack)iterator.next(); itemstack = iterator.next();
if (!itemstack.isEmpty()) { if (!itemstack.isEmpty()) {
return false; return false;
} }
@ -711,7 +709,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
ItemStack itemstack = this.armor.get(0); ItemStack itemstack = this.armor.get(0);
int index = i; int index = i;
if (itemstack.getItem() instanceof ItemArmor) { 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)));
} }
} }
} }

View file

@ -41,6 +41,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.Consumer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -351,38 +352,36 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
pm.registerEvents(new InventoryListener(this), this); pm.registerEvents(new InventoryListener(this), this);
// Register commands to their executors // Register commands to their executors
OpenInvCommand openInv = new OpenInvCommand(this); this.setCommandExecutor(new OpenInvCommand(this), "openinv", "openender");
this.setCommandExecutor("openinv", openInv); this.setCommandExecutor(new SearchContainerCommand(this), "searchcontainer");
this.setCommandExecutor("openender", openInv); this.setCommandExecutor(new SearchInvCommand(this), "searchinv", "searchender");
this.setCommandExecutor("searchcontainer", new SearchContainerCommand(this)); this.setCommandExecutor(new SearchEnchantCommand(this), "searchenchant");
SearchInvCommand searchInv = new SearchInvCommand(this); this.setCommandExecutor(new ContainerSettingCommand(this), "silentcontainer", "anycontainer");
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);
} else { } else {
this.getLogger().info("Your version of CraftBukkit (" + this.accessor.getVersion() + ") is not supported."); this.sendVersionError(this.getLogger()::warning);
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.");
} }
} }
private void setCommandExecutor(String commandName, CommandExecutor executor) { private void sendVersionError(Consumer<String> messageMethod) {
PluginCommand command = this.getCommand(commandName); messageMethod.accept("Your server version (" + this.accessor.getVersion() + ") is not supported.");
if (command != null) { messageMethod.accept("Please obtain an appropriate version here: " + accessor.getReleasesLink());
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);
}
} }
} }
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!this.accessor.isSupported()) { if (!this.accessor.isSupported()) {
sender.sendMessage("Your server version (" + this.accessor.getVersion() + ") is not supported."); this.sendVersionError(sender::sendMessage);
sender.sendMessage("Please check https://github.com/lishid/OpenInv/releases for an update.");
return true; return true;
} }
return false; return false;

View file

@ -44,10 +44,49 @@ public class InternalAccessor {
Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest"); Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest");
this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager"); this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager");
this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer"); this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer");
this.supported = InventoryAccess.isUseable(); this.supported = InventoryAccess.isUsable();
} catch (Exception ignored) {} } 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> T createObject(final Class<? extends T> assignableClass, final String className, private <T> T createObject(final Class<? extends T> assignableClass, final String className,
final Object... params) throws ClassCastException, ClassNotFoundException, final Object... params) throws ClassCastException, ClassNotFoundException,
InstantiationException, IllegalAccessException, IllegalArgumentException, InstantiationException, IllegalAccessException, IllegalArgumentException,