diff --git a/.travis.yml b/.travis.yml
index f91cc32..02d3bb8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,10 @@ language: java
before_install:
- cd BuildTools
-- bash build.sh
+- jdk_switcher use openjdk8
+- bash build-pre1.17.sh
+- jdk_switcher use openjdk16
+- bash build-1.17+.sh
- cd ../
install:
diff --git a/BuildTools/build-1.17+.sh b/BuildTools/build-1.17+.sh
new file mode 100644
index 0000000..07f20d7
--- /dev/null
+++ b/BuildTools/build-1.17+.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+echo "Checking BuildTools 1.17+ cache"
+
+#Local Maven Repo
+MAVEN_DIR="$HOME/.m2"
+
+#CraftBukkit in local repo
+CRAFTBUKKIT="${MAVEN_DIR}/repository/org/bukkit/craftbukkit"
+
+#Versions
+array=("1.17")
+
+#Download BuildTools jar
+curl -s -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
+
+for i in "${array[@]}"
+do
+ VERSION_DIR="${CRAFTBUKKIT}/${i}-R0.1-SNAPSHOT"
+
+ if [ -d "$VERSION_DIR" ]; then
+ echo "CraftBukkit version ${i} is cached!"
+ echo "Checking for latest commit! "
+ java -jar BuildTools.jar --rev ${i} --compile craftbukkit --compile-if-changed --remapped > /dev/null 2>&1
+ echo "Finished Check."
+ else
+ echo "CraftBukkit version ${i} isn't cached!"
+ echo "Running BuildTools!"
+ java -jar BuildTools.jar --rev ${i} --compile craftbukkit --remapped > /dev/null 2>&1
+ echo "Compiled CraftBukkit ${i}"
+ fi
+done
diff --git a/BuildTools/build.sh b/BuildTools/build-pre1.17.sh
similarity index 95%
rename from BuildTools/build.sh
rename to BuildTools/build-pre1.17.sh
index 995bd1d..41c489b 100644
--- a/BuildTools/build.sh
+++ b/BuildTools/build-pre1.17.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-echo "Checking BuildTools cache"
+echo "Checking BuildTools pre-1.17 cache"
#Local Maven Repo
MAVEN_DIR="$HOME/.m2"
diff --git a/ChestsPlusPlusAPI/pom.xml b/ChestsPlusPlusAPI/pom.xml
index 9ee381a..ba43d59 100644
--- a/ChestsPlusPlusAPI/pom.xml
+++ b/ChestsPlusPlusAPI/pom.xml
@@ -15,6 +15,11 @@
../pom.xml
+
+ 16
+ 16
+
+
org.spigotmc
diff --git a/ChestsPlusPlus_1_17_R1/pom.xml b/ChestsPlusPlus_1_17_R1/pom.xml
new file mode 100644
index 0000000..0354c58
--- /dev/null
+++ b/ChestsPlusPlus_1_17_R1/pom.xml
@@ -0,0 +1,109 @@
+
+
+
+
+ ChestsPlusPlus-Parent
+ com.jamesdpeters.minecraft.chests
+ 1.0-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ jar
+ ChestsPlusPlus_1_17_R1
+ 1.0-SNAPSHOT
+
+
+
+ spigotmc-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+
+
+
+ com.jamesdpeters.minecraft.chests
+ ChestsPlusPlus-API
+ 1.0-SNAPSHOT
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.17-R0.1-SNAPSHOT
+ provided
+
+
+ com.jamesdpeters.minecraft.chests
+ ChestsPlusPlus_1_16
+ 1.0-SNAPSHOT
+ compile
+
+
+
+ org.bukkit
+ craftbukkit
+ 1.17-R0.1-SNAPSHOT
+ remapped-mojang
+ provided
+
+
+
+ org.spigotmc
+ spigot
+ 1.17-R0.1-SNAPSHOT
+ remapped-mojang
+ provided
+
+
+
+
+
+
+ net.md-5
+ specialsource-maven-plugin
+ 1.2.2
+
+
+ package
+
+ remap
+
+ remap-obf
+
+ org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:txt:maps-mojang
+ true
+ org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-mojang
+ true
+ remapped-obf
+
+
+
+ package
+
+ remap
+
+ remap-spigot
+
+ ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
+ org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:csrg:maps-spigot
+ org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-obf
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 16
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/Crafting.java b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/Crafting.java
new file mode 100644
index 0000000..3241445
--- /dev/null
+++ b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/Crafting.java
@@ -0,0 +1,106 @@
+package com.jamesdpeters.minecraft.chests.v1_17_R1;
+
+import com.jamesdpeters.minecraft.chests.CraftingProvider;
+import com.jamesdpeters.minecraft.chests.CraftingResult;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.inventory.AbstractContainerMenu;
+import net.minecraft.world.inventory.CraftingContainer;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.crafting.CraftingRecipe;
+import net.minecraft.world.item.crafting.RecipeType;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
+import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
+import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.Recipe;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class Crafting implements CraftingProvider {
+
+ @Override
+ public CraftingResult craft(World world, List items) {
+ AbstractContainerMenu container = new AbstractContainerMenu(null, -1) {
+ @Override
+ public InventoryView getBukkitView() {
+ return null;
+ }
+
+ @Override
+ public boolean stillValid(Player player) {
+ return false;
+ }
+ };
+
+ CraftingContainer crafting = new CraftingContainer(container, 3, 3);
+
+ for (int i = 0; i < items.size(); i++) {
+ crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
+ }
+
+ CraftServer server = (CraftServer) Bukkit.getServer();
+ CraftWorld craftWorld = (CraftWorld) world;
+ Optional optional = server.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, crafting, craftWorld.getHandle());
+
+ net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
+
+ if (optional.isPresent()) {
+ CraftingRecipe recipeCrafting = optional.get();
+ itemStack = recipeCrafting.assemble(crafting);
+ }
+
+ CraftingResult result = new CraftingResult();
+ result.setResult(CraftItemStack.asBukkitCopy(itemStack));
+
+ List matrixResult = crafting.getContents().stream()
+ .map(item -> {
+ Item remainingItem = item.getItem().getCraftingRemainingItem();
+ return remainingItem != null ? CraftItemStack.asBukkitCopy(remainingItem.getDefaultInstance()) : null;
+ }).collect(Collectors.toList());
+
+ result.setMatrixResult(matrixResult);
+
+ return result;
+ }
+
+ @Override
+ public Recipe getRecipe(World world, List items) {
+ AbstractContainerMenu container = new AbstractContainerMenu(null, -1) {
+ @Override
+ public InventoryView getBukkitView() {
+ return null;
+ }
+
+ @Override
+ public boolean stillValid(Player player) {
+ return false;
+ }
+
+ };
+
+ CraftingContainer crafting = new CraftingContainer(container, 3, 3);
+
+ for (int i = 0; i < items.size(); i++) {
+ if(i >= 9) break; // ItemList cant contain more than 9 items.
+ crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
+ }
+
+ CraftServer server = (CraftServer) Bukkit.getServer();
+ CraftWorld craftWorld = (CraftWorld) world;
+ Optional optional = server.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, crafting, craftWorld.getHandle());
+
+// var map = server.getServer().getRecipeManager().recipes.get(RecipeType.CRAFTING);
+//
+// Optional recipe = map.values().stream().flatMap(recipe1 -> {
+// recipe1.matches()
+// })
+
+ return optional.map(net.minecraft.world.item.crafting.Recipe::toBukkitRecipe).orElse(null);
+
+ }
+}
diff --git a/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/MaterialChecker_1_17_R1.java b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/MaterialChecker_1_17_R1.java
new file mode 100644
index 0000000..8289745
--- /dev/null
+++ b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/MaterialChecker_1_17_R1.java
@@ -0,0 +1,35 @@
+package com.jamesdpeters.minecraft.chests.v1_17_R1;
+
+import com.jamesdpeters.minecraft.chests.MaterialChecker;
+import com.jamesdpeters.minecraft.chests.v1_16_R1.MaterialChecker_1_16;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.List;
+
+/**
+ * Only a protocol change from 1.16.2 to 1.16.3 so no new materials were added.
+ */
+public class MaterialChecker_1_17_R1 extends MaterialChecker {
+
+ private final MaterialChecker_1_16 version1_16;
+
+ public MaterialChecker_1_17_R1(){
+ version1_16 = new MaterialChecker_1_16();
+ }
+
+ @Override
+ public List graphically2DList() {
+ return version1_16.graphically2DList();
+ }
+
+ @Override
+ public List ignoredMaterials() {
+ return version1_16.ignoredMaterials();
+ }
+
+ @Override
+ public boolean isTool(ItemStack itemStack) {
+ return version1_16.isTool(itemStack);
+ }
+}
diff --git a/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/NMSProviderImpl.java b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/NMSProviderImpl.java
new file mode 100644
index 0000000..cd1c075
--- /dev/null
+++ b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/NMSProviderImpl.java
@@ -0,0 +1,48 @@
+package com.jamesdpeters.minecraft.chests.v1_17_R1;
+
+import com.jamesdpeters.minecraft.chests.*;
+import org.bukkit.block.Lidded;
+import org.bukkit.entity.ItemFrame;
+
+public class NMSProviderImpl implements NMSProvider {
+
+ @Override
+ public ChestOpener getChestOpener() {
+ return (inventory, container, tileEntityOpener) -> {
+ if(hasLiddedAPI()){
+ if(container instanceof Lidded){
+ if(inventory.getViewers().size() > 0){
+ ((Lidded) container).open();
+ } else {
+ ((Lidded) container).close();
+ }
+ }
+ }
+ return null;
+ };
+ }
+
+ @Override
+ public MaterialChecker getMaterialChecker() {
+ return new MaterialChecker_1_17_R1();
+ }
+
+ @Override
+ public CraftingProvider getCraftingProvider() {
+ return new Crafting();
+ }
+
+ @Override
+ public NPCProvider getNPCProvider() {
+ return new NPC();
+ }
+
+ @Override
+ public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
+ itemFrame.setVisible(visible);
+ }
+
+ private boolean hasLiddedAPI(){
+ return true;
+ }
+}
diff --git a/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/NPC.java b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/NPC.java
new file mode 100644
index 0000000..b64b6b8
--- /dev/null
+++ b/ChestsPlusPlus_1_17_R1/src/main/java/com/jamesdpeters/minecraft/chests/v1_17_R1/NPC.java
@@ -0,0 +1,23 @@
+package com.jamesdpeters.minecraft.chests.v1_17_R1;
+
+import com.jamesdpeters.minecraft.chests.NPCProvider;
+import com.mojang.authlib.GameProfile;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
+import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
+import org.bukkit.entity.HumanEntity;
+
+import java.util.UUID;
+
+public class NPC implements NPCProvider {
+ public HumanEntity createHumanEntity() {
+ MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
+ ServerLevel nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
+ GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "Chests++NPC");
+ ServerPlayer npc = new ServerPlayer(nmsServer, nmsWorld, gameProfile);
+ return npc.getBukkitEntity();
+ }
+}
diff --git a/ChestsPlusPlus_Main/pom.xml b/ChestsPlusPlus_Main/pom.xml
index c6d4a38..8900989 100644
--- a/ChestsPlusPlus_Main/pom.xml
+++ b/ChestsPlusPlus_Main/pom.xml
@@ -6,11 +6,12 @@
com.jamesdpeters.minecraft.chests
ChestsPlusPlus-Master
- 2.4.1-Release
+ 2.5-Beta
- 8
- 8
+ 16
+ 16
+ true
@@ -52,6 +53,13 @@
+
+
+ maven-snapshots
+ https://repository.apache.org/content/repositories/snapshots/
+
+
+
org.spigotmc
@@ -88,7 +96,7 @@
net.wesjd
anvilgui
- 1.4.0-SNAPSHOT
+ 1.5.1-SNAPSHOT
@@ -97,6 +105,14 @@
1.7
+
+ com.jamesdpeters.minecraft.chests
+ ChestsPlusPlus_1_17_R1
+ 1.0-SNAPSHOT
+ jar
+ compile
+
+
com.jamesdpeters.minecraft.chests
ChestsPlusPlus_1_16_R3
@@ -147,7 +163,7 @@
org.jetbrains
annotations
- RELEASE
+ 18.0.0
compile
@@ -155,7 +171,7 @@
org.projectlombok
lombok
- 1.18.18
+ 1.18.20
provided
@@ -171,7 +187,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.1.0
+ 3.3.0-SNAPSHOT
@@ -256,6 +272,8 @@
+
+
diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/HopperListener.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/HopperListener.java
index 44df0e3..4f9892a 100644
--- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/HopperListener.java
+++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/HopperListener.java
@@ -10,7 +10,6 @@ import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.serialize.PluginConfig;
import com.jamesdpeters.minecraft.chests.serialize.SpigotConfig;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -28,6 +27,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
+import java.util.function.Function;
+
public class HopperListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
@@ -39,26 +40,28 @@ public class HopperListener implements Listener {
if(event.isCancelled()) return;
if(event.getDestination().getLocation().getBlock().isBlockPowered()) return;
}
- event.setCancelled(!HopperFilter.isInFilter(event.getDestination().getLocation().getBlock(),event.getItem()));
+
+ Function isFilteredItem = (itemStack ->
+ HopperFilter.isInFilter(event.getDestination().getLocation().getBlock(), itemStack));
+
+ event.setCancelled(!isFilteredItem.apply(event.getItem()));
// Item shouldn't be allowed
if (event.isCancelled() && ServerType.getType() == ServerType.Type.PAPER) {
int index = event.getSource().first(event.getItem());
+ int hopperAmount = SpigotConfig.getWorldSettings(event.getSource().getLocation()).getHopperAmount();
- ItemStack item;
- // Loop until next item is found, if no item found return.
- while ((item = event.getSource().getItem(++index)) == null) {
- if (index >= event.getSource().getSize() - 1)
+ // Loop over the inventory until next item is found, if no item found return.
+ while (true) {
+ ItemStack item = event.getSource().getItem(index++);
+
+ if (index >= event.getSource().getSize())
return;
- }
- InventoryMoveItemEvent newEvent =
- new InventoryMoveItemEvent(event.getSource(), item, event.getDestination(), true);
- Bukkit.getPluginManager().callEvent(newEvent);
-
- if (!newEvent.isCancelled()) {
- int hopperAmount = SpigotConfig.getWorldSettings(event.getSource().getLocation()).getHopperAmount();
- Utils.hopperMove(event.getSource(), item, hopperAmount, event.getDestination());
+ if (isFilteredItem.apply(item)) {
+ Utils.hopperMove(event.getSource(), item, hopperAmount, event.getDestination());
+ return;
+ }
}
}
diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/StorageUtils.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/StorageUtils.java
index 864c597..5c47c8c 100644
--- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/StorageUtils.java
+++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/StorageUtils.java
@@ -19,13 +19,7 @@ import org.bukkit.persistence.PersistentDataType;
import java.util.UUID;
-public class StorageUtils, S extends AbstractStorage> {
-
- private final StorageType storageType;
-
- public StorageUtils(StorageType storageType) {
- this.storageType = storageType;
- }
+public record StorageUtils, S extends AbstractStorage>(StorageType storageType) {
public StorageInfo getStorageInfo(Sign sign, String[] lines, UUID uuid) {
if (lines != null) {
@@ -71,13 +65,11 @@ public class StorageUtils, S extends AbstractStorage> {
if (face == null) return null;
Block sign = block.getRelative(face);
- if (sign.getBlockData() instanceof Directional) {
+ if (sign.getBlockData() instanceof Directional directional) {
//Check if the sign is attached to the given block.
- Directional directional = (Directional) sign.getBlockData();
if (directional.getFacing() != face) return null;
//If it is we can extract info from it.
- if (sign.getState() instanceof Sign) {
- Sign s = (Sign) sign.getState();
+ if (sign.getState() instanceof Sign s) {
return getStorageInfo(s);
}
}
@@ -93,8 +85,7 @@ public class StorageUtils, S extends AbstractStorage> {
*/
public boolean isValidSignPosition(Location location) {
Block block = location.getBlock();
- if (block.getBlockData() instanceof Directional) {
- Directional sign = (Directional) block.getBlockData();
+ if (block.getBlockData() instanceof Directional sign) {
BlockFace facing = sign.getFacing().getOppositeFace();
Block toTest = block.getRelative(facing);
@@ -105,7 +96,7 @@ public class StorageUtils, S extends AbstractStorage> {
if (!storageType.isValidBlockType(toTest)) return false;
//Check if block placed against is already part of this group.
- StorageInfo info = getStorageInfo(toTest.getLocation());
+ StorageInfo info = getStorageInfo(toTest.getLocation());
return (info == null);
}
return false;
diff --git a/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties b/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties
index 0ef417f..4da0094 100644
--- a/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties
+++ b/ChestsPlusPlus_Main/src/main/resources/lang/en_GB.properties
@@ -1,4 +1,4 @@
-# Chests++ Language File (Version 2.4.1-Release)
+# Chests++ Language File (Version 2.5-Release)
# NOTE: This file gets replaced when the plugin launches! If you want to make modifications create a copy first!
# To create a new language file simply create a copy of this file and rename it to your desired choice for example 'en_US.properties'
# It should be located in the 'lang' folder
diff --git a/pom.xml b/pom.xml
index 9294ce4..901dce9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,6 +16,7 @@
ChestsPlusPlusAPI
+ ChestsPlusPlus_1_17_R1
ChestsPlusPlus_1_16_R3
ChestsPlusPlus_1_16_R2
ChestsPlusPlus_1_16