ChestLinks now open!

Added NMS support.
Fixed versioning.
This commit is contained in:
jameslfc19 2020-07-04 14:45:58 +01:00
parent c178d982af
commit 367ffdcc73
19 changed files with 356 additions and 25 deletions

View File

@ -1,6 +1,7 @@
#!/bin/sh
echo "Checking BuildTools cache"
#Download BuildTools jar
curl -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
#Local Maven Repo
@ -10,23 +11,19 @@ MAVEN_DIR="$HOME/.m2"
CRAFTBUKKIT="${MAVEN_DIR}/repository/org/bukkit/craftbukkit"
#Versions
#VERSION_1_16="1.16.1"
VERSION_1_15="1.15.2"
#VERSION_1_14="1.14.4"
array=("1.16.1" "1.15.2" "1.14.4")
#array=("${VERSION_1_16}" "${VERSION_1_15}" "${VERSION_1_14}")
array=("${VERSION_1_15}")
for i in "${array[@]}"
do
VERSION_DIR="${CRAFTBUKKIT}/${i}-R0.1-SNAPSHOT"
if [ -d "$VERSION_DIR" ]; then
echo "${i} is cached!"
echo "CraftBukkit version ${i} is cached!"
else
echo "${i} isn't cached!"
echo "CraftBukkit version ${i} isn't cached!"
echo "Running BuildTools!"
java -jar BuildTools.jar --rev ${i} --compile craftbukkit > /dev/null 2>&1
java -jar BuildTools.jar --rev ${i} --compile craftbukkit | awk 'NR <= 3'
echo "Compiled CraftBukkit ${i}"
fi
done

View File

@ -5,13 +5,13 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -0,0 +1,7 @@
package com.jamesdpeters.minecraft.chests;
import org.bukkit.block.Chest;
public interface ChestOpener {
void setLidOpen(Chest chest, boolean open);
}

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_14</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,35 @@
package com.jamesdpeters.minecraft.chests;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.TileEntity;
import net.minecraft.server.v1_14_R1.TileEntityChest;
import net.minecraft.server.v1_14_R1.World;
import org.bukkit.block.Chest;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftChest;
public class ChestOpener_1_14 implements ChestOpener {
@Override
public void setLidOpen(Chest chest, boolean open) {
CraftChest craftChest = (CraftChest) chest;
CraftWorld craftWorld = (CraftWorld) craftChest.getWorld();
World world = craftWorld.getHandle();
BlockPosition position = craftChest.getPosition();
TileEntity tileEntity = world.getTileEntity(position);
if(tileEntity instanceof TileEntityChest){
boolean isCustomTileEntity = tileEntity instanceof CustomTileEntityChest;
CustomTileEntityChest customTileEntityChest;
if(!isCustomTileEntity){
customTileEntityChest = new CustomTileEntityChest();
world.removeTileEntity(position);
world.setTileEntity(position, customTileEntityChest);
} else {
customTileEntityChest = (CustomTileEntityChest) tileEntity;
}
customTileEntityChest.setOpen(open);
customTileEntityChest.onOpen();
}
}
}

View File

@ -0,0 +1,25 @@
package com.jamesdpeters.minecraft.chests;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.BlockChest;
import net.minecraft.server.v1_14_R1.TileEntityChest;
public class CustomTileEntityChest extends TileEntityChest {
private int phantomViewers;
@Override
public void onOpen() {
Block block = this.getBlock().getBlock();
if (block instanceof BlockChest) {
this.world.playBlockAction(this.position, block, 1, phantomViewers);
this.world.applyPhysics(this.position, block);
}
}
public void setOpen(boolean open){
if(open) phantomViewers++;
else phantomViewers--;
if(phantomViewers < 0) phantomViewers = 0;
}
}

View File

@ -0,0 +1,34 @@
package com.jamesdpeters.minecraft.chests;
import net.minecraft.server.v1_14_R1.TileEntityChest;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftChest;
import java.util.ArrayList;
import java.util.List;
public class MaterialChecker_1_14 extends MaterialChecker {
private List<Material> materials;
private List<Material> ignoredMaterials;
public MaterialChecker_1_14(){
materials = new ArrayList<>();
materials.addAll(version_1_14_Items);
ignoredMaterials = new ArrayList<>();
ignoredMaterials.addAll(version_1_14_Ignored_Items);
}
@Override
protected List<Material> graphically2DList() {
return materials;
}
@Override
protected List<Material> ignoredMaterials() {
return ignoredMaterials;
}
}

View File

@ -5,13 +5,14 @@
<parent>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_15</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
@ -24,7 +25,7 @@
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>

View File

