mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-02-15 12:03:00 +01:00
Added new 1.16 Lidded API support.
This commit is contained in:
parent
2d22eb732f
commit
b2925e44a6
@ -1,5 +1,6 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_16_R1;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.API;
|
||||
import com.jamesdpeters.minecraft.chests.ChestOpener;
|
||||
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
|
||||
import com.jamesdpeters.minecraft.chests.v1_16_R1.tileentities.CustomTileEntityBarrel;
|
||||
@ -11,7 +12,10 @@ import net.minecraft.server.v1_16_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_16_R1.TileEntityChestTrapped;
|
||||
import net.minecraft.server.v1_16_R1.TileEntityTypes;
|
||||
import net.minecraft.server.v1_16_R1.World;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.Lidded;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.CraftContainer;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@ -23,12 +27,25 @@ import java.util.List;
|
||||
public class ChestOpener_1_16 implements ChestOpener {
|
||||
|
||||
@Override
|
||||
public TileEntityOpener updateState(Inventory inventory, Container chest, TileEntityOpener tileEntityOpener) {
|
||||
public TileEntityOpener updateState(Inventory inventory, Container container, TileEntityOpener tileEntityOpener) {
|
||||
if(hasLiddedAPI()){
|
||||
if(container instanceof Lidded){
|
||||
if(inventory.getViewers().size() > 0){
|
||||
((Lidded) container).open();
|
||||
} else {
|
||||
((Lidded) container).close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if(tileEntityOpener != null) {
|
||||
tileEntityOpener.setViewers(inventory.getViewers());
|
||||
TileEntityOpener opener = tileEntityOpener;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(API.getPlugin(), ()-> opener.setViewers(inventory.getViewers()),1);
|
||||
return tileEntityOpener;
|
||||
} else {
|
||||
CraftContainer craftContainer = (CraftContainer) chest;
|
||||
CraftContainer craftContainer = (CraftContainer) container;
|
||||
CraftWorld craftWorld = (CraftWorld) craftContainer.getWorld();
|
||||
World world = craftWorld.getHandle();
|
||||
BlockPosition position = craftContainer.getPosition();
|
||||
@ -37,7 +54,8 @@ public class ChestOpener_1_16 implements ChestOpener {
|
||||
//Checks if Tile Entity has already got custom Opener.
|
||||
if (tileEntity instanceof TileEntityOpener) {
|
||||
tileEntityOpener = (TileEntityOpener) tileEntity;
|
||||
tileEntityOpener.setViewers(inventory.getViewers());
|
||||
TileEntityOpener opener = tileEntityOpener;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(API.getPlugin(), ()-> opener.setViewers(inventory.getViewers()),1);
|
||||
return tileEntityOpener;
|
||||
} else {
|
||||
//If not set the new tile entity and set the viewers.
|
||||
@ -58,6 +76,15 @@ public class ChestOpener_1_16 implements ChestOpener {
|
||||
private <T extends TileEntity & TileEntityOpener> void setTileEnt(World world, BlockPosition position, T tileEntOpener, List<HumanEntity> viewers){
|
||||
world.removeTileEntity(position);
|
||||
world.setTileEntity(position, tileEntOpener);
|
||||
tileEntOpener.setViewers(viewers);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(API.getPlugin(), ()-> tileEntOpener.setViewers(viewers),1);
|
||||
}
|
||||
|
||||
private boolean hasLiddedAPI(){
|
||||
try {
|
||||
Class.forName("org.bukkit.block.Lidded");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,11 +61,11 @@ public class CustomTileEntityBarrel extends TileEntityBarrel implements TileEnti
|
||||
a(iblockdata, false);
|
||||
}
|
||||
|
||||
private void a(IBlockData iblockdata, boolean flag) {
|
||||
public void a(IBlockData iblockdata, boolean flag) {
|
||||
this.world.setTypeAndData(this.getPosition(), (IBlockData)iblockdata.set(BlockBarrel.b, flag), 3);
|
||||
}
|
||||
|
||||
private void a(IBlockData iblockdata, SoundEffect soundeffect) {
|
||||
public void a(IBlockData iblockdata, SoundEffect soundeffect) {
|
||||
BaseBlockPosition baseblockposition = ((EnumDirection)iblockdata.get(BlockBarrel.a)).p();
|
||||
double d0 = (double)this.position.getX() + 0.5D + (double)baseblockposition.getX() / 2.0D;
|
||||
double d1 = (double)this.position.getY() + 0.5D + (double)baseblockposition.getY() / 2.0D;
|
||||
|
@ -56,7 +56,7 @@ public class CustomTileEntityChest extends TileEntityChest implements TileEntity
|
||||
onOpen();
|
||||
}
|
||||
|
||||
private void a(SoundEffect soundeffect) {
|
||||
public void a(SoundEffect soundeffect) {
|
||||
BlockPropertyChestType blockpropertychesttype = (BlockPropertyChestType)this.getBlock().get(BlockChest.c);
|
||||
if (blockpropertychesttype != BlockPropertyChestType.LEFT) {
|
||||
double d0 = (double)this.position.getX() + 0.5D;
|
||||
|
@ -3,26 +3,38 @@ package com.jamesdpeters.minecraft.chests.api;
|
||||
import com.jamesdpeters.minecraft.chests.ChestOpener;
|
||||
import com.jamesdpeters.minecraft.chests.MaterialChecker;
|
||||
import com.jamesdpeters.minecraft.chests.NMSProvider;
|
||||
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
|
||||
import com.jamesdpeters.minecraft.chests.v1_16_R1.ChestOpener_1_16;
|
||||
import com.jamesdpeters.minecraft.chests.v1_16_R1.MaterialChecker_1_16;
|
||||
import com.jamesdpeters.minecraft.chests.v1_16_R1.NMSProviderImpl;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class NMSProviderDefault implements NMSProvider {
|
||||
|
||||
//Latest version at time of build is 1.16
|
||||
NMSProviderImpl provider1_16;
|
||||
|
||||
public NMSProviderDefault(){
|
||||
provider1_16 = new NMSProviderImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChestOpener getChestOpener() {
|
||||
return (storage, chest, tileEntityOpener) -> {
|
||||
//Default to doing nothing.
|
||||
return null;
|
||||
};
|
||||
//1.16 ChestOpener contains lidded API!
|
||||
return provider1_16.getChestOpener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialChecker getMaterialChecker() {
|
||||
//Return the current latest MaterialChecker when an newer server implementation is found.
|
||||
return new MaterialChecker_1_16();
|
||||
return provider1_16.getMaterialChecker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
//Not supported in Bukkit api 1.14.
|
||||
provider1_16.setItemFrameVisible(itemFrame, visible);
|
||||
}
|
||||
}
|
||||
|
@ -40,28 +40,32 @@ import java.util.stream.Stream;
|
||||
public class Utils {
|
||||
|
||||
public static void openChestInventory(Player player, ChestLinkStorage storage, LocationInfo openedChestLocation){
|
||||
player.openInventory(storage.getInventory());
|
||||
//Check if all chests should perform open animation.
|
||||
if(Settings.isShouldAnimateAllChests()) {
|
||||
storage.getLocations().forEach(locationInfo -> {
|
||||
Location location = locationInfo.getLocation();
|
||||
if (location != null) {
|
||||
containerAnimation(storage.getInventory(), locationInfo);
|
||||
containerAnimation(storage.getInventory(), locationInfo, true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
containerAnimation(storage.getInventory(), openedChestLocation);
|
||||
containerAnimation(storage.getInventory(), openedChestLocation, true);
|
||||
}
|
||||
player.openInventory(storage.getInventory());
|
||||
}
|
||||
|
||||
private static void containerAnimation(Inventory inventory, LocationInfo location){
|
||||
private static void containerAnimation(Inventory inventory, LocationInfo location, boolean open){
|
||||
if (location != null && Utils.isLocationChunkLoaded(location.getLocation())) {
|
||||
Block block = location.getLocation().getBlock();
|
||||
if (block.getState() instanceof Container) {
|
||||
Container chest = (Container) block.getState();
|
||||
if(open){
|
||||
location.setTileEntityOpener(ApiSpecific.getChestOpener().updateState(inventory, chest, location.getTileEntityOpener()));
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestsPlusPlus.PLUGIN,() -> {
|
||||
location.setTileEntityOpener(ApiSpecific.getChestOpener().updateState(inventory, chest, location.getTileEntityOpener()));
|
||||
},1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,7 +74,7 @@ public class Utils {
|
||||
storage.getLocations().forEach(locationInfo -> {
|
||||
Location location = locationInfo.getLocation();
|
||||
if (location != null) {
|
||||
containerAnimation(storage.getInventory(), locationInfo);
|
||||
containerAnimation(storage.getInventory(), locationInfo, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user