Compare commits

...

10 Commits

Author SHA1 Message Date
Jikoo
476171911a Silences shulker boxes but breaks sound/animation till tile is reloaded
Time for relaxation and sleep, too much actual effort expended today
2016-11-19 02:01:52 -05:00
Jikoo
9501d1c571 AnyChest supports Shulker Boxes, silent makes sound but doesn't animate.
I'm done for the day, got a lot of stuff to do tomorrow. Hopefully I'll iron out all of the wrinkles by the end of the day.
2016-11-18 01:51:11 -05:00
Jikoo
ff683d65d1 Prep for silent shulker boxes, backport ocelot fix to all versions
No clue why I didn't port it to all versions, seems like I stopped after 1.8 or something. Ocelots have been around since 1.2.
2016-11-17 20:06:10 -05:00
Jikoo
c3f517d7ab Fix project setup to prevent recursive dependencies
Maven's fine with it, but it is bad practice.

OpenInv still modifies plugin.yml in OpenInvPlugin. It should really be done via the Assembly Plugin, but it works and I am lazy.
2016-11-17 12:22:52 -05:00
Jikoo
2e41b4bd45 Fix potentially server-crashing NPE
Whoops.
2016-11-17 03:22:24 -05:00
Jikoo
e100dff6ab Update for 1.11 2016-11-17 02:34:52 -05:00
Jikoo
835e3151eb Convert to a more user-friendly Maven setup
Mostly based on Mbaxter's AbstractionExamplePlugin
Compiling OpenInv for a specific version is very easy - just compile the correct module.
Compiling for a set of versions is slightly more complex. You'll need to use a profile for the versions you want to compile. Provided profiles are latest, modern - versions 1.7.10+, and all. For more information, check out the Maven guide http://maven.apache.org/guides/introduction/introduction-to-profiles.html

This commit doesn't change anything with the plugin itself, but it makes it loads easier for people to maintain and compile their own version without destroying backwards compatibility.
2016-07-14 09:47:06 -04:00
Jikoo
3312ed9ff6 Fixed armor/offhand slot display in 1.10
Whoops :D
2016-07-09 12:51:10 -04:00
Jikoo
23bda96f38 Fix improper caching causing duplications, closes #10
* Implemented a universal cache for loaded players
* Reworked a significant amount of my API additions
* Simplified join/quit handling
* Cleaned up ISpecialEnderChest/ISpecialPlayerInventory implementations
* Fixed OpenInv.* permission not granting access to commands
2016-07-09 10:41:51 -04:00
Jikoo
1bbdde683c Fixed online matching preventing exact offline access, closes #9
Restored some old OpenInv behavior - Offline name partial completion.
Currently there's no minimum similarity to consider a match a success, and the first name with the same similarity will take precedence. As a result, you may see some very odd results on occasion.
2016-06-15 18:50:38 -04:00
166 changed files with 5193 additions and 3536 deletions

219
OpenInv/pom.xml Normal file
View File

@@ -0,0 +1,219 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>openinv</artifactId>
<name>OpenInv</name>
<version>2.5.3-SNAPSHOT</version>
<profiles>
<profile>
<id>latest</id>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_11_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>modern</id>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_7_R4</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_8_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_8_R2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_8_R3</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_9_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_9_R2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_10_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_11_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>all</id>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_4_5</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_4_6</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_4_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_5_R2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_5_R3</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_6_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_6_R2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_6_R3</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_7_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_7_R2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_7_R3</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_7_R4</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_8_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_8_R2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_8_R3</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_9_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_9_R2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_10_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcraftbukkit1_11_R1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<directory>../target</directory>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>../OpenInvPlugin/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<!--
~ This keeps the final file clean, but may cause issues for people not familiar with the setup.
~ If you're having trouble with the final product missing files, remove or tweak this configuration.
-->
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>com.lishid:*</artifact>
<includes>
<include>com/lishid/openinv/**/*</include>
<include>plugin.yml</include>
</includes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

22
OpenInvCore/pom.xml Normal file
View File

