Skip to content

Commit

Permalink
1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Mar 1, 2016
1 parent 8f17bd0 commit a623af5
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 56 deletions.
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_8_R3;
package com.lishid.openinv.internal.v1_9_R1;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
Expand All @@ -23,17 +23,17 @@
import com.lishid.openinv.internal.IAnySilentChest;

//Volatile
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;

import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_8_R3.ITileInventory;
import net.minecraft.server.v1_8_R3.InventoryLargeChest;
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_8_R3.TileEntityChest;
import net.minecraft.server.v1_8_R3.World;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;

import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_9_R1.IInventory;
import net.minecraft.server.v1_9_R1.ITileInventory;
import net.minecraft.server.v1_9_R1.InventoryLargeChest;
import net.minecraft.server.v1_9_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_9_R1.TileEntityChest;
import net.minecraft.server.v1_9_R1.World;

public class AnySilentChest implements IAnySilentChest {
@Override
Expand All @@ -42,19 +42,19 @@ public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
if (world.getType(new BlockPosition(x, y + 1, z)).l())
return true;

int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());

// If block next to chest is chest and has a block on top
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
return true;
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
return true;

return false;
Expand All @@ -71,15 +71,15 @@ public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, in
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());

if (!anychest) {
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
if (world.getType(new BlockPosition(x, y + 1, z)).l())
return true;
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
return true;
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
return true;
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
return true;
}

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_8_R3;
package com.lishid.openinv.internal.v1_9_R1;

import java.lang.reflect.Field;

Expand All @@ -26,9 +26,9 @@
import com.lishid.openinv.internal.IInventoryAccess;

//Volatile
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;

import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_9_R1.IInventory;

public class InventoryAccess implements IInventoryAccess {
@Override
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_8_R3;
package com.lishid.openinv.internal.v1_9_R1;

import java.io.File;
import java.util.UUID;
Expand All @@ -28,11 +28,11 @@
import com.mojang.authlib.GameProfile;

//Volatile
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;

import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.PlayerInteractManager;
import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_9_R1.MinecraftServer;
import net.minecraft.server.v1_9_R1.PlayerInteractManager;

public class PlayerDataManager implements IPlayerDataManager {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal.v1_9_R1;

//Volatile
import net.minecraft.server.v1_8_R3.ContainerChest;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_9_R1.ContainerChest;
import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_9_R1.IInventory;

public class SilentContainerChest extends ContainerChest {
public IInventory inv;
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_8_R3;
package com.lishid.openinv.internal.v1_9_R1;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand All @@ -29,15 +29,15 @@
import com.lishid.openinv.internal.ISpecialEnderChest;

//Volatile
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;

import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_8_R3.InventoryEnderChest;
import net.minecraft.server.v1_8_R3.InventorySubcontainer;
import net.minecraft.server.v1_8_R3.ItemStack;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;

import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_9_R1.IInventory;
import net.minecraft.server.v1_9_R1.InventoryEnderChest;
import net.minecraft.server.v1_9_R1.InventorySubcontainer;
import net.minecraft.server.v1_9_R1.ItemStack;

public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal.v1_9_R1;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
Expand All @@ -23,13 +26,13 @@
import com.lishid.openinv.internal.ISpecialPlayerInventory;

//Volatile
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;

import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.PlayerInventory;
import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_9_R1.ItemStack;
import net.minecraft.server.v1_9_R1.PlayerInventory;

public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
Expand All @@ -41,11 +44,30 @@ public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}

private void setItemArrays(PlayerInventory inventory, ItemStack[] items, ItemStack[] armor,
ItemStack[] extraSlots) {
try {
Field field = inventory.getClass().getField("items");
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, items);
field = inventory.getClass().getField("armor");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, armor);
field = inventory.getClass().getField("extraSlots");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException
| IllegalAccessException e) {
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
e.printStackTrace();
}
}

@Override
public Inventory getBukkitInventory() {
return inventory;
Expand All @@ -63,8 +85,7 @@ public void InventoryRemovalCheck() {
public void PlayerGoOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
setItemArrays(p.getHandle().inventory, items, armor, extraSlots);
p.saveData();
playerOnline = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: OpenInv
main: com.lishid.openinv.OpenInv
version: 2.2.9
version: 2.2.10
author: lishid
authors: [Jikoo]
description: >
Expand Down

0 comments on commit a623af5

Please sign in to comment.