@ -0,0 +1,35 @@
package com.jamesdpeters.minecraft.chests;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.TileEntity;
import net.minecraft.server.v1_15_R1.TileEntityChest;
import net.minecraft.server.v1_15_R1.World;
import org.bukkit.block.Chest;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.block.CraftChest;
public class ChestOpener_1_15 implements ChestOpener {
@Override
public void setLidOpen(Chest chest, boolean open) {
CraftChest craftChest = (CraftChest) chest;
CraftWorld craftWorld = (CraftWorld) craftChest.getWorld();
World world = craftWorld.getHandle();
BlockPosition position = craftChest.getPosition();
TileEntity tileEntity = world.getTileEntity(position);
if(tileEntity instanceof TileEntityChest){
boolean isCustomTileEntity = tileEntity instanceof CustomTileEntityChest;
CustomTileEntityChest customTileEntityChest;
if(!isCustomTileEntity){
customTileEntityChest = new CustomTileEntityChest();
world.removeTileEntity(position);
world.setTileEntity(position, customTileEntityChest);
} else {
customTileEntityChest = (CustomTileEntityChest) tileEntity;
}
customTileEntityChest.setOpen(open);
customTileEntityChest.onOpen();
}
}
}

View File

@ -0,0 +1,25 @@
package com.jamesdpeters.minecraft.chests;
import net.minecraft.server.v1_15_R1.Block;
import net.minecraft.server.v1_15_R1.BlockChest;
import net.minecraft.server.v1_15_R1.TileEntityChest;
public class CustomTileEntityChest extends TileEntityChest {
private int phantomViewers;
@Override
public void onOpen() {
Block block = this.getBlock().getBlock();
if (block instanceof BlockChest) {
this.world.playBlockAction(this.position, block, 1, phantomViewers);
this.world.applyPhysics(this.position, block);
}
}
public void setOpen(boolean open){
if(open) phantomViewers++;
else phantomViewers--;
if(phantomViewers < 0) phantomViewers = 0;
}
}

View File

@ -2,6 +2,8 @@ package com.jamesdpeters.minecraft.chests;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import java.util.ArrayList;
import java.util.List;

View File

@ -6,13 +6,14 @@
<parent>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_16</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
@ -25,7 +26,7 @@
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
@ -37,9 +38,16 @@
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_15</artifactId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -0,0 +1,36 @@
package com.jamesdpeters.minecraft.chests;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.TileEntity;
import net.minecraft.server.v1_16_R1.TileEntityChest;
import net.minecraft.server.v1_16_R1.World;
import org.bukkit.block.Chest;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R1.block.CraftChest;
public class ChestOpener_1_16 implements ChestOpener {
@Override
public void setLidOpen(Chest chest, boolean open) {
CraftChest craftChest = (CraftChest) chest;
CraftWorld craftWorld = (CraftWorld) craftChest.getWorld();
World world = craftWorld.getHandle();
BlockPosition position = craftChest.getPosition();
TileEntity tileEntity = world.getTileEntity(position);
if(tileEntity instanceof TileEntityChest){
boolean isCustomTileEntity = tileEntity instanceof CustomTileEntityChest;
CustomTileEntityChest customTileEntityChest;
if(!isCustomTileEntity){
customTileEntityChest = new CustomTileEntityChest();
world.removeTileEntity(position);
world.setTileEntity(position, customTileEntityChest);
} else {
customTileEntityChest = (CustomTileEntityChest) tileEntity;
}
customTileEntityChest.setOpen(open);
customTileEntityChest.onOpen();
}
}
}

View File

@ -0,0 +1,25 @@
package com.jamesdpeters.minecraft.chests;
import net.minecraft.server.v1_16_R1.Block;
import net.minecraft.server.v1_16_R1.BlockChest;
import net.minecraft.server.v1_16_R1.TileEntityChest;
public class CustomTileEntityChest extends TileEntityChest {
private int phantomViewers;
@Override
protected void onOpen() {
Block block = this.getBlock().getBlock();
if (block instanceof BlockChest) {
this.world.playBlockAction(this.position, block, 1, phantomViewers);
this.world.applyPhysics(this.position, block);
}
}
public void setOpen(boolean open){
if(open) phantomViewers++;
else phantomViewers--;
if(phantomViewers < 0) phantomViewers = 0;
}
}

View File

@ -6,7 +6,7 @@
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-Master</artifactId>
<version>1.5-BETA-3</version>
<version>1.5-BETA-4</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
@ -84,7 +84,7 @@
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_16</artifactId>
<version>${version}</version>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
@ -92,7 +92,15 @@
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_15</artifactId>
<version>${version}</version>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_14</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
@ -100,11 +108,10 @@
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>${version}</version>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<!--Tell maven how to prepare and build our jar file from our source and dependancies-->