@@ -0,0 +1,22 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>openinvcore</artifactId>
<name>OpenInvCore</name>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.4.5-R1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,8 +18,22 @@ package com.lishid.openinv.internal;
import org.bukkit.entity.Player;
/**
* @deprecated Use {@link IAnySilentContainer}
*/
@Deprecated
public interface IAnySilentChest {
/**
* @deprecated Use {@link IAnySilentContainer#activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
/**
* @deprecated Use {@link IAnySilentContainer#isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
public boolean isAnyChestNeeded(Player player, int x, int y, int z);
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
}

View File

@@ -0,0 +1,40 @@
package com.lishid.openinv.internal;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
public interface IAnySilentContainer extends IAnySilentChest {
/**
* Checks if the given block is a container which can be unblocked or silenced.
*
* @param block the BlockState
* @return true if the Block is a supported container
*/
public boolean isAnySilentContainer(BlockState block);
/**
* Opens the container at the given coordinates for the Player.
*
* @param player
* @param anychest whether compatibility for blocked containers is to be used
* @param silentchest whether the container's noise is to be silenced
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @return true if the container can be opened
*/
public boolean activateContainer(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
/**
* Checks if the container at the given coordinates is blocked.
*
* @param player the Player opening the container
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @return true if the container is blocked
*/
public boolean isAnyContainerNeeded(Player player, int x, int y, int z);
}

View File

@@ -20,5 +20,14 @@ import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
public interface IInventoryAccess {
/**
* Check if an entity has permission to modify the contents of an inventory.
*
* @param inventory the Inventory
* @param player the HumanEntity
* @return true if the HumanEntity can modify the Inventory
*/
public boolean check(Inventory inventory, HumanEntity player);
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2011-2014 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public interface IPlayerDataManager {
/**
* Loads a Player for an OfflinePlayer.
* </p>
* This method is potentially blocking, and should not be called on the main thread.
*
* @param offline
* @return
*/
public Player loadPlayer(OfflinePlayer offline);
/**
* Gets a unique identifying string for an OfflinePlayer.
*
* @param player
* @return
*/
public String getPlayerDataID(OfflinePlayer player);
}

View File

@@ -21,17 +21,30 @@ import org.bukkit.inventory.Inventory;
public interface ISpecialEnderChest {
/**
* Gets the Inventory associated with this ISpecialEnderChest.
*
* @return the Inventory
*/
public Inventory getBukkitInventory();
public boolean inventoryRemovalCheck(boolean save);
/**
* Sets the Player associated with this ISpecialEnderChest online.
*
* @param player the Player coming online
*/
public void setPlayerOnline(Player player);
/**
* Sets the Player associated with this ISpecialEnderChest offline.
*
* @return true if the ISpecialEnderChest is eligible for removal
*/
public boolean setPlayerOffline();
public void setPlayerOffline();
/**
* Gets whether or not this ISpecialEnderChest is in use.
*
* @return true if the ISpecialEnderChest is in use
*/
public boolean isInUse();
}

View File

@@ -21,16 +21,30 @@ import org.bukkit.inventory.Inventory;
public interface ISpecialPlayerInventory {
/**
* Gets the Inventory associated with this ISpecialPlayerInventory.
*
* @return the Inventory
*/
public Inventory getBukkitInventory();
public boolean inventoryRemovalCheck(boolean save);
/**
* Sets the Player associated with this ISpecialPlayerInventory online.
*
* @param player the Player coming online
*/
public void setPlayerOnline(Player player);
/**
* Sets the Player associated with this ISpecialPlayerInventory offline.
*
* @return true if the ISpecialPlayerInventory is eligible for removal
*/
public boolean setPlayerOffline();
public void setPlayerOffline();
/**
* Gets whether or not this ISpecialPlayerInventory is in use.
*
* @return true if the ISpecialPlayerInventory is in use
*/
public boolean isInUse();
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_10_R1</artifactId>
<name>OpenInvCraftbukkit1_10_R1</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -16,10 +16,11 @@
package com.lishid.openinv.internal.v1_10_R1;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentContainer;
import com.lishid.openinv.internal.IAnySilentChest;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
@@ -37,12 +38,64 @@ import net.minecraft.server.v1_10_R1.World;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
if (chest == null)
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
returnValue = true;
} else {
try {
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
player.activeContainer = silentContainerChest;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
return true;
@@ -50,16 +103,8 @@ public class AnySilentChest implements IAnySilentChest {
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
// If block next to chest is chest and has a block or ocelot on top
if (isBlockedChest(world, id, x - 1, y, z))
return true;
if (isBlockedChest(world, id, x + 1, y, z))
return true;
if (isBlockedChest(world, id, x, y, z - 1))
return true;
if (isBlockedChest(world, id, x, y, z + 1))
return true;
return false;
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
@@ -87,58 +132,22 @@ public class AnySilentChest implements IAnySilentChest {
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
if (chest == null)
return true;
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
if (!anychest) {
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)).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)).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)).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)).l()))
return true;
}
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
boolean returnValue = true;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
try {
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
player.activeContainer = silentContainerChest;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
return returnValue;
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -18,13 +18,13 @@ package com.lishid.openinv.internal.v1_10_R1;
import java.lang.reflect.Field;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_10_R1.IInventory;
@@ -49,7 +49,7 @@ public class InventoryAccess implements IInventoryAccess {
return true;
}
private IInventory grabInventory(Inventory inventory) {
if(inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory();

View File

@@ -16,12 +16,14 @@
package com.lishid.openinv.internal.v1_10_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.mojang.authlib.GameProfile;
// Volatile
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.MinecraftServer;
@@ -29,10 +31,10 @@ import net.minecraft.server.v1_10_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
if (offline == null || !offline.hasPlayedBefore()) {
return null;
}
@@ -56,4 +58,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getUniqueId().toString();
}
}

View File

@@ -18,44 +18,32 @@ package com.lishid.openinv.internal.v1_10_R1;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.IInventory;
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
import net.minecraft.server.v1_10_R1.InventorySubcontainer;
import net.minecraft.server.v1_10_R1.ItemStack;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player;
this.enderChest = craftPlayer.getHandle().getEnderChest();
this.bukkitOwner = craftPlayer;
setItemArrays(this, enderChest.getContents());
}
@@ -84,21 +72,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
setItemArrays(owner.getHandle().getEnderChest(), this.items);
this.bukkitOwner = player;
CraftPlayer craftPlayer = (CraftPlayer) player;
setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items);
}
catch (Exception e) {}
playerOnline = true;
@@ -106,62 +86,19 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public ItemStack[] getContents() {
return this.items;
}
@Override
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
public List<HumanEntity> getViewers() {
return transaction;
}
@Override
public InventoryHolder getOwner() {
return this.owner;
}
@Override
public void setMaxStackSize(int size) {
maxStack = size;
}
@Override
public int getMaxStackSize() {
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -19,33 +19,27 @@ package com.lishid.openinv.internal.v1_10_R1;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[4];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
}
@@ -92,49 +86,37 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
setItemArrays(this.player.inventory, items, armor, extraSlots);
playerOnline = true;
}
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
System.arraycopy(extraSlots, 0, C, items.length + armor.length, extraSlots.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
System.arraycopy(extraSlots, 0, contents, items.length + armor.length, extraSlots.length);
return contents;
}
@Override
public int getSize() {
return super.getSize() + 5;
return super.getSize() + 4;
}
@Override
@@ -277,13 +259,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack, true);
player.drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_11_R1</artifactId>
<name>OpenInvCraftbukkit1_11_R1</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,241 @@
/*
* Copyright (C) 2011-2014 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockChest;
import net.minecraft.server.v1_11_R1.BlockChest.Type;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
import net.minecraft.server.v1_11_R1.Container;
import net.minecraft.server.v1_11_R1.Entity;
import net.minecraft.server.v1_11_R1.EntityOcelot;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.EnumDirection;
import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.ITileInventory;
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_11_R1.StatisticList;
import net.minecraft.server.v1_11_R1.TileEntity;
import net.minecraft.server.v1_11_R1.TileEntityChest;
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
import net.minecraft.server.v1_11_R1.World;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnySilentContainer(org.bukkit.block.BlockState block) {
return block instanceof org.bukkit.block.Chest || block instanceof org.bukkit.block.ShulkerBox;
}
@Override
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
BlockPosition blockPosition = new BlockPosition(x, y, z);
Object tile = world.getTileEntity(blockPosition);
if (tile == null) {
return false;
}
Block block = world.getType(new BlockPosition(x, y, z)).getBlock();
Container container = null;
if (block instanceof BlockChest) {
BlockChest blockChest = (BlockChest) block;
for (EnumDirection enumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
BlockPosition localBlockPosition = blockPosition.shift(enumDirection);
Block localBlock = world.getType(localBlockPosition).getBlock();
if (localBlock != block) {
continue;
}
if (!anychest && isBlockedChest(world, localBlock, localBlockPosition)) {
return false;
}
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
if (!(localTileEntity instanceof TileEntityChest)) {
continue;
}
if ((enumDirection == EnumDirection.WEST) || (enumDirection == EnumDirection.NORTH)) {
tile = new InventoryLargeChest("container.chestDouble",
(TileEntityChest) localTileEntity, (ITileInventory) tile);
} else {
tile = new InventoryLargeChest("container.chestDouble",
(ITileInventory) tile, (TileEntityChest) localTileEntity);
}
break;
}
if (blockChest.g == Type.BASIC)
player.b(StatisticList.ac);
else if (blockChest.g == Type.TRAP) {
player.b(StatisticList.W);
}
if (silentchest) {
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
}
}
if (block instanceof BlockShulkerBox) {
if (!anychest && isBlockedShulkerBox(world, blockPosition, block)) {
return false;
}
player.b(StatisticList.ae);
if (silentchest && tile instanceof TileEntityShulkerBox) {
// TODO: This fixes sound, but the box is then silent for anyone until the tile entity is recreated
SilentContainerShulkerBox.increaseOpenQuantity((TileEntityShulkerBox) tile);
container = new SilentContainerShulkerBox(player.inventory, ((IInventory) tile), player);
SilentContainerShulkerBox.decreaseOpenQuantity((TileEntityShulkerBox) tile);
}
}
boolean returnValue = false;
if (!silentchest || container == null) {
player.openContainer((IInventory) tile);
returnValue = true;
} else {
try {
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) tile).getScoreboardDisplayName(), ((IInventory) tile).getSize()));
player.activeContainer = container;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
BlockPosition blockPosition = new BlockPosition(x, y, z);
Block block = world.getType(blockPosition).getBlock();
if (block instanceof BlockShulkerBox) {
return isBlockedShulkerBox(world, blockPosition, block);
}
// For reference, loot at net.minecraft.server.BlockChest
// Check if chest is blocked or has an ocelot on top
if (world.getType(new BlockPosition(x, y + 1, z)).m() || hasOcelotOnTop(world, blockPosition)) {
return true;
}
// Check for matching adjacent chests that are blocked or have an ocelot on top
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
if (isBlockedChest(world, block, localBlockPosition)) {
return true;
}
}
return false;
}
private boolean isBlockedShulkerBox(World world, BlockPosition blockPosition, Block block) {
// For reference, look at net.minecraft.server.BlockShulkerBox
TileEntity tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return false;
}
IBlockData iBlockData = block.getBlockData();
EnumDirection enumDirection = iBlockData.get(BlockShulkerBox.a);
if (((TileEntityShulkerBox) tile).p() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
AxisAlignedBB axisAlignedBB = BlockShulkerBox.j.b(0.5F * enumDirection.getAdjacentX(),
0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
enumDirection.getAdjacentZ());
return !(world.b(axisAlignedBB.a(blockPosition.shift(enumDirection))));
}
return true;
}
private boolean isBlockedChest(World world, Block block, BlockPosition blockPosition) {
if (world.getType(blockPosition).getBlock() == block) {
return false;
}
return world.getType(blockPosition).m() || hasOcelotOnTop(world, blockPosition);
}
private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
for (Entity localEntity : world.a(EntityOcelot.class,
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
blockPosition.getZ() + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2011-2014 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_11_R1.IInventory;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
public class InventoryAccess implements IInventoryAccess {
@Override
public boolean check(Inventory inventory, HumanEntity player) {
IInventory inv = grabInventory(inventory);
if (inv instanceof SpecialPlayerInventory) {
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
return false;
}
} else if (inv instanceof SpecialEnderChest) {
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
return false;
}
}
return true;
}
private IInventory grabInventory(Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory();
}
// Use reflection to find the iinventory
Class<? extends Inventory> clazz = inventory.getClass();
IInventory result = null;
for (Field f : clazz.getDeclaredFields()) {
f.setAccessible(true);
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
try {
result = (IInventory) f.get(inventory);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return result;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2011-2014 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadPlayer(OfflinePlayer offline) {
if (offline == null || !offline.hasPlayedBefore()) {
return null;
}
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity();
if (target != null) {
// Load data
target.loadData();
// Return the entity
return target;
}
return null;
}
@Override
public String getPlayerDataID(OfflinePlayer player) {
return player.getUniqueId().toString();
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2011-2014 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
// Volatile
import net.minecraft.server.v1_11_R1.ContainerChest;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest {
public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
// close signal
iInventory.closeContainer(entityHuman);
}
@Override
public void b(EntityHuman entityHuman) {
// Don't send close signal twice, might screw up
PlayerInventory playerinventory = entityHuman.inventory;
if (!playerinventory.getCarried().isEmpty()) {
entityHuman.drop(playerinventory.getCarried(), false);
playerinventory.setCarried(ItemStack.a);
}
}
}

View File

@@ -0,0 +1,55 @@
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import net.minecraft.server.v1_11_R1.ContainerShulkerBox;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.PlayerInventory;
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
public class SilentContainerShulkerBox extends ContainerShulkerBox {
private static Field h;
private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
if (h == null) {
h = TileEntityShulkerBox.class.getDeclaredField("h");
h.setAccessible(true);
}
return h;
}
public static void increaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
try {
exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) + 1);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void decreaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
try {
exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) - 1);
} catch (Exception e) {
e.printStackTrace();
}
}
public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
}
@Override
public void b(EntityHuman entityHuman) {
PlayerInventory playerinventory = entityHuman.inventory;
if (!playerinventory.getCarried().isEmpty()) {
entityHuman.drop(playerinventory.getCarried(), false);
playerinventory.setCarried(ItemStack.a);
}
}
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2011-2014 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
import net.minecraft.server.v1_11_R1.InventorySubcontainer;
import net.minecraft.server.v1_11_R1.ItemStack;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player;
this.enderChest = craftPlayer.getHandle().getEnderChest();
this.bukkitOwner = craftPlayer;
setItemLists(this, enderChest.getContents());
}
private void setItemLists(InventorySubcontainer subcontainer, List<ItemStack> list) {
try {
// Prepare to remove final modifier
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
// Access and replace main inventory array
Field field = InventorySubcontainer.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(subcontainer, list);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
this.bukkitOwner = player;
CraftPlayer craftPlayer = (CraftPlayer) player;
setItemLists(craftPlayer.getHandle().getEnderChest(), this.items);
}
catch (Exception e) {}
playerOnline = true;
}
}
@Override
public void setPlayerOffline() {
playerOnline = false;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -0,0 +1,257 @@
/*
* Copyright (C) 2011-2014 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_11_R1.ContainerUtil;
// Volatile
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NonNullList;
import net.minecraft.server.v1_11_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
}
private void setItemArrays(PlayerInventory inventory, NonNullList<ItemStack> items,
NonNullList<ItemStack> armor, NonNullList<ItemStack> extraSlots) {
try {
// Prepare to remove final modifier
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
// Access and replace main inventory array
Field field = PlayerInventory.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, items);
// Access and replace armor inventory array
field = PlayerInventory.class.getField("armor");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, armor);
// Access and replace offhand inventory array
field = PlayerInventory.class.getField("extraSlots");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, extraSlots);
// Access and replace array containing all inventory arrays
field = PlayerInventory.class.getDeclaredField("g");
field.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots }));
} catch (NoSuchFieldException e) {
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
setItemArrays(this.player.inventory, items, armor, extraSlots);
playerOnline = true;
}
}
@Override
public void setPlayerOffline() {
playerOnline = false;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public int getSize() {
return super.getSize() + 4;
}
@Override
public ItemStack getItem(int i) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list.get(i);
}
@Override
public ItemStack splitStack(int i, int j) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list == null || list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
}
@Override
public ItemStack splitWithoutUpdate(int i) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
if (list != null && !list.get(i).isEmpty()) {
ItemStack itemstack = list.get(i);
list.set(i, ItemStack.a);
return itemstack;
}
return ItemStack.a;
}
@Override
public void setItem(int i, ItemStack itemstack) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
player.drop(itemstack, true);
return;
}
if (list != null) {
list.set(i, itemstack);
}
}
private int getReversedItemSlotNum(int i) {
if (i >= 27)
return i - 27;
else
return i + 9;
}
private int getReversedArmorSlotNum(int i) {
if (i == 0)
return 3;
if (i == 1)
return 2;
if (i == 2)
return 1;
if (i == 3)
return 0;
else
return i;
}
@Override
public String getName() {
if (player.getName().length() > 16) {
return player.getName().substring(0, 16);
}
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_4_5</artifactId>
<name>OpenInvCraftbukkit1_4_5</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.4.5-R1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,13 +18,16 @@ package com.lishid.openinv.internal.v1_4_5;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_4_5.AxisAlignedBB;
import net.minecraft.server.v1_4_5.Block;
import net.minecraft.server.v1_4_5.EntityOcelot;
import net.minecraft.server.v1_4_5.EntityPlayer;
import net.minecraft.server.v1_4_5.IInventory;
import net.minecraft.server.v1_4_5.InventoryLargeChest;
@@ -34,48 +37,23 @@ import net.minecraft.server.v1_4_5.World;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.s(x, y + 1, z))
return true;
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest) {
if (world.s(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
@@ -87,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int id = 0;
try {
@@ -100,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
id = windowID.getInt(player);
id = id % 100 + 1;
windowID.setInt(player, id);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = id;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -117,4 +93,62 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
|| isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
}
private boolean isBlockedChest(World world, int x, int y, int z) {
if (world.getTypeId(x, y, z) != Block.CHEST.id) {
return false;
}
if (world.s(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_4_5;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -27,10 +29,10 @@ import net.minecraft.server.v1_4_5.MinecraftServer;
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -51,4 +53,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_4_5.EntityHuman;
import net.minecraft.server.v1_4_5.IInventory;
import net.minecraft.server.v1_4_5.InventoryEnderChest;
import net.minecraft.server.v1_4_5.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
@Override
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_4_5;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_4_5.EntityHuman;
import net.minecraft.server.v1_4_5.ItemStack;
import net.minecraft.server.v1_4_5.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -247,14 +228,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public String getName() {
if (player.name.length() > 16) {
return player.name.substring(0, 16);
if (player.getName().length() > 16) {
return player.getName().substring(0, 16);
}
return player.name;
return player.getName();
}
@Override
public boolean a_(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_4_6</artifactId>
<name>OpenInvCraftbukkit1_4_6</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.4.6-R0.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,12 +18,16 @@ package com.lishid.openinv.internal.v1_4_6;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_4_6.AxisAlignedBB;
import net.minecraft.server.v1_4_6.Block;
import net.minecraft.server.v1_4_6.EntityOcelot;
import net.minecraft.server.v1_4_6.EntityPlayer;
import net.minecraft.server.v1_4_6.IInventory;
import net.minecraft.server.v1_4_6.InventoryLargeChest;
@@ -31,51 +35,25 @@ import net.minecraft.server.v1_4_6.Packet100OpenWindow;
import net.minecraft.server.v1_4_6.TileEntityChest;
import net.minecraft.server.v1_4_6.World;
// Volatile
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.s(x, y + 1, z))
return true;
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest) {
if (world.s(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
@@ -87,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int id = 0;
try {
@@ -100,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
id = windowID.getInt(player);
id = id % 100 + 1;
windowID.setInt(player, id);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = id;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -117,4 +93,62 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
|| isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
}
private boolean isBlockedChest(World world, int x, int y, int z) {
if (world.getTypeId(x, y, z) != Block.CHEST.id) {
return false;
}
if (world.s(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -23,9 +23,9 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
// Volatile
import net.minecraft.server.v1_4_6.IInventory;
// Volatile
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
public class InventoryAccess implements IInventoryAccess {

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_4_6;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -27,10 +29,10 @@ import net.minecraft.server.v1_4_6.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -51,4 +53,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_4_6.EntityHuman;
import net.minecraft.server.v1_4_6.IInventory;
import net.minecraft.server.v1_4_6.InventoryEnderChest;
import net.minecraft.server.v1_4_6.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
@Override
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_4_6;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_4_6.EntityHuman;
import net.minecraft.server.v1_4_6.ItemStack;
import net.minecraft.server.v1_4_6.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -247,14 +228,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public String getName() {
if (player.name.length() > 16) {
return player.name.substring(0, 16);
if (player.getName().length() > 16) {
return player.getName().substring(0, 16);
}
return player.name;
return player.getName();
}
@Override
public boolean a_(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_4_R1</artifactId>
<name>OpenInvCraftbukkit1_4_R1</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.4.7-R1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,12 +18,16 @@ package com.lishid.openinv.internal.v1_4_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
import net.minecraft.server.v1_4_R1.Block;
import net.minecraft.server.v1_4_R1.EntityOcelot;
import net.minecraft.server.v1_4_R1.EntityPlayer;
import net.minecraft.server.v1_4_R1.IInventory;
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
@@ -31,51 +35,25 @@ import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
import net.minecraft.server.v1_4_R1.TileEntityChest;
import net.minecraft.server.v1_4_R1.World;
// Volatile
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.s(x, y + 1, z))
return true;
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest) {
if (world.s(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
@@ -87,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int id = 0;
try {
@@ -100,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
id = windowID.getInt(player);
id = id % 100 + 1;
windowID.setInt(player, id);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = id;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -117,4 +93,62 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
|| isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
}
private boolean isBlockedChest(World world, int x, int y, int z) {
if (world.getTypeId(x, y, z) != Block.CHEST.id) {
return false;
}
if (world.s(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,16 +16,16 @@
package com.lishid.openinv.internal.v1_4_R1;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import net.minecraft.server.v1_4_R1.IInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_R1.IInventory;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
public class InventoryAccess implements IInventoryAccess {

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_4_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -28,10 +30,10 @@ import net.minecraft.server.v1_4_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -52,4 +54,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
// Volatile
import com.lishid.openinv.internal.ISpecialEnderChest;
import net.minecraft.server.v1_4_R1.EntityHuman;
import net.minecraft.server.v1_4_R1.IInventory;
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
import net.minecraft.server.v1_4_R1.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
@Override
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_4_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import net.minecraft.server.v1_4_R1.EntityHuman;
// Volatile
import net.minecraft.server.v1_4_R1.ItemStack;
import net.minecraft.server.v1_4_R1.PlayerInventory;
// Volatile
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -247,14 +228,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public String getName() {
if (player.name.length() > 16) {
return player.name.substring(0, 16);
if (player.getName().length() > 16) {
return player.getName().substring(0, 16);
}
return player.name;
return player.getName();
}
@Override
public boolean a_(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_5_R2</artifactId>
<name>OpenInvCraftbukkit1_5_R2</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.5.1-R0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,12 +18,15 @@ package com.lishid.openinv.internal.v1_5_R2;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
import net.minecraft.server.v1_5_R2.EntityOcelot;
import net.minecraft.server.v1_5_R2.EntityPlayer;
import net.minecraft.server.v1_5_R2.IInventory;
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
@@ -33,54 +36,27 @@ import net.minecraft.server.v1_5_R2.World;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = world.getTypeId(x, y, z);
if (!anychest) {
if (world.t(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
}
if (world.getTypeId(x - 1, y, z) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (world.getTypeId(x + 1, y, z) == id)
@@ -90,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -103,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -120,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (world.getTypeId(x, y, z) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_5_R2;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R2.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_5_R2;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -27,10 +29,10 @@ import net.minecraft.server.v1_5_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -51,4 +53,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_5_R2.EntityHuman;
import net.minecraft.server.v1_5_R2.IInventory;
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
import net.minecraft.server.v1_5_R2.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_5_R2;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_5_R2.EntityHuman;
import net.minecraft.server.v1_5_R2.ItemStack;
import net.minecraft.server.v1_5_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -247,14 +228,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public String getName() {
if (player.name.length() > 16) {
return player.name.substring(0, 16);
if (player.getName().length() > 16) {
return player.getName().substring(0, 16);
}
return player.name;
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_5_R3</artifactId>
<name>OpenInvCraftbukkit1_5_R3</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.5.2-R1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,12 +18,15 @@ package com.lishid.openinv.internal.v1_5_R3;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_5_R3.AxisAlignedBB;
import net.minecraft.server.v1_5_R3.EntityOcelot;
import net.minecraft.server.v1_5_R3.EntityPlayer;
import net.minecraft.server.v1_5_R3.IInventory;
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
@@ -33,54 +36,27 @@ import net.minecraft.server.v1_5_R3.World;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = world.getTypeId(x, y, z);
if (!anychest) {
if (world.t(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
}
if (world.getTypeId(x - 1, y, z) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (world.getTypeId(x + 1, y, z) == id)
@@ -90,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -103,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -120,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (world.getTypeId(x, y, z) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_5_R3;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R3.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_5_R3;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -27,10 +29,10 @@ import net.minecraft.server.v1_5_R3.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -51,4 +53,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_5_R3.EntityHuman;
import net.minecraft.server.v1_5_R3.IInventory;
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
import net.minecraft.server.v1_5_R3.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_5_R3;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_5_R3.EntityHuman;
import net.minecraft.server.v1_5_R3.ItemStack;
import net.minecraft.server.v1_5_R3.PlayerInventory;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -247,14 +228,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public String getName() {
if (player.name.length() > 16) {
return player.name.substring(0, 16);
if (player.getName().length() > 16) {
return player.getName().substring(0, 16);
}
return player.name;
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_6_R1</artifactId>
<name>OpenInvCraftbukkit1_6_R1</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.6.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,12 +18,15 @@ package com.lishid.openinv.internal.v1_6_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_6_R1.AxisAlignedBB;
import net.minecraft.server.v1_6_R1.EntityOcelot;
import net.minecraft.server.v1_6_R1.EntityPlayer;
import net.minecraft.server.v1_6_R1.IInventory;
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
@@ -33,54 +36,27 @@ import net.minecraft.server.v1_6_R1.World;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = world.getTypeId(x, y, z);
if (!anychest) {
if (world.t(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
}
if (world.getTypeId(x - 1, y, z) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (world.getTypeId(x + 1, y, z) == id)
@@ -90,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -103,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -120,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (world.getTypeId(x, y, z) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_6_R1;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R1.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_6_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -27,10 +29,10 @@ import net.minecraft.server.v1_6_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -51,4 +53,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_6_R1.EntityHuman;
import net.minecraft.server.v1_6_R1.IInventory;
import net.minecraft.server.v1_6_R1.InventoryEnderChest;
import net.minecraft.server.v1_6_R1.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,34 +16,26 @@
package com.lishid.openinv.internal.v1_6_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_6_R1.EntityHuman;
import net.minecraft.server.v1_6_R1.ItemStack;
import net.minecraft.server.v1_6_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -54,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -75,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -217,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -254,8 +234,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_6_R2</artifactId>
<name>OpenInvCraftbukkit1_6_R2</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.6.2-R1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,12 +18,15 @@ package com.lishid.openinv.internal.v1_6_R2;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_6_R2.AxisAlignedBB;
import net.minecraft.server.v1_6_R2.EntityOcelot;
import net.minecraft.server.v1_6_R2.EntityPlayer;
import net.minecraft.server.v1_6_R2.IInventory;
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
@@ -33,54 +36,27 @@ import net.minecraft.server.v1_6_R2.World;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = world.getTypeId(x, y, z);
if (!anychest) {
if (world.t(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
}
if (world.getTypeId(x - 1, y, z) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (world.getTypeId(x + 1, y, z) == id)
@@ -90,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -103,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -120,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (world.getTypeId(x, y, z) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_6_R2;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R2.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_6_R2;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -27,10 +29,10 @@ import net.minecraft.server.v1_6_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R2.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -51,4 +53,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_6_R2.EntityHuman;
import net.minecraft.server.v1_6_R2.IInventory;
import net.minecraft.server.v1_6_R2.InventoryEnderChest;
import net.minecraft.server.v1_6_R2.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_6_R2;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_6_R2.EntityHuman;
import net.minecraft.server.v1_6_R2.ItemStack;
import net.minecraft.server.v1_6_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -253,8 +234,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_6_R3</artifactId>
<name>OpenInvCraftbukkit1_6_R3</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.6.4-R2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,12 +18,15 @@ package com.lishid.openinv.internal.v1_6_R3;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_6_R3.AxisAlignedBB;
import net.minecraft.server.v1_6_R3.EntityOcelot;
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.IInventory;
import net.minecraft.server.v1_6_R3.InventoryLargeChest;
@@ -33,54 +36,27 @@ import net.minecraft.server.v1_6_R3.World;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = world.getTypeId(x, y, z);
if (!anychest) {
if (world.t(x, y + 1, z))
return true;
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
}
if (world.getTypeId(x - 1, y, z) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (world.getTypeId(x + 1, y, z) == id)
@@ -90,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
if (world.getTypeId(x, y, z + 1) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -103,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -120,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (world.getTypeId(x, y, z) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_6_R3;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R3.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_6_R3;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -27,10 +29,10 @@ import net.minecraft.server.v1_6_R3.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R3.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
@@ -51,4 +53,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_6_R3.EntityHuman;
import net.minecraft.server.v1_6_R3.IInventory;
import net.minecraft.server.v1_6_R3.InventoryEnderChest;
import net.minecraft.server.v1_6_R3.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_6_R3;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_6_R3.EntityHuman;
import net.minecraft.server.v1_6_R3.ItemStack;
import net.minecraft.server.v1_6_R3.PlayerInventory;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack);
player.drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -253,8 +234,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_7_R1</artifactId>
<name>OpenInvCraftbukkit1_7_R1</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.2-R0.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,13 +18,16 @@ package com.lishid.openinv.internal.v1_7_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_7_R1.AxisAlignedBB;
import net.minecraft.server.v1_7_R1.Block;
import net.minecraft.server.v1_7_R1.EntityOcelot;
import net.minecraft.server.v1_7_R1.EntityPlayer;
import net.minecraft.server.v1_7_R1.IInventory;
import net.minecraft.server.v1_7_R1.InventoryLargeChest;
@@ -34,54 +37,27 @@ import net.minecraft.server.v1_7_R1.World;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.getType(x, y + 1, z).c())
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block on top
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = Block.b(world.getType(x, y, z));
if (!anychest) {
if (world.getType(x, y + 1, z).c())
return true;
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
}
if (Block.b(world.getType(x - 1, y, z)) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (Block.b(world.getType(x + 1, y, z)) == id)
@@ -91,11 +67,11 @@ public class AnySilentChest implements IAnySilentChest {
if (Block.b(world.getType(x, y, z + 1)) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -104,16 +80,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -121,4 +95,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (Block.b(world.getType(x, y, z)) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_7_R1;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R1.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_7_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -28,10 +30,10 @@ import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
GameProfile profile = new GameProfile(null, offline.getName());
@@ -53,4 +55,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_7_R1.EntityHuman;
import net.minecraft.server.v1_7_R1.IInventory;
import net.minecraft.server.v1_7_R1.InventoryEnderChest;
import net.minecraft.server.v1_7_R1.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_7_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_7_R1.EntityHuman;
import net.minecraft.server.v1_7_R1.ItemStack;
import net.minecraft.server.v1_7_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack, true);
player.drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -253,8 +234,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_7_R2</artifactId>
<name>OpenInvCraftbukkit1_7_R2</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.5-R0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,13 +18,16 @@ package com.lishid.openinv.internal.v1_7_R2;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
import net.minecraft.server.v1_7_R2.Block;
//Volatile
import net.minecraft.server.v1_7_R2.AxisAlignedBB;
import net.minecraft.server.v1_7_R2.Block;
import net.minecraft.server.v1_7_R2.EntityOcelot;
import net.minecraft.server.v1_7_R2.EntityPlayer;
import net.minecraft.server.v1_7_R2.IInventory;
import net.minecraft.server.v1_7_R2.InventoryLargeChest;
@@ -34,54 +37,27 @@ import net.minecraft.server.v1_7_R2.World;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.getType(x, y + 1, z).c())
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block on top
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = Block.b(world.getType(x, y, z));
if (!anychest) {
if (world.getType(x, y + 1, z).c())
return true;
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
}
if (Block.b(world.getType(x - 1, y, z)) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (Block.b(world.getType(x + 1, y, z)) == id)
@@ -91,11 +67,11 @@ public class AnySilentChest implements IAnySilentChest {
if (Block.b(world.getType(x, y, z + 1)) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -104,16 +80,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -121,4 +95,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (Block.b(world.getType(x, y, z)) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_7_R2;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R2.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_7_R2;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -28,10 +30,10 @@ import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
GameProfile profile = new GameProfile(null, offline.getName());
@@ -53,4 +55,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getName();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_7_R2.EntityHuman;
import net.minecraft.server.v1_7_R2.IInventory;
import net.minecraft.server.v1_7_R2.InventoryEnderChest;
import net.minecraft.server.v1_7_R2.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_7_R2;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_7_R2.EntityHuman;
import net.minecraft.server.v1_7_R2.ItemStack;
import net.minecraft.server.v1_7_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack, true);
player.drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -253,8 +234,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>OpenInvCraftbukkit1_7_R3</artifactId>
<name>OpenInvCraftbukkit1_7_R3</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcore</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.9-R0.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,13 +18,16 @@ package com.lishid.openinv.internal.v1_7_R3;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.lishid.openinv.internal.IAnySilentChest;
// Volatile
import net.minecraft.server.v1_7_R3.AxisAlignedBB;
import net.minecraft.server.v1_7_R3.Block;
import net.minecraft.server.v1_7_R3.EntityOcelot;
import net.minecraft.server.v1_7_R3.EntityPlayer;
import net.minecraft.server.v1_7_R3.IInventory;
import net.minecraft.server.v1_7_R3.InventoryLargeChest;
@@ -34,54 +37,27 @@ import net.minecraft.server.v1_7_R3.World;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.getType(x, y + 1, z).c())
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block on top
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
return false;
public boolean isAnySilentContainer(BlockState block) {
return block instanceof org.bukkit.block.Chest;
}
@Override
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = world.getTileEntity(x, y, z);
if (chest == null)
return true;
return false;
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
return false;
}
int id = Block.b(world.getType(x, y, z));
if (!anychest) {
if (world.getType(x, y + 1, z).c())
return true;
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
}
if (Block.b(world.getType(x - 1, y, z)) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (Block.b(world.getType(x + 1, y, z)) == id)
@@ -91,11 +67,11 @@ public class AnySilentChest implements IAnySilentChest {
if (Block.b(world.getType(x, y, z + 1)) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
boolean returnValue = true;
boolean returnValue = false;
if (!silentchest) {
player.openContainer((IInventory) chest);
}
else {
returnValue = true;
} else {
try {
int windowId = 0;
try {
@@ -104,16 +80,14 @@ public class AnySilentChest implements IAnySilentChest {
windowId = windowID.getInt(player);
windowId = windowId % 100 + 1;
windowID.setInt(player, windowId);
}
catch (NoSuchFieldException e) {}
} catch (NoSuchFieldException e) {}
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
returnValue = false;
}
catch (Exception e) {
returnValue = true;
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
@@ -121,4 +95,64 @@ public class AnySilentChest implements IAnySilentChest {
return returnValue;
}
@Override
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block or ocelot on top
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block or ocelot on top
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
}
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
if (Block.b(world.getType(x, y, z)) != id) {
return false;
}
if (world.t(x, y + 1, z)) {
return true;
}
return hasOcelotOnTop(world, x, y, z);
}
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
for (Object localEntity : world.a(EntityOcelot.class,
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
*/
@Deprecated
@Override
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
return !activateContainer(player, anychest, silentchest, x, y, z);
}
/**
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
*/
@Deprecated
@Override
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
return isAnyContainerNeeded(player, x, y, z);
}
}

