Skip to content

Commit

Permalink
Add 1.16 support, drop 1.14 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Jun 25, 2020
1 parent 1228fc2 commit 201a357
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 176 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ The final file is `target/OpenInv.jar`

## License
```
Copyright (C) 2011-2019 lishid. All rights reserved.
Copyright (C) 2011-2020 lishid. All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<id>all</id>
<modules>
<module>v1_8_R3</module>
<module>v1_14_R1</module>
<module>v1_15_R1</module>
<module>v1_16_R1</module>
</modules>
</profile>

Expand Down
6 changes: 3 additions & 3 deletions internal/v1_14_R1/pom.xml → internal/v1_16_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openinvadapter1_14_R1</artifactId>
<name>OpenInvAdapter1_14_R1</name>
<artifactId>openinvadapter1_16_R1</artifactId>
<name>OpenInvAdapter1_16_R1</name>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.14.3-R0.1-SNAPSHOT</version>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lishid.openinv.internal.v1_14_R1;
package com.lishid.openinv.internal.v1_16_R1;

import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentContainer;
import java.lang.reflect.Field;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.BlockBarrel;
import net.minecraft.server.v1_14_R1.BlockChest;
import net.minecraft.server.v1_14_R1.BlockChestTrapped;
import net.minecraft.server.v1_14_R1.BlockEnderChest;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.BlockPropertyChestType;
import net.minecraft.server.v1_14_R1.BlockShulkerBox;
import net.minecraft.server.v1_14_R1.ChatMessage;
import net.minecraft.server.v1_14_R1.Container;
import net.minecraft.server.v1_14_R1.ContainerChest;
import net.minecraft.server.v1_14_R1.Containers;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.EnumChatFormat;
import net.minecraft.server.v1_14_R1.EnumGamemode;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.ITileInventory;
import net.minecraft.server.v1_14_R1.InventoryEnderChest;
import net.minecraft.server.v1_14_R1.InventoryLargeChest;
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
import net.minecraft.server.v1_14_R1.PlayerInventory;
import net.minecraft.server.v1_14_R1.TileEntity;
import net.minecraft.server.v1_14_R1.TileEntityChest;
import net.minecraft.server.v1_14_R1.TileEntityEnderChest;
import net.minecraft.server.v1_14_R1.TileEntityLootable;
import net.minecraft.server.v1_14_R1.TileInventory;
import net.minecraft.server.v1_14_R1.World;
import net.minecraft.server.v1_16_R1.Block;
import net.minecraft.server.v1_16_R1.BlockBarrel;
import net.minecraft.server.v1_16_R1.BlockChest;
import net.minecraft.server.v1_16_R1.BlockChestTrapped;
import net.minecraft.server.v1_16_R1.BlockEnderChest;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.BlockPropertyChestType;
import net.minecraft.server.v1_16_R1.BlockShulkerBox;
import net.minecraft.server.v1_16_R1.ChatMessage;
import net.minecraft.server.v1_16_R1.Container;
import net.minecraft.server.v1_16_R1.ContainerChest;
import net.minecraft.server.v1_16_R1.Containers;
import net.minecraft.server.v1_16_R1.EntityHuman;
import net.minecraft.server.v1_16_R1.EntityPlayer;
import net.minecraft.server.v1_16_R1.EnumChatFormat;
import net.minecraft.server.v1_16_R1.EnumGamemode;
import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.IChatBaseComponent;
import net.minecraft.server.v1_16_R1.ITileInventory;
import net.minecraft.server.v1_16_R1.InventoryEnderChest;
import net.minecraft.server.v1_16_R1.InventoryLargeChest;
import net.minecraft.server.v1_16_R1.PlayerInteractManager;
import net.minecraft.server.v1_16_R1.PlayerInventory;
import net.minecraft.server.v1_16_R1.TileEntity;
import net.minecraft.server.v1_16_R1.TileEntityChest;
import net.minecraft.server.v1_16_R1.TileEntityEnderChest;
import net.minecraft.server.v1_16_R1.TileEntityLootable;
import net.minecraft.server.v1_16_R1.TileInventory;
import net.minecraft.server.v1_16_R1.World;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.Barrel;
Expand Down Expand Up @@ -216,7 +216,7 @@ public boolean activateContainer(@NotNull final Player bukkitPlayer, final boole
break;
}
return new ContainerChest(containers, containerCounter, playerInventory, enderChest, rows);
}, BlockEnderChest.d));
}, BlockEnderChest.e));
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
Expand All @@ -231,16 +231,16 @@ public boolean activateContainer(@NotNull final Player bukkitPlayer, final boole

if (block instanceof BlockChest) {

BlockPropertyChestType chestType = blockData.get(BlockChest.b);
BlockPropertyChestType chestType = blockData.get(BlockChest.c);

if (chestType != BlockPropertyChestType.SINGLE) {

BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.j(blockData));
BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.h(blockData));
IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);

if (adjacentBlockData.getBlock() == block) {

BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.c);

if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
&& adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lishid.openinv.internal.v1_14_R1;
package com.lishid.openinv.internal.v1_16_R1;

import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
Expand All @@ -23,30 +23,32 @@
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Field;
import net.minecraft.server.v1_14_R1.ChatComponentText;
import net.minecraft.server.v1_14_R1.ChatMessageType;
import net.minecraft.server.v1_14_R1.Container;
import net.minecraft.server.v1_14_R1.Containers;
import net.minecraft.server.v1_14_R1.DimensionManager;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.MinecraftServer;
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.PacketPlayOutChat;
import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
import net.minecraft.server.v1_14_R1.PlayerInventory;
import net.minecraft.server.v1_14_R1.WorldNBTStorage;
import net.minecraft.server.v1_16_R1.ChatComponentText;
import net.minecraft.server.v1_16_R1.ChatMessageType;
import net.minecraft.server.v1_16_R1.Container;
import net.minecraft.server.v1_16_R1.Containers;
import net.minecraft.server.v1_16_R1.Entity;
import net.minecraft.server.v1_16_R1.EntityHuman;
import net.minecraft.server.v1_16_R1.EntityPlayer;
import net.minecraft.server.v1_16_R1.MinecraftServer;
import net.minecraft.server.v1_16_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_16_R1.NBTTagCompound;
import net.minecraft.server.v1_16_R1.PacketPlayOutChat;
import net.minecraft.server.v1_16_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_16_R1.PlayerInteractManager;
import net.minecraft.server.v1_16_R1.PlayerInventory;
import net.minecraft.server.v1_16_R1.SystemUtils;
import net.minecraft.server.v1_16_R1.World;
import net.minecraft.server.v1_16_R1.WorldNBTStorage;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer;
import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_16_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftContainer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
Expand All @@ -57,7 +59,7 @@

public class PlayerDataManager implements IPlayerDataManager {

private Field bukkitEntity;
private @Nullable Field bukkitEntity;

public PlayerDataManager() {
try {
Expand Down Expand Up @@ -90,6 +92,7 @@ public static EntityPlayer getHandle(final Player player) {
return nmsPlayer;
}

@Nullable
@Override
public Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data
Expand All @@ -98,11 +101,17 @@ public Player loadPlayer(@NotNull final OfflinePlayer offline) {
}

// Create a profile and entity to load the player data
// See net.minecraft.server.PlayerList#attemptLogin
GameProfile profile = new GameProfile(offline.getUniqueId(),
offline.getName() != null ? offline.getName() : offline.getUniqueId().toString());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
WorldServer worldServer = server.getWorldServer(World.OVERWORLD);

if (worldServer == null) {
return null;
}

EntityPlayer entity = new EntityPlayer(server, worldServer, profile, new PlayerInteractManager(worldServer));

try {
injectPlayer(entity);
Expand Down Expand Up @@ -133,7 +142,7 @@ public void saveData() {
super.saveData();
// See net.minecraft.server.WorldNBTStorage#save(EntityPlayer)
try {
WorldNBTStorage worldNBTStorage = (WorldNBTStorage) player.server.getPlayerList().playerFileData;
WorldNBTStorage worldNBTStorage = player.server.getPlayerList().playerFileData;

NBTTagCompound playerData = player.save(new NBTTagCompound());

Expand Down Expand Up @@ -280,7 +289,7 @@ public void sendSystemMessage(@NotNull Player player, @NotNull String message) {

// For action bar chat, color codes are still supported but JSON text color is not allowed. Do not convert text.
if (nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(message), ChatMessageType.GAME_INFO));
nmsPlayer.playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(message), ChatMessageType.GAME_INFO, SystemUtils.b));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lishid.openinv.internal.v1_14_R1;
package com.lishid.openinv.internal.v1_16_R1;

import com.lishid.openinv.internal.ISpecialEnderChest;
import java.util.List;
import net.minecraft.server.v1_14_R1.AutoRecipeStackManager;
import net.minecraft.server.v1_14_R1.ContainerUtil;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.IInventoryListener;
import net.minecraft.server.v1_14_R1.InventoryEnderChest;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NonNullList;
import net.minecraft.server.v1_16_R1.AutoRecipeStackManager;
import net.minecraft.server.v1_16_R1.ContainerUtil;
import net.minecraft.server.v1_16_R1.EntityHuman;
import net.minecraft.server.v1_16_R1.EntityPlayer;
import net.minecraft.server.v1_16_R1.IInventoryListener;
import net.minecraft.server.v1_16_R1.InventoryEnderChest;
import net.minecraft.server.v1_16_R1.ItemStack;
import net.minecraft.server.v1_16_R1.NonNullList;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventory;
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 {

Expand Down Expand Up @@ -115,7 +116,7 @@ public InventoryHolder getOwner() {
}

@Override
public Location getLocation() {
public @Nullable Location getLocation() {
return null;
}

Expand All @@ -131,7 +132,7 @@ public void b(IInventoryListener iinventorylistener) {

@Override
public ItemStack getItem(int i) {
return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.b;
}

@Override
Expand All @@ -153,7 +154,7 @@ public ItemStack a(ItemStack itemstack) {
if (itemstack2.isEmpty()) {
this.setItem(i, itemstack1);
this.update();
return ItemStack.a;
return ItemStack.b;
}

if (ItemStack.c(itemstack2, itemstack1)) {
Expand All @@ -164,7 +165,7 @@ public ItemStack a(ItemStack itemstack) {
itemstack1.subtract(k);
if (itemstack1.isEmpty()) {
this.update();
return ItemStack.a;
return ItemStack.b;
}
}
}
Expand All @@ -181,9 +182,9 @@ public ItemStack a(ItemStack itemstack) {
public ItemStack splitWithoutUpdate(int i) {
ItemStack itemstack = this.items.get(i);
if (itemstack.isEmpty()) {
return ItemStack.a;
return ItemStack.b;
} else {
this.items.set(i, ItemStack.a);
this.items.set(i, ItemStack.b);
return itemstack;
}
}
Expand All @@ -204,7 +205,7 @@ public int getSize() {
}

@Override
public boolean isNotEmpty() {
public boolean isEmpty() {

for (ItemStack itemstack : this.items) {
if (!itemstack.isEmpty()) {
Expand Down
Loading

0 comments on commit 201a357

Please sign in to comment.