View File

@ -1,22 +1,29 @@
package com.jamesdpeters.minecraft.chests.api_interfaces;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.ChestOpener_1_14;
import com.jamesdpeters.minecraft.chests.ChestOpener_1_15;
import com.jamesdpeters.minecraft.chests.ChestOpener_1_16;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.MaterialChecker_1_15;
import com.jamesdpeters.minecraft.chests.MaterialChecker_1_16;
import org.bukkit.Bukkit;
import org.bukkit.block.Chest;
import java.util.Arrays;
public class ApiSpecific {
private static MaterialChecker materialChecker;
private static ChestOpener chestOpener;
private static Version version;
public static void init(){
version = getVersion();
ChestsPlusPlus.PLUGIN.getLogger().info("Found API version: "+version);
materialChecker = getMaterialChecker(version);
chestOpener = getChestOpener(version);
}
enum Version {
@ -47,7 +54,21 @@ public class ApiSpecific {
}
}
private static ChestOpener getChestOpener(Version version){
switch (version){
case API_1_16: return new ChestOpener_1_16();
case API_1_15: return new ChestOpener_1_15();
case API_1_14: return new ChestOpener_1_14();
default: return (chest, open) -> {
//Do nothing
};
}
}
public static MaterialChecker getMaterialChecker() {
return materialChecker;
}
public static ChestOpener getChestOpener() {
return chestOpener;
}
}

View File

@ -1,6 +1,7 @@
package com.jamesdpeters.minecraft.chests.listeners;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.api_interfaces.ApiSpecific;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualCraftingHolder;
import com.jamesdpeters.minecraft.chests.storage.autocraft.AutoCraftingStorage;
import com.jamesdpeters.minecraft.chests.serialize.Config;
@ -10,6 +11,9 @@ import com.jamesdpeters.minecraft.chests.misc.Utils;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -35,7 +39,7 @@ public class InventoryListener implements Listener {
if (storage != null) {
event.setCancelled(true);
if (event.getPlayer().hasPermission(Permissions.OPEN) && storage.hasPermission((Player) event.getPlayer())) {
Utils.openChestInventory((Player) event.getPlayer(), storage.getInventory());
Utils.openChestInventory((Player) event.getPlayer(), storage, event.getInventory().getLocation());
} else {
Messages.NO_PERMISSION((Player) event.getPlayer());
}
@ -63,9 +67,17 @@ public class InventoryListener implements Listener {
if (holder instanceof VirtualInventoryHolder) {
VirtualInventoryHolder vHolder = (VirtualInventoryHolder) holder;
vHolder.openPreviousInventory();
if (event.getInventory().getLocation() == null) {
Location location = event.getInventory().getLocation();
if (location == null) {
Utils.closeInventorySound((Player) event.getPlayer(), event.getInventory());
}
vHolder.getStorage().getLocations().forEach(locationInfo -> {
Block block = locationInfo.getLocation().getBlock();
if(block.getState() instanceof Chest){
Chest chest = (Chest) block.getState();
ApiSpecific.getChestOpener().setLidOpen(chest,false);
}
});
}
if(holder instanceof VirtualCraftingHolder){
((VirtualCraftingHolder) holder).stopAnimation();

View File

@ -1,7 +1,9 @@
package com.jamesdpeters.minecraft.chests.misc;
import com.jamesdpeters.minecraft.chests.api_interfaces.ApiSpecific;
import com.jamesdpeters.minecraft.chests.filters.Filter;
import com.jamesdpeters.minecraft.chests.filters.HopperFilter;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
import org.bukkit.*;
import org.bukkit.block.*;
import org.bukkit.entity.Player;
@ -16,9 +18,21 @@ import java.util.stream.Collectors;
public class Utils {
public static void openChestInventory(Player player, ChestLinkStorage storage, Location location){
storage.getLocations().forEach(locationInfo -> {
if(locationInfo.getLocation() != null){
Block block = locationInfo.getLocation().getBlock();
if(block.getState() instanceof Chest){
Chest chest = (Chest) block.getState();
ApiSpecific.getChestOpener().setLidOpen(chest,true);
}
}
});
player.openInventory(storage.getInventory());
}
public static void openChestInventory(Player player, Inventory inventory){
if(inventory.getLocation() != null) player.getWorld().playSound(inventory.getLocation(), Sound.BLOCK_CHEST_OPEN,0.5f,1f);
else player.getWorld().playSound(player.getLocation(), Sound.BLOCK_CHEST_OPEN,0.5f,1f);
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_CHEST_OPEN,0.5f,1f);
player.openInventory(inventory);
}

View File

@ -6,7 +6,7 @@
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<version>1.5-BETA-3</version>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>