View File

@@ -16,13 +16,13 @@
package com.lishid.openinv.internal.v1_7_R3;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.IInventoryAccess;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R3.IInventory;

View File

@@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_7_R3;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -28,10 +30,10 @@ import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager {
public class PlayerDataManager implements IPlayerDataManager {
@Override
public Player loadOfflinePlayer(OfflinePlayer offline) {
public Player loadPlayer(OfflinePlayer offline) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
@@ -53,4 +55,5 @@ public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataMan
public String getPlayerDataID(OfflinePlayer player) {
return player.getUniqueId().toString();
}
}

View File

@@ -20,16 +20,14 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
// Volatile
import net.minecraft.server.v1_7_R3.EntityHuman;
import net.minecraft.server.v1_7_R3.IInventory;
import net.minecraft.server.v1_7_R3.InventoryEnderChest;
import net.minecraft.server.v1_7_R3.InventorySubcontainer;
@@ -41,7 +39,6 @@ import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final OpenInv plugin;
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
@@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) {
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
this.plugin = plugin;
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
@@ -63,15 +59,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
@@ -88,9 +75,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
@@ -106,7 +97,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
@Override
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.inventoryRemovalCheck(true);
}
@Override
@@ -129,22 +119,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
return maxStack;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen() {
}
public void f() {
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -16,33 +16,26 @@
package com.lishid.openinv.internal.v1_7_R3;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
// Volatile
import net.minecraft.server.v1_7_R3.EntityHuman;
import net.minecraft.server.v1_7_R3.ItemStack;
import net.minecraft.server.v1_7_R3.PlayerInventory;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final OpenInv plugin;
private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this);
private CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.plugin = plugin;
this.owner = ((CraftPlayer) p);
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@@ -53,20 +46,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return inventory;
}
@Override
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save && !plugin.disableSaving()) {
owner.saveData();
}
return offline;
}
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player = ((CraftPlayer) player).getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
@@ -74,23 +57,21 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
}
@Override
public boolean setPlayerOffline() {
public void setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck(true);
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, contents, 0, items.length);
System.arraycopy(armor, 0, contents, items.length, armor.length);
return contents;
}
@Override
@@ -216,13 +197,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemstack, true);
player.drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().defaultContainer.b();
player.defaultContainer.b();
}
private int getReversedItemSlotNum(int i) {
@@ -253,8 +234,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

Some files were not shown because too many files have changed in this diff Show More