Compare commits
	
		
			59 Commits
		
	
	
		
			3.3.4-A1
			...
			feature/cu
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					1dd28ac0eb | ||
| 
						 | 
					ff76f2b95a | ||
| 
						 | 
					b92543e078 | ||
| 
						 | 
					252ca34e42 | ||
| 
						 | 
					c28383ef36 | ||
| 
						 | 
					5fbab1ab8f | ||
| 
						 | 
					d97b092978 | ||
| 
						 | 
					154bf56c2a | ||
| 
						 | 
					d65a9caeb2 | ||
| 
						 | 
					b3c4253606 | ||
| 
						 | 
					b64000e89b | ||
| 
						 | 
					3faf41ef18 | ||
| 
						 | 
					db27d25a93 | ||
| 
						 | 
					0f02e6fe66 | ||
| 
						 | 
					ec07637e9f | ||
| 
						 | 
					b269f3509c | ||
| 
						 | 
					f2e4c8a3ad | ||
| 
						 | 
					35839f1548 | ||
| 
						 | 
					a4a462a1fa | ||
| 
						 | 
					b9f901af66 | ||
| 
						 | 
					1333056613 | ||
| 
						 | 
					fb23df313a | ||
| 
						 | 
					96dc400c83 | ||
| 
						 | 
					b801d36f12 | ||
| 
						 | 
					4c27599dd9 | ||
| 
						 | 
					64ad0a5267 | ||
| 
						 | 
					cba7f44192 | ||
| 
						 | 
					e8ace6bd06 | ||
| 
						 | 
					fd70f260ba | ||
| 
						 | 
					be9874ba1d | ||
| 
						 | 
					096faef161 | ||
| 
						 | 
					df96d5106a | ||
| 
						 | 
					fe77a1d2e7 | ||
| 
						 | 
					3096e43540 | ||
| 
						 | 
					2939551d65 | ||
| 
						 | 
					fb74fd3ced | ||
| 
						 | 
					393fe1d837 | ||
| 
						 | 
					f80df9d83b | ||
| 
						 | 
					5c006f8ebd | ||
| 
						 | 
					57097e626e | ||
| 
						 | 
					0f266c8a64 | ||
| 
						 | 
					185f037254 | ||
| 
						 | 
					e4d0020296 | ||
| 
						 | 
					9e37cbbca8 | ||
| 
						 | 
					adc35e9ad5 | ||
| 
						 | 
					a469c732cc | ||
| 
						 | 
					c5c1f47167 | ||
| 
						 | 
					dc59356f76 | ||
| 
						 | 
					d497772ad7 | ||
| 
						 | 
					4f4d46974a | ||
| 
						 | 
					96c38895e2 | ||
| 
						 | 
					5753648d77 | ||
| 
						 | 
					3725711b94 | ||
| 
						 | 
					c22e18c096 | ||
| 
						 | 
					6bff759d72 | ||
| 
						 | 
					582c7201dd | ||
| 
						 | 
					59a8ed70bb | ||
| 
						 | 
					27812c133d | ||
| 
						 | 
					165f3fb00e | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -3,7 +3,7 @@
 | 
				
			|||||||
**/.project
 | 
					**/.project
 | 
				
			||||||
**/.classpath
 | 
					**/.classpath
 | 
				
			||||||
**/.idea
 | 
					**/.idea
 | 
				
			||||||
**/.iml
 | 
					**.iml
 | 
				
			||||||
**/target
 | 
					**/target
 | 
				
			||||||
**/bin
 | 
					**/bin
 | 
				
			||||||
**/out
 | 
					**/out
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								README.MD
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								README.MD
									
									
									
									
									
								
							@@ -132,15 +132,19 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## For Developers
 | 
					## For Developers
 | 
				
			||||||
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
 | 
					To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
 | 
				
			||||||
Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
 | 
					Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.8-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.8-R0.1-SNAPSHOT`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To compile for a specific version or set of versions, you'll need to use a profile. Provided profiles are `latest`, `recent` (last 2 major Minecraft versions), and `all`. Select an existing profile using the `-P` argument (ex: `mvn clean package -am -P all`) or make your own. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
 | 
					To compile for a single version, specify the NMS revision you are targeting: `mvn -pl <NMS module> -am clean install`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The final file is target/OpenInv.jar
 | 
					To compile for a set of versions, you'll need to use a profile. The only provided profile is `all`. Select a profile using the `-P` argument: `mvn clean package -am -P all`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For more information, check out the [official Maven guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The final file is `target/OpenInv.jar`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## License
 | 
					## License
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This program is free software: you can redistribute it and/or modify
 | 
					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
 | 
					it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										48
									
								
								api/pom.xml
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								api/pom.xml
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					  ~ Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
  ~
 | 
					  ~
 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					  ~ 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
 | 
					  ~ it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -21,7 +21,7 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvparent</artifactId>
 | 
					    <artifactId>openinvparent</artifactId>
 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvapi</artifactId>
 | 
					  <artifactId>openinvapi</artifactId>
 | 
				
			||||||
@@ -29,12 +29,46 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  <dependencies>
 | 
					  <dependencies>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					      <groupId>org.jetbrains</groupId>
 | 
				
			||||||
      <artifactId>bukkit</artifactId>
 | 
					      <artifactId>annotations</artifactId>
 | 
				
			||||||
      <version>1.4.5-R1.0</version>
 | 
					      <version>17.0.0</version>
 | 
				
			||||||
      <scope>system</scope>
 | 
					    </dependency>
 | 
				
			||||||
      <systemPath>${project.basedir}/../lib/bukkit-1.4.5-R1.0.jar</systemPath>
 | 
					    <dependency>
 | 
				
			||||||
 | 
					      <groupId>org.spigotmc</groupId>
 | 
				
			||||||
 | 
					      <artifactId>spigot-api</artifactId>
 | 
				
			||||||
 | 
					      <version>1.8.8-R0.1-SNAPSHOT</version>
 | 
				
			||||||
 | 
					      <scope>provided</scope>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <build>
 | 
				
			||||||
 | 
					    <plugins>
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					        <executions>
 | 
				
			||||||
 | 
					          <execution>
 | 
				
			||||||
 | 
					            <phase>package</phase>
 | 
				
			||||||
 | 
					            <goals>
 | 
				
			||||||
 | 
					              <goal>shade</goal>
 | 
				
			||||||
 | 
					            </goals>
 | 
				
			||||||
 | 
					          </execution>
 | 
				
			||||||
 | 
					        </executions>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <artifactId>maven-compiler-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>3.8.1</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <source>1.8</source>
 | 
				
			||||||
 | 
					          <target>1.8</target>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					    </plugins>
 | 
				
			||||||
 | 
					  </build>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</project>
 | 
					</project>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -16,16 +16,22 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv;
 | 
					package com.lishid.openinv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					import com.lishid.openinv.internal.IAnySilentContainer;
 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					import com.lishid.openinv.internal.IInventoryAccess;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
				
			||||||
 | 
					import com.lishid.openinv.util.InventoryAccess;
 | 
				
			||||||
 | 
					import com.lishid.openinv.util.StringMetric;
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
import org.bukkit.plugin.Plugin;
 | 
					import org.bukkit.plugin.Plugin;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Interface defining behavior for the OpenInv plugin.
 | 
					 * Interface defining behavior for the OpenInv plugin.
 | 
				
			||||||
@@ -45,50 +51,23 @@ public interface IOpenInv {
 | 
				
			|||||||
    boolean disableSaving();
 | 
					    boolean disableSaving();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets the active ISilentContainer implementation. May return null if the server version is
 | 
					     * Gets the active ISilentContainer implementation.
 | 
				
			||||||
     * unsupported.
 | 
					 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return the ISilentContainer
 | 
					     * @return the ISilentContainer
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    IAnySilentContainer getAnySilentContainer();
 | 
					    @NotNull IAnySilentContainer getAnySilentContainer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets an ISpecialEnderChest for the given Player. Returns null if the ISpecialEnderChest could
 | 
					     * Gets the active IInventoryAccess implementation.
 | 
				
			||||||
     * not be instantiated.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param player the Player
 | 
					 | 
				
			||||||
     * @param online true if the Player is currently online
 | 
					 | 
				
			||||||
     * @return the ISpecialEnderChest
 | 
					 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					 | 
				
			||||||
     * @deprecated Use {@link IOpenInv#getSpecialEnderChest(Player, boolean)}
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    @Deprecated
 | 
					 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    ISpecialEnderChest getEnderChest(Player player, boolean online);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets an ISpecialPlayerInventory for the given Player. Returns null if the
 | 
					 | 
				
			||||||
     * ISpecialPlayerInventory could not be instantiated.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param player the Player
 | 
					 | 
				
			||||||
     * @param online true if the Player is currently online
 | 
					 | 
				
			||||||
     * @return the ISpecialPlayerInventory
 | 
					 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					 | 
				
			||||||
     * @deprecated Use {@link IOpenInv#getSpecialInventory(Player, boolean)}
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    @Deprecated
 | 
					 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    ISpecialPlayerInventory getInventory(Player player, boolean online);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets the active IInventoryAccess implementation. May return null if the server version is
 | 
					 | 
				
			||||||
     * unsupported.
 | 
					 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return the IInventoryAccess
 | 
					     * @return the IInventoryAccess
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    IInventoryAccess getInventoryAccess();
 | 
					    @Deprecated
 | 
				
			||||||
 | 
					    default @NotNull IInventoryAccess getInventoryAccess() {
 | 
				
			||||||
 | 
					        return new InventoryAccess();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets the provided player's AnyChest setting.
 | 
					     * Gets the provided player's AnyChest setting.
 | 
				
			||||||
@@ -97,7 +76,7 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @return true if AnyChest is enabled
 | 
					     * @return true if AnyChest is enabled
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    boolean getPlayerAnyChestStatus(OfflinePlayer player);
 | 
					    boolean getPlayerAnyChestStatus(@NotNull OfflinePlayer player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value
 | 
					     * Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value
 | 
				
			||||||
@@ -107,16 +86,18 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @return the identifier
 | 
					     * @return the identifier
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    String getPlayerID(OfflinePlayer offline);
 | 
					    default @NotNull String getPlayerID(@NotNull OfflinePlayer offline) {
 | 
				
			||||||
 | 
					        return offline.getUniqueId().toString();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets a player's SilentChest setting.
 | 
					     * Gets a player's SilentChest setting.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param player the OfflinePlayer
 | 
					     * @param offline the OfflinePlayer
 | 
				
			||||||
     * @return true if SilentChest is enabled
 | 
					     * @return true if SilentChest is enabled
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    boolean getPlayerSilentChestStatus(OfflinePlayer player);
 | 
					    boolean getPlayerSilentChestStatus(@NotNull OfflinePlayer offline);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets an ISpecialEnderChest for the given Player.
 | 
					     * Gets an ISpecialEnderChest for the given Player.
 | 
				
			||||||
@@ -127,7 +108,7 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @throws IllegalStateException  if the server version is unsupported
 | 
					     * @throws IllegalStateException  if the server version is unsupported
 | 
				
			||||||
     * @throws InstantiationException if the ISpecialEnderChest could not be instantiated
 | 
					     * @throws InstantiationException if the ISpecialEnderChest could not be instantiated
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ISpecialEnderChest getSpecialEnderChest(Player player, boolean online) throws InstantiationException;
 | 
					    @NotNull ISpecialEnderChest getSpecialEnderChest(@NotNull Player player, boolean online) throws InstantiationException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets an ISpecialPlayerInventory for the given Player.
 | 
					     * Gets an ISpecialPlayerInventory for the given Player.
 | 
				
			||||||
@@ -138,7 +119,7 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @throws IllegalStateException  if the server version is unsupported
 | 
					     * @throws IllegalStateException  if the server version is unsupported
 | 
				
			||||||
     * @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated
 | 
					     * @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ISpecialPlayerInventory getSpecialInventory(Player player, boolean online) throws InstantiationException;
 | 
					    @NotNull ISpecialPlayerInventory getSpecialInventory(@NotNull Player player, boolean online) throws InstantiationException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Checks if the server version is supported by OpenInv.
 | 
					     * Checks if the server version is supported by OpenInv.
 | 
				
			||||||
@@ -154,8 +135,7 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @return the Player, or null
 | 
					     * @return the Player, or null
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nullable
 | 
					    @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline);
 | 
				
			||||||
    Player loadPlayer(final OfflinePlayer offline);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get an OfflinePlayer by name.
 | 
					     * Get an OfflinePlayer by name.
 | 
				
			||||||
@@ -167,8 +147,85 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @param name the name of the Player
 | 
					     * @param name the name of the Player
 | 
				
			||||||
     * @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
 | 
					     * @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nullable
 | 
					    default @Nullable OfflinePlayer matchPlayer(@NotNull String name) {
 | 
				
			||||||
    OfflinePlayer matchPlayer(String name);
 | 
					
 | 
				
			||||||
 | 
					        // Warn if called on the main thread - if we resort to searching offline players, this may take several seconds.
 | 
				
			||||||
 | 
					        if (Bukkit.getServer().isPrimaryThread()) {
 | 
				
			||||||
 | 
					            this.getLogger().warning("Call to OpenInv#matchPlayer made on the main thread!");
 | 
				
			||||||
 | 
					            this.getLogger().warning("This can cause the server to hang, potentially severely.");
 | 
				
			||||||
 | 
					            this.getLogger().warning("Trace:");
 | 
				
			||||||
 | 
					            for (StackTraceElement element : new Throwable().fillInStackTrace().getStackTrace()) {
 | 
				
			||||||
 | 
					                this.getLogger().warning(element.toString());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        OfflinePlayer player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            UUID uuid = UUID.fromString(name);
 | 
				
			||||||
 | 
					            player = Bukkit.getOfflinePlayer(uuid);
 | 
				
			||||||
 | 
					            // Ensure player is a real player, otherwise return null
 | 
				
			||||||
 | 
					            if (player.hasPlayedBefore() || player.isOnline()) {
 | 
				
			||||||
 | 
					                return player;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } catch (IllegalArgumentException ignored) {
 | 
				
			||||||
 | 
					            // Not a UUID
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Ensure name is valid if server is in online mode to avoid unnecessary searching
 | 
				
			||||||
 | 
					        if (Bukkit.getServer().getOnlineMode() && !name.matches("[a-zA-Z0-9_]{3,16}")) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        player = Bukkit.getServer().getPlayerExact(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (player != null) {
 | 
				
			||||||
 | 
					            return player;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        player = Bukkit.getServer().getOfflinePlayer(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (player.hasPlayedBefore()) {
 | 
				
			||||||
 | 
					            return player;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        player = Bukkit.getServer().getPlayer(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (player != null) {
 | 
				
			||||||
 | 
					            return player;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        float bestMatch = 0;
 | 
				
			||||||
 | 
					        for (OfflinePlayer offline : Bukkit.getServer().getOfflinePlayers()) {
 | 
				
			||||||
 | 
					            if (offline.getName() == null) {
 | 
				
			||||||
 | 
					                // Loaded by UUID only, name has never been looked up.
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            float currentMatch = StringMetric.compareJaroWinkler(name, offline.getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (currentMatch == 1.0F) {
 | 
				
			||||||
 | 
					                return offline;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (currentMatch > bestMatch) {
 | 
				
			||||||
 | 
					                bestMatch = currentMatch;
 | 
				
			||||||
 | 
					                player = offline;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Only null if no players have played ever, otherwise even the worst match will do.
 | 
				
			||||||
 | 
					        return player;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Open an ISpecialInventory for a Player.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param player the Player
 | 
				
			||||||
 | 
					     * @param inventory the ISpecialInventory
 | 
				
			||||||
 | 
					     * @return the InventoryView for the opened ISpecialInventory
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Check the configuration value for whether or not OpenInv displays a notification to the user
 | 
					     * Check the configuration value for whether or not OpenInv displays a notification to the user
 | 
				
			||||||
@@ -194,7 +251,7 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @param plugin the Plugin no longer holding a reference to the Player
 | 
					     * @param plugin the Plugin no longer holding a reference to the Player
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void releasePlayer(Player player, Plugin plugin);
 | 
					    void releasePlayer(@NotNull Player player, @NotNull Plugin plugin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Mark a Player as in use by a Plugin to prevent it from being removed from the cache. Used to
 | 
					     * Mark a Player as in use by a Plugin to prevent it from being removed from the cache. Used to
 | 
				
			||||||
@@ -219,32 +276,34 @@ public interface IOpenInv {
 | 
				
			|||||||
     * @param plugin the Plugin holding the reference to the Player
 | 
					     * @param plugin the Plugin holding the reference to the Player
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void retainPlayer(Player player, Plugin plugin);
 | 
					    void retainPlayer(@NotNull Player player, @NotNull Plugin plugin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Sets a player's AnyChest setting.
 | 
					     * Sets a player's AnyChest setting.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param player the OfflinePlayer
 | 
					     * @param offline the OfflinePlayer
 | 
				
			||||||
     * @param status the status
 | 
					     * @param status the status
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void setPlayerAnyChestStatus(OfflinePlayer player, boolean status);
 | 
					    void setPlayerAnyChestStatus(@NotNull OfflinePlayer offline, boolean status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Sets a player's SilentChest setting.
 | 
					     * Sets a player's SilentChest setting.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param player the OfflinePlayer
 | 
					     * @param offline the OfflinePlayer
 | 
				
			||||||
     * @param status the status
 | 
					     * @param status the status
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void setPlayerSilentChestStatus(OfflinePlayer player, boolean status);
 | 
					    void setPlayerSilentChestStatus(@NotNull OfflinePlayer offline, boolean status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Forcibly unload a cached Player's data.
 | 
					     * Forcibly unload a cached Player's data.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param player the OfflinePlayer to unload
 | 
					     * @param offline the OfflinePlayer to unload
 | 
				
			||||||
     * @throws IllegalStateException if the server version is unsupported
 | 
					     * @throws IllegalStateException if the server version is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void unload(OfflinePlayer player);
 | 
					    void unload(@NotNull OfflinePlayer offline);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Logger getLogger();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -18,6 +18,7 @@ package com.lishid.openinv.internal;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.bukkit.block.Block;
 | 
					import org.bukkit.block.Block;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public interface IAnySilentContainer {
 | 
					public interface IAnySilentContainer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -26,19 +27,19 @@ public interface IAnySilentContainer {
 | 
				
			|||||||
     * containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)}
 | 
					     * containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)}
 | 
				
			||||||
     * first.
 | 
					     * first.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param player      the Player opening the container
 | 
					     * @param player    the Player opening the container
 | 
				
			||||||
     * @param silentchest whether the container's noise is to be silenced
 | 
					     * @param silent    whether the container's noise is to be silenced
 | 
				
			||||||
     * @param block       the Block
 | 
					     * @param block     the Block
 | 
				
			||||||
     * @return true if the container can be opened
 | 
					     * @return true if the container can be opened
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    boolean activateContainer(Player player, boolean silentchest, Block block);
 | 
					    boolean activateContainer(@NotNull Player player, boolean silent, @NotNull Block block);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Closes the Player's currently open container silently, if necessary.
 | 
					     * Closes the Player's currently open container silently, if necessary.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param player the Player closing a container
 | 
					     * @param player the Player closing a container
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void deactivateContainer(Player player);
 | 
					    void deactivateContainer(@NotNull Player player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Checks if the container at the given coordinates is blocked.
 | 
					     * Checks if the container at the given coordinates is blocked.
 | 
				
			||||||
@@ -47,7 +48,7 @@ public interface IAnySilentContainer {
 | 
				
			|||||||
     * @param block  the Block
 | 
					     * @param block  the Block
 | 
				
			||||||
     * @return true if the container is blocked
 | 
					     * @return true if the container is blocked
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    boolean isAnyContainerNeeded(Player player, Block block);
 | 
					    boolean isAnyContainerNeeded(@NotNull Player player, @NotNull Block block);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Checks if the given block is a container which can be unblocked or silenced.
 | 
					     * Checks if the given block is a container which can be unblocked or silenced.
 | 
				
			||||||
@@ -55,6 +56,6 @@ public interface IAnySilentContainer {
 | 
				
			|||||||
     * @param block the BlockState
 | 
					     * @param block the BlockState
 | 
				
			||||||
     * @return true if the Block is a supported container
 | 
					     * @return true if the Block is a supported container
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    boolean isAnySilentContainer(Block block);
 | 
					    boolean isAnySilentContainer(@NotNull Block block);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -16,10 +16,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Deprecated
 | 
				
			||||||
public interface IInventoryAccess {
 | 
					public interface IInventoryAccess {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -29,8 +30,8 @@ public interface IInventoryAccess {
 | 
				
			|||||||
     * @param inventory the Inventory
 | 
					     * @param inventory the Inventory
 | 
				
			||||||
     * @return the ISpecialEnderChest or null
 | 
					     * @return the ISpecialEnderChest or null
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nullable
 | 
					    @Deprecated
 | 
				
			||||||
    ISpecialEnderChest getSpecialEnderChest(Inventory inventory);
 | 
					    @Nullable ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
 | 
					     * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
 | 
				
			||||||
@@ -39,8 +40,8 @@ public interface IInventoryAccess {
 | 
				
			|||||||
     * @param inventory the Inventory
 | 
					     * @param inventory the Inventory
 | 
				
			||||||
     * @return the ISpecialPlayerInventory or null
 | 
					     * @return the ISpecialPlayerInventory or null
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nullable
 | 
					    @Deprecated
 | 
				
			||||||
    ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory);
 | 
					    @Nullable ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Check if an Inventory is an ISpecialEnderChest implementation.
 | 
					     * Check if an Inventory is an ISpecialEnderChest implementation.
 | 
				
			||||||
@@ -48,7 +49,8 @@ public interface IInventoryAccess {
 | 
				
			|||||||
     * @param inventory the Inventory
 | 
					     * @param inventory the Inventory
 | 
				
			||||||
     * @return true if the Inventory is backed by an ISpecialEnderChest
 | 
					     * @return true if the Inventory is backed by an ISpecialEnderChest
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    boolean isSpecialEnderChest(Inventory inventory);
 | 
					    @Deprecated
 | 
				
			||||||
 | 
					    boolean isSpecialEnderChest(@NotNull Inventory inventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Check if an Inventory is an ISpecialPlayerInventory implementation.
 | 
					     * Check if an Inventory is an ISpecialPlayerInventory implementation.
 | 
				
			||||||
@@ -56,6 +58,7 @@ public interface IInventoryAccess {
 | 
				
			|||||||
     * @param inventory the Inventory
 | 
					     * @param inventory the Inventory
 | 
				
			||||||
     * @return true if the Inventory is backed by an ISpecialPlayerInventory
 | 
					     * @return true if the Inventory is backed by an ISpecialPlayerInventory
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    boolean isSpecialPlayerInventory(Inventory inventory);
 | 
					    @Deprecated
 | 
				
			||||||
 | 
					    boolean isSpecialPlayerInventory(@NotNull Inventory inventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -16,35 +16,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					public interface ISpecialEnderChest extends ISpecialInventory {
 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets the Inventory associated with this ISpecialEnderChest.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return the Inventory
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    Inventory getBukkitInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Sets the Player associated with this ISpecialEnderChest online.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param player the Player coming online
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    void setPlayerOnline(Player player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Sets the Player associated with this ISpecialEnderChest offline.
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    void setPlayerOffline();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets whether or not this ISpecialEnderChest is in use.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return true if the ISpecialEnderChest is in use
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    boolean isInUse();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,51 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface ISpecialInventory {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the Inventory associated with this ISpecialInventory.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return the Inventory
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @NotNull Inventory getBukkitInventory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Sets the Player associated with this ISpecialInventory online.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param player the Player coming online
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    void setPlayerOnline(@NotNull Player player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Sets the Player associated with this ISpecialInventory offline.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    void setPlayerOffline();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets whether or not this ISpecialInventory is in use.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return true if the ISpecialInventory is in use
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    boolean isInUse();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -16,35 +16,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					public interface ISpecialPlayerInventory extends ISpecialInventory {
 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets the Inventory associated with this ISpecialPlayerInventory.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return the Inventory
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    Inventory getBukkitInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Sets the Player associated with this ISpecialPlayerInventory online.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param player the Player coming online
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    void setPlayerOnline(Player player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Sets the Player associated with this ISpecialPlayerInventory offline.
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    void setPlayerOffline();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets whether or not this ISpecialPlayerInventory is in use.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return true if the ISpecialPlayerInventory is in use
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    boolean isInUse();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										145
									
								
								api/src/main/java/com/lishid/openinv/util/InventoryAccess.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								api/src/main/java/com/lishid/openinv/util/InventoryAccess.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,145 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.IInventoryAccess;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
				
			||||||
 | 
					import java.lang.reflect.Field;
 | 
				
			||||||
 | 
					import java.lang.reflect.Method;
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class InventoryAccess implements IInventoryAccess {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static Class<?> craftInventory = null;
 | 
				
			||||||
 | 
					    private static Method getInventory = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static {
 | 
				
			||||||
 | 
					        String packageName = Bukkit.getServer().getClass().getPackage().getName();
 | 
				
			||||||
 | 
					        String version = packageName.substring(packageName.lastIndexOf('.') + 1);
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            craftInventory = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftInventory");
 | 
				
			||||||
 | 
					        } catch (ClassNotFoundException ignored) {}
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            getInventory = craftInventory.getDeclaredMethod("getInventory");
 | 
				
			||||||
 | 
					        } catch (NoSuchMethodException ignored) {}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean isUseable() {
 | 
				
			||||||
 | 
					        return craftInventory != null && getInventory != null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean isPlayerInventory(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        if (craftInventory.isAssignableFrom(inventory.getClass())) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                return getInventory.invoke(inventory) instanceof ISpecialPlayerInventory;
 | 
				
			||||||
 | 
					            } catch (ReflectiveOperationException ignored) {}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return grabFieldOfTypeFromObject(ISpecialPlayerInventory.class, inventory) != null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static ISpecialPlayerInventory getPlayerInventory(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        Object inv = null;
 | 
				
			||||||
 | 
					        if (craftInventory.isAssignableFrom(inventory.getClass())) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                inv = getInventory.invoke(inventory);
 | 
				
			||||||
 | 
					            } catch (ReflectiveOperationException ignored) {}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (inv == null) {
 | 
				
			||||||
 | 
					            inv = grabFieldOfTypeFromObject(ISpecialPlayerInventory.class, inventory);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (inv instanceof ISpecialPlayerInventory) {
 | 
				
			||||||
 | 
					            return (ISpecialPlayerInventory) inv;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean isEnderChest(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        if (craftInventory.isAssignableFrom(inventory.getClass())) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                return getInventory.invoke(inventory) instanceof ISpecialEnderChest;
 | 
				
			||||||
 | 
					            } catch (ReflectiveOperationException ignored) {}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return grabFieldOfTypeFromObject(ISpecialEnderChest.class, inventory) != null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static ISpecialEnderChest getEnderChest(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        Object inv = null;
 | 
				
			||||||
 | 
					        if (craftInventory.isAssignableFrom(inventory.getClass())) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                inv = getInventory.invoke(inventory);
 | 
				
			||||||
 | 
					            } catch (ReflectiveOperationException ignored) {}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (inv == null) {
 | 
				
			||||||
 | 
					            inv = grabFieldOfTypeFromObject(ISpecialEnderChest.class, inventory);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (inv instanceof ISpecialEnderChest) {
 | 
				
			||||||
 | 
					            return (ISpecialEnderChest) inv;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static <T> T grabFieldOfTypeFromObject(final Class<T> type, final Object object) {
 | 
				
			||||||
 | 
					        // Use reflection to find the IInventory
 | 
				
			||||||
 | 
					        Class<?> clazz = object.getClass();
 | 
				
			||||||
 | 
					        T result = null;
 | 
				
			||||||
 | 
					        for (Field f : clazz.getDeclaredFields()) {
 | 
				
			||||||
 | 
					            f.setAccessible(true);
 | 
				
			||||||
 | 
					            if (type.isAssignableFrom(f.getDeclaringClass())) {
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    result = type.cast(f.get(object));
 | 
				
			||||||
 | 
					                } catch (Exception e) {
 | 
				
			||||||
 | 
					                    e.printStackTrace();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return result;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Deprecated
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public @Nullable ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        return getEnderChest(inventory);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Deprecated
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public @Nullable ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        return getPlayerInventory(inventory);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Deprecated
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        return isEnderChest(inventory);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Deprecated
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
 | 
				
			||||||
 | 
					        return isPlayerInventory(inventory);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										150
									
								
								api/src/main/java/com/lishid/openinv/util/StringMetric.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										150
									
								
								api/src/main/java/com/lishid/openinv/util/StringMetric.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,150 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class StringMetric {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static float compareJaroWinkler(String a, String b) {
 | 
				
			||||||
 | 
					        final float jaroScore = compareJaro(a, b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (jaroScore < (float) 0.7) {
 | 
				
			||||||
 | 
					            return jaroScore;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String prefix = commonPrefix(a, b);
 | 
				
			||||||
 | 
					        int prefixLength = Math.min(prefix.codePointCount(0, prefix.length()), 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return jaroScore + (prefixLength * (float) 0.1 * (1.0f - jaroScore));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static float compareJaro(String a, String b) {
 | 
				
			||||||
 | 
					        if (a.isEmpty() && b.isEmpty()) {
 | 
				
			||||||
 | 
					            return 1.0f;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (a.isEmpty() || b.isEmpty()) {
 | 
				
			||||||
 | 
					            return 0.0f;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final int[] charsA = a.codePoints().toArray();
 | 
				
			||||||
 | 
					        final int[] charsB = b.codePoints().toArray();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Intentional integer division to round down.
 | 
				
			||||||
 | 
					        final int halfLength = Math.max(0, Math.max(charsA.length, charsB.length) / 2 - 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final int[] commonA = getCommonCodePoints(charsA, charsB, halfLength);
 | 
				
			||||||
 | 
					        final int[] commonB = getCommonCodePoints(charsB, charsA, halfLength);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // commonA and commonB will always contain the same multi-set of
 | 
				
			||||||
 | 
					        // characters. Because getCommonCharacters has been optimized, commonA
 | 
				
			||||||
 | 
					        // and commonB are -1-padded. So in this loop we count transposition
 | 
				
			||||||
 | 
					        // and use commonCharacters to determine the length of the multi-set.
 | 
				
			||||||
 | 
					        float transpositions = 0;
 | 
				
			||||||
 | 
					        int commonCharacters = 0;
 | 
				
			||||||
 | 
					        for (int length = commonA.length; commonCharacters < length
 | 
				
			||||||
 | 
					                && commonA[commonCharacters] > -1; commonCharacters++) {
 | 
				
			||||||
 | 
					            if (commonA[commonCharacters] != commonB[commonCharacters]) {
 | 
				
			||||||
 | 
					                transpositions++;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (commonCharacters == 0) {
 | 
				
			||||||
 | 
					            return 0.0f;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        float aCommonRatio = commonCharacters / (float) charsA.length;
 | 
				
			||||||
 | 
					        float bCommonRatio = commonCharacters / (float) charsB.length;
 | 
				
			||||||
 | 
					        float transpositionRatio = (commonCharacters - transpositions / 2.0f) / commonCharacters;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return (aCommonRatio + bCommonRatio + transpositionRatio) / 3.0f;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
 | 
					     * Returns an array of code points from a within b. A character in b is
 | 
				
			||||||
 | 
					     * counted as common when it is within separation distance from the position
 | 
				
			||||||
 | 
					     * in a.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static int[] getCommonCodePoints(final int[] charsA, final int[] charsB, final int separation) {
 | 
				
			||||||
 | 
					        final int[] common = new int[Math.min(charsA.length, charsB.length)];
 | 
				
			||||||
 | 
					        final boolean[] matched = new boolean[charsB.length];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Iterate of string a and find all characters that occur in b within
 | 
				
			||||||
 | 
					        // the separation distance. Mark any matches found to avoid
 | 
				
			||||||
 | 
					        // duplicate matchings.
 | 
				
			||||||
 | 
					        int commonIndex = 0;
 | 
				
			||||||
 | 
					        for (int i = 0, length = charsA.length; i < length; i++) {
 | 
				
			||||||
 | 
					            final int character = charsA[i];
 | 
				
			||||||
 | 
					            final int index = indexOf(character, charsB, i - separation, i
 | 
				
			||||||
 | 
					                    + separation + 1, matched);
 | 
				
			||||||
 | 
					            if (index > -1) {
 | 
				
			||||||
 | 
					                common[commonIndex++] = character;
 | 
				
			||||||
 | 
					                matched[index] = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (commonIndex < common.length) {
 | 
				
			||||||
 | 
					            common[commonIndex] = -1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Both invocations will yield the same multi-set terminated by -1, so
 | 
				
			||||||
 | 
					        // they can be compared for transposition without making a copy.
 | 
				
			||||||
 | 
					        return common;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
 | 
					     * Search for code point in buffer starting at fromIndex to toIndex - 1.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * Returns -1 when not found.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static int indexOf(int character, int[] buffer, int fromIndex, int toIndex, boolean[] matched) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // compare char with range of characters to either side
 | 
				
			||||||
 | 
					        for (int j = Math.max(0, fromIndex), length = Math.min(toIndex, buffer.length); j < length; j++) {
 | 
				
			||||||
 | 
					            // check if found
 | 
				
			||||||
 | 
					            if (buffer[j] == character && !matched[j]) {
 | 
				
			||||||
 | 
					                return j;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static String commonPrefix(CharSequence a, CharSequence b) {
 | 
				
			||||||
 | 
					        int maxPrefixLength = Math.min(a.length(), b.length());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        p = 0;
 | 
				
			||||||
 | 
					        while (p < maxPrefixLength && a.charAt(p) == b.charAt(p)) {
 | 
				
			||||||
 | 
					            ++p;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (validSurrogatePairAt(a, p - 1) || validSurrogatePairAt(b, p - 1)) {
 | 
				
			||||||
 | 
					            --p;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return a.subSequence(0, p).toString();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static boolean validSurrogatePairAt(CharSequence string, int index) {
 | 
				
			||||||
 | 
					        return index >= 0 && index <= string.length() - 2 && Character.isHighSurrogate(string.charAt(index)) && Character.isLowSurrogate(string.charAt(index + 1));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private StringMetric(){}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					  ~ Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
  ~
 | 
					  ~
 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					  ~ 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
 | 
					  ~ it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -21,7 +21,7 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvparent</artifactId>
 | 
					    <artifactId>openinvparent</artifactId>
 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvassembly</artifactId>
 | 
					  <artifactId>openinvassembly</artifactId>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					  ~ Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
  ~
 | 
					  ~
 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					  ~ 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
 | 
					  ~ it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					  ~ Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
  ~
 | 
					  ~
 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					  ~ 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
 | 
					  ~ it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -21,25 +21,54 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvparent</artifactId>
 | 
					    <artifactId>openinvparent</artifactId>
 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvcommon</artifactId>
 | 
					  <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
  <name>OpenInvCommon</name>
 | 
					  <name>OpenInvCommon</name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <dependencies>
 | 
					  <dependencies>
 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>bukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.4.5-R1.0</version>
 | 
					 | 
				
			||||||
      <scope>system</scope>
 | 
					 | 
				
			||||||
      <systemPath>${project.basedir}/../lib/bukkit-1.4.5-R1.0.jar</systemPath>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					      <groupId>com.lishid</groupId>
 | 
				
			||||||
      <artifactId>openinvapi</artifactId>
 | 
					      <artifactId>openinvapi</artifactId>
 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					      <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
 | 
					    </dependency>
 | 
				
			||||||
 | 
					    <dependency>
 | 
				
			||||||
 | 
					      <groupId>org.spigotmc</groupId>
 | 
				
			||||||
 | 
					      <artifactId>spigot-api</artifactId>
 | 
				
			||||||
 | 
					      <version>1.8.8-R0.1-SNAPSHOT</version>
 | 
				
			||||||
 | 
					      <scope>provided</scope>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <build>
 | 
				
			||||||
 | 
					    <plugins>
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					        <executions>
 | 
				
			||||||
 | 
					          <execution>
 | 
				
			||||||
 | 
					            <phase>package</phase>
 | 
				
			||||||
 | 
					            <goals>
 | 
				
			||||||
 | 
					              <goal>shade</goal>
 | 
				
			||||||
 | 
					            </goals>
 | 
				
			||||||
 | 
					          </execution>
 | 
				
			||||||
 | 
					        </executions>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <artifactId>maven-compiler-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>3.8.1</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <source>1.8</source>
 | 
				
			||||||
 | 
					          <target>1.8</target>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					    </plugins>
 | 
				
			||||||
 | 
					  </build>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</project>
 | 
					</project>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -16,10 +16,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public interface IPlayerDataManager {
 | 
					public interface IPlayerDataManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,29 +32,16 @@ public interface IPlayerDataManager {
 | 
				
			|||||||
     * @param offline the OfflinePlayer
 | 
					     * @param offline the OfflinePlayer
 | 
				
			||||||
     * @return the Player loaded
 | 
					     * @return the Player loaded
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
	Player loadPlayer(OfflinePlayer offline);
 | 
					    @Nullable Player loadPlayer(@NotNull OfflinePlayer offline);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets a unique identifying string for an OfflinePlayer.
 | 
					     * Opens an ISpecialInventory for a Player.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param offline the OfflinePlayer
 | 
					     * @param player the Player opening the ISpecialInventory
 | 
				
			||||||
     * @return the unique identifier
 | 
					     * @param inventory the Inventory
 | 
				
			||||||
 | 
					     *`
 | 
				
			||||||
 | 
					     * @return the InventoryView opened
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
	String getPlayerDataID(OfflinePlayer offline);
 | 
					    InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets an OfflinePlayer by the given unique identifier.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param identifier the unique identifier
 | 
					 | 
				
			||||||
     * @return the OfflinePlayer, or null if no exact match was found
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
	OfflinePlayer getPlayerByID(String identifier);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Gets a Collection of all Players currently online.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return the Collection of Players
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
	Collection<? extends Player> getOnlinePlayers();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -16,15 +16,14 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.util;
 | 
					package com.lishid.openinv.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.collect.Multimap;
 | 
				
			||||||
 | 
					import com.google.common.collect.TreeMultimap;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.Comparator;
 | 
					 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
import com.google.common.collect.Multimap;
 | 
					 | 
				
			||||||
import com.google.common.collect.TreeMultimap;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * A minimal thread-safe time-based cache implementation backed by a HashMap and TreeMultimap.
 | 
					 * A minimal thread-safe time-based cache implementation backed by a HashMap and TreeMultimap.
 | 
				
			||||||
@@ -46,20 +45,9 @@ public class Cache<K, V> {
 | 
				
			|||||||
     * @param postRemoval Function used to perform any operations required when a key is invalidated
 | 
					     * @param postRemoval Function used to perform any operations required when a key is invalidated
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public Cache(final long retention, final Function<V> inUseCheck, final Function<V> postRemoval) {
 | 
					    public Cache(final long retention, final Function<V> inUseCheck, final Function<V> postRemoval) {
 | 
				
			||||||
        this.internal = new HashMap<K, V>();
 | 
					        this.internal = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.expiry = TreeMultimap.create(new Comparator<Long>() {
 | 
					        this.expiry = TreeMultimap.create(Long::compareTo, (k1, k2) -> Objects.equals(k1, k2) ? 0 : 1);
 | 
				
			||||||
                    @Override
 | 
					 | 
				
			||||||
                    public int compare(final Long long1, final Long long2) {
 | 
					 | 
				
			||||||
                        return long1.compareTo(long2);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                new Comparator<K>() {
 | 
					 | 
				
			||||||
                    @Override
 | 
					 | 
				
			||||||
                    public int compare(final K k1, final K k2) {
 | 
					 | 
				
			||||||
                        return k1 == k2 || k1 != null && k1.equals(k2) ? 0 : 1;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.retention = retention;
 | 
					        this.retention = retention;
 | 
				
			||||||
        this.inUseCheck = inUseCheck;
 | 
					        this.inUseCheck = inUseCheck;
 | 
				
			||||||
@@ -161,7 +149,7 @@ public class Cache<K, V> {
 | 
				
			|||||||
    private void lazyCheck() {
 | 
					    private void lazyCheck() {
 | 
				
			||||||
        long now = System.currentTimeMillis();
 | 
					        long now = System.currentTimeMillis();
 | 
				
			||||||
        synchronized (this.internal) {
 | 
					        synchronized (this.internal) {
 | 
				
			||||||
            List<K> inUse = new ArrayList<K>();
 | 
					            List<K> inUse = new ArrayList<>();
 | 
				
			||||||
            for (Iterator<Map.Entry<Long, K>> iterator = this.expiry.entries().iterator(); iterator
 | 
					            for (Iterator<Map.Entry<Long, K>> iterator = this.expiry.entries().iterator(); iterator
 | 
				
			||||||
                    .hasNext();) {
 | 
					                    .hasNext();) {
 | 
				
			||||||
                Map.Entry<Long, K> entry = iterator.next();
 | 
					                Map.Entry<Long, K> entry = iterator.next();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -16,44 +16,21 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.util;
 | 
					package com.lishid.openinv.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.lang.reflect.Constructor;
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.lang.reflect.InvocationTargetException;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					import com.lishid.openinv.internal.IAnySilentContainer;
 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					import com.lishid.openinv.internal.IPlayerDataManager;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
				
			||||||
 | 
					import java.lang.reflect.Constructor;
 | 
				
			||||||
 | 
					import java.lang.reflect.InvocationTargetException;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.plugin.Plugin;
 | 
					import org.bukkit.plugin.Plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class InternalAccessor {
 | 
					public class InternalAccessor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static <T> T grabFieldOfTypeFromObject(final Class<T> type, final Object object) {
 | 
					 | 
				
			||||||
        // Use reflection to find the IInventory
 | 
					 | 
				
			||||||
        Class<?> clazz = object.getClass();
 | 
					 | 
				
			||||||
        T result = null;
 | 
					 | 
				
			||||||
        for (Field f : clazz.getDeclaredFields()) {
 | 
					 | 
				
			||||||
            f.setAccessible(true);
 | 
					 | 
				
			||||||
            if (type.isAssignableFrom(f.getDeclaringClass())) {
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    result = type.cast(f.get(object));
 | 
					 | 
				
			||||||
                } catch (Exception e) {
 | 
					 | 
				
			||||||
                    e.printStackTrace();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return result;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final Plugin plugin;
 | 
					    private final Plugin plugin;
 | 
				
			||||||
    private final String version;
 | 
					    private final String version;
 | 
				
			||||||
    private boolean supported = false;
 | 
					    private boolean supported = false;
 | 
				
			||||||
    private IPlayerDataManager playerDataManager;
 | 
					    private IPlayerDataManager playerDataManager;
 | 
				
			||||||
    private IInventoryAccess inventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private IAnySilentContainer anySilentContainer;
 | 
					    private IAnySilentContainer anySilentContainer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public InternalAccessor(final Plugin plugin) {
 | 
					    public InternalAccessor(final Plugin plugin) {
 | 
				
			||||||
@@ -63,13 +40,13 @@ public class InternalAccessor {
 | 
				
			|||||||
        this.version = packageName.substring(packageName.lastIndexOf('.') + 1);
 | 
					        this.version = packageName.substring(packageName.lastIndexOf('.') + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            // TODO: implement support for CraftMagicNumbers#getMappingsVersion
 | 
				
			||||||
            Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialPlayerInventory");
 | 
					            Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialPlayerInventory");
 | 
				
			||||||
            Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest");
 | 
					            Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest");
 | 
				
			||||||
            this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager");
 | 
					            this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager");
 | 
				
			||||||
            this.inventoryAccess = this.createObject(IInventoryAccess.class, "InventoryAccess");
 | 
					 | 
				
			||||||
            this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer");
 | 
					            this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer");
 | 
				
			||||||
            this.supported = true;
 | 
					            this.supported = InventoryAccess.isUseable();
 | 
				
			||||||
        } catch (Exception e) {}
 | 
					        } catch (Exception ignored) {}
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private <T> T createObject(final Class<? extends T> assignableClass, final String className,
 | 
					    private <T> T createObject(final Class<? extends T> assignableClass, final String className,
 | 
				
			||||||
@@ -129,19 +106,6 @@ public class InternalAccessor {
 | 
				
			|||||||
        return this.anySilentContainer;
 | 
					        return this.anySilentContainer;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Creates an instance of the IInventoryAccess implementation for the current server version.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return the IInventoryAccess
 | 
					 | 
				
			||||||
     * @throws IllegalStateException if server version is unsupported
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public IInventoryAccess getInventoryAccess() {
 | 
					 | 
				
			||||||
        if (!this.supported) {
 | 
					 | 
				
			||||||
            throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return this.inventoryAccess;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Creates an instance of the IPlayerDataManager implementation for the current server version.
 | 
					     * Creates an instance of the IPlayerDataManager implementation for the current server version.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										53
									
								
								common/src/main/java/com/lishid/openinv/util/Pair.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								common/src/main/java/com/lishid/openinv/util/Pair.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Simple tuple.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param <L> the left value
 | 
				
			||||||
 | 
					 * @param <R> the right value
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Jikoo
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class Pair<L, R> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private L left;
 | 
				
			||||||
 | 
					    private R right;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Pair(L left, R right) {
 | 
				
			||||||
 | 
					        this.left = left;
 | 
				
			||||||
 | 
					        this.right = right;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public L getLeft() {
 | 
				
			||||||
 | 
					        return left;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setLeft(L left) {
 | 
				
			||||||
 | 
					        this.left = left;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public R getRight() {
 | 
				
			||||||
 | 
					        return right;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setRight(R right) {
 | 
				
			||||||
 | 
					        this.right = right;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,201 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.AbstractCollection;
 | 
				
			||||||
 | 
					import java.util.Collection;
 | 
				
			||||||
 | 
					import java.util.Iterator;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.ListIterator;
 | 
				
			||||||
 | 
					import java.util.NoSuchElementException;
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					import java.util.function.Consumer;
 | 
				
			||||||
 | 
					import java.util.function.Supplier;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A List implementation intended for wrapping a single field.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param <V> the type of the field
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Jikoo
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class SingleFieldList<V> extends AbstractCollection<V> implements List<V> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final Supplier<V> fieldGetter;
 | 
				
			||||||
 | 
					    private final Consumer<V> fieldSetter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SingleFieldList(@NotNull Supplier<V> fieldGetter, @NotNull Consumer<V> fieldSetter) {
 | 
				
			||||||
 | 
					        this.fieldGetter = fieldGetter;
 | 
				
			||||||
 | 
					        this.fieldSetter = fieldSetter;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int size() {
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean contains(Object o) {
 | 
				
			||||||
 | 
					        return Objects.equals(o, fieldGetter.get());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NotNull
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Iterator<V> iterator() {
 | 
				
			||||||
 | 
					        return listIterator();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean addAll(int index, @NotNull Collection<? extends V> c) {
 | 
				
			||||||
 | 
					        return super.addAll(c);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean equals(Object o) {
 | 
				
			||||||
 | 
					        return o instanceof SingleFieldList
 | 
				
			||||||
 | 
					                && fieldGetter.equals(((SingleFieldList) o).fieldGetter)
 | 
				
			||||||
 | 
					                && fieldSetter.equals(((SingleFieldList) o).fieldSetter);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int hashCode() {
 | 
				
			||||||
 | 
					        return fieldSetter.hashCode() * 17 * fieldGetter.hashCode();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public V get(int index) {
 | 
				
			||||||
 | 
					        if (index != 0) {
 | 
				
			||||||
 | 
					            throw new IndexOutOfBoundsException();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return fieldGetter.get();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public V set(int index, V element) {
 | 
				
			||||||
 | 
					        if (index != 0) {
 | 
				
			||||||
 | 
					            throw new IndexOutOfBoundsException();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        V old = fieldGetter.get();
 | 
				
			||||||
 | 
					        fieldSetter.accept(element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return old;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void add(int index, V element) {
 | 
				
			||||||
 | 
					        throw new UnsupportedOperationException();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public V remove(int index) {
 | 
				
			||||||
 | 
					        throw new UnsupportedOperationException();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int indexOf(Object o) {
 | 
				
			||||||
 | 
					        return fieldGetter.get().equals(o) ? 0 : -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int lastIndexOf(Object o) {
 | 
				
			||||||
 | 
					        return indexOf(o);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NotNull
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ListIterator<V> listIterator() {
 | 
				
			||||||
 | 
					        return new ListIterator<V>() {
 | 
				
			||||||
 | 
					            private boolean hasNext = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public boolean hasNext() {
 | 
				
			||||||
 | 
					                return hasNext;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public V next() {
 | 
				
			||||||
 | 
					                if (!hasNext) {
 | 
				
			||||||
 | 
					                    throw new NoSuchElementException();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return fieldGetter.get();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public boolean hasPrevious() {
 | 
				
			||||||
 | 
					                return !hasNext;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public V previous() {
 | 
				
			||||||
 | 
					                if (hasNext) {
 | 
				
			||||||
 | 
					                    throw new NoSuchElementException();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return fieldGetter.get();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public int nextIndex() {
 | 
				
			||||||
 | 
					                return hasNext ? 0 : 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public int previousIndex() {
 | 
				
			||||||
 | 
					                return hasNext ? -1 : 0;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void remove() {
 | 
				
			||||||
 | 
					                throw new UnsupportedOperationException();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void set(V v) {
 | 
				
			||||||
 | 
					                fieldSetter.accept(v);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void add(V v) {
 | 
				
			||||||
 | 
					                throw new UnsupportedOperationException();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NotNull
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ListIterator<V> listIterator(int index) {
 | 
				
			||||||
 | 
					        if (index != 0) {
 | 
				
			||||||
 | 
					            throw new IndexOutOfBoundsException();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return listIterator();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NotNull
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<V> subList(int fromIndex, int toIndex) {
 | 
				
			||||||
 | 
					        if (fromIndex != 0 || toIndex != 1) {
 | 
				
			||||||
 | 
					            throw new IndexOutOfBoundsException();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void clear() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_4_5</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_4_5</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>craftbukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.4.5-R1.0</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,171 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.Container;
 | 
					 | 
				
			||||||
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.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.event.CraftEventFactory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block or ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
					 | 
				
			||||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
					 | 
				
			||||||
        return world.t(x, y + 1, z) || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof IInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IInventory inventory = (IInventory) tile;
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer(inventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Call InventoryOpenEvent
 | 
					 | 
				
			||||||
            Container container = new SilentContainerChest(player.inventory, inventory);
 | 
					 | 
				
			||||||
            container = CraftEventFactory.callInventoryOpenEvent(player, container);
 | 
					 | 
				
			||||||
            if (container == null) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Open window
 | 
					 | 
				
			||||||
            int windowId = player.nextContainerCounter();
 | 
					 | 
				
			||||||
            player.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize()));
 | 
					 | 
				
			||||||
            player.activeContainer = container;
 | 
					 | 
				
			||||||
            player.activeContainer.windowId = windowId;
 | 
					 | 
				
			||||||
            player.activeContainer.addSlotListener(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            p.sendMessage(ChatColor.RED + "Error while sending silent container.");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,101 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.ItemInWorldManager;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.MinecraftServer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create an entity to load the player data
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
					 | 
				
			||||||
                new ItemInWorldManager(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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
 | 
					 | 
				
			||||||
        // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
        if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Arrays.asList(Bukkit.getOnlinePlayers());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        // Send close signal
 | 
					 | 
				
			||||||
        i2.f();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman entityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (playerinventory.getCarried() != null) {
 | 
					 | 
				
			||||||
            ItemStack carried = playerinventory.getCarried();
 | 
					 | 
				
			||||||
            playerinventory.setCarried(null);
 | 
					 | 
				
			||||||
            entityHuman.drop(carried);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,130 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 net.minecraft.server.v1_4_5.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
    private CraftPlayer owner;
 | 
					 | 
				
			||||||
    private int maxStack = MAX_STACK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
					 | 
				
			||||||
                field.setAccessible(true);
 | 
					 | 
				
			||||||
                field.set(playerEnderChest, this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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 void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,235 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.player.inventory.items = this.items;
 | 
					 | 
				
			||||||
            this.player.inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        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
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            player.drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        player.defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_4_6</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_4_6</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>craftbukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.4.6-R0.3</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,171 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.Container;
 | 
					 | 
				
			||||||
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.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.event.CraftEventFactory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block or ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
					 | 
				
			||||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
					 | 
				
			||||||
        return world.t(x, y + 1, z) || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof IInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IInventory inventory = (IInventory) tile;
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer(inventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Call InventoryOpenEvent
 | 
					 | 
				
			||||||
            Container container = new SilentContainerChest(player.inventory, inventory);
 | 
					 | 
				
			||||||
            container = CraftEventFactory.callInventoryOpenEvent(player, container);
 | 
					 | 
				
			||||||
            if (container == null) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Open window
 | 
					 | 
				
			||||||
            int windowId = player.nextContainerCounter();
 | 
					 | 
				
			||||||
            player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize()));
 | 
					 | 
				
			||||||
            player.activeContainer = container;
 | 
					 | 
				
			||||||
            player.activeContainer.windowId = windowId;
 | 
					 | 
				
			||||||
            player.activeContainer.addSlotListener(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            p.sendMessage(ChatColor.RED + "Error while sending silent container.");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,101 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create an entity to load the player data
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
					 | 
				
			||||||
                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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
 | 
					 | 
				
			||||||
        // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
        if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Arrays.asList(Bukkit.getOnlinePlayers());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        // Send close signal
 | 
					 | 
				
			||||||
        i2.f();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman entityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (playerinventory.getCarried() != null) {
 | 
					 | 
				
			||||||
            ItemStack carried = playerinventory.getCarried();
 | 
					 | 
				
			||||||
            playerinventory.setCarried(null);
 | 
					 | 
				
			||||||
            entityHuman.drop(carried);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,130 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 net.minecraft.server.v1_4_6.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
    private CraftPlayer owner;
 | 
					 | 
				
			||||||
    private int maxStack = MAX_STACK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
					 | 
				
			||||||
                field.setAccessible(true);
 | 
					 | 
				
			||||||
                field.set(playerEnderChest, this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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 void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,227 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.player.inventory.items = this.items;
 | 
					 | 
				
			||||||
            this.player.inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        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
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            player.drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        player.defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					  ~ Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
  ~
 | 
					  ~
 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					  ~ 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
 | 
					  ~ it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvparent</artifactId>
 | 
					    <artifactId>openinvparent</artifactId>
 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvinternal</artifactId>
 | 
					  <artifactId>openinvinternal</artifactId>
 | 
				
			||||||
@@ -30,48 +30,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  <profiles>
 | 
					  <profiles>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <profile>
 | 
					 | 
				
			||||||
      <id>latest</id>
 | 
					 | 
				
			||||||
      <modules>
 | 
					 | 
				
			||||||
        <module>v1_12_R1</module>
 | 
					 | 
				
			||||||
      </modules>
 | 
					 | 
				
			||||||
    </profile>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <profile>
 | 
					 | 
				
			||||||
      <id>recent</id>
 | 
					 | 
				
			||||||
      <!-- The recent profile is for the most recent 2 versions. -->
 | 
					 | 
				
			||||||
      <modules>
 | 
					 | 
				
			||||||
        <module>v1_12_R1</module>
 | 
					 | 
				
			||||||
        <module>v1_13_R1</module>
 | 
					 | 
				
			||||||
      </modules>
 | 
					 | 
				
			||||||
    </profile>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <profile>
 | 
					    <profile>
 | 
				
			||||||
      <id>all</id>
 | 
					      <id>all</id>
 | 
				
			||||||
      <modules>
 | 
					      <modules>
 | 
				
			||||||
        <module>1_4_5</module>
 | 
					 | 
				
			||||||
        <module>1_4_6</module>
 | 
					 | 
				
			||||||
        <module>v1_4_R1</module>
 | 
					 | 
				
			||||||
        <!-- 1_5_R1 was never released -->
 | 
					 | 
				
			||||||
        <module>v1_5_R2</module>
 | 
					 | 
				
			||||||
        <module>v1_5_R3</module>
 | 
					 | 
				
			||||||
        <!-- 1_6_R1 also had no tagged releases, remove? -->
 | 
					 | 
				
			||||||
        <module>v1_6_R1</module>
 | 
					 | 
				
			||||||
        <module>v1_6_R2</module>
 | 
					 | 
				
			||||||
        <module>v1_6_R3</module>
 | 
					 | 
				
			||||||
        <module>v1_7_R1</module>
 | 
					 | 
				
			||||||
        <module>v1_7_R2</module>
 | 
					 | 
				
			||||||
        <module>v1_7_R3</module>
 | 
					 | 
				
			||||||
        <module>v1_7_R4</module>
 | 
					 | 
				
			||||||
        <module>v1_8_R1</module>
 | 
					 | 
				
			||||||
        <module>v1_8_R2</module>
 | 
					 | 
				
			||||||
        <module>v1_8_R3</module>
 | 
					        <module>v1_8_R3</module>
 | 
				
			||||||
        <module>v1_9_R1</module>
 | 
					        <module>v1_13_R2</module>
 | 
				
			||||||
        <module>v1_9_R2</module>
 | 
					        <module>v1_14_R1</module>
 | 
				
			||||||
        <module>v1_10_R1</module>
 | 
					 | 
				
			||||||
        <module>v1_11_R1</module>
 | 
					 | 
				
			||||||
        <module>v1_12_R1</module>
 | 
					 | 
				
			||||||
        <module>v1_13_R1</module>
 | 
					 | 
				
			||||||
      </modules>
 | 
					      </modules>
 | 
				
			||||||
    </profile>
 | 
					    </profile>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_10_R1</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_10_R1</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.spigotmc</groupId>
 | 
					 | 
				
			||||||
      <artifactId>spigot</artifactId>
 | 
					 | 
				
			||||||
      <version>1.10-R0.1-SNAPSHOT</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,250 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_10_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryView;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.Block;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.BlockChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.BlockPosition;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.Entity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.EntityOcelot;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.EnumDirection;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.EnumGamemode;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.ITileInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.StatisticList;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.TileEntity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private Field playerInteractManagerGamemode;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public AnySilentContainer() {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode.setAccessible(true);
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
					 | 
				
			||||||
        Block block = world.getType(blockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.getType(blockPosition.up()).m();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check if chest is blocked or has an ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(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);
 | 
					 | 
				
			||||||
            Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (localBlock != block) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					 | 
				
			||||||
            if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (isBlockedChest(world, localBlockPosition)) {
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, BlockPosition blockPosition) {
 | 
					 | 
				
			||||||
        // For reference, loot at net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        return world.getType(blockPosition.up()).l() || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is pretty much API-only
 | 
					 | 
				
			||||||
        if (silentchest && b.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            player.b(StatisticList.X);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(blockPosition);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            player.b(StatisticList.X);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof ITileInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ITileInventory tileInventory = (ITileInventory) tile;
 | 
					 | 
				
			||||||
        Block block = world.getType(blockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockChest) {
 | 
					 | 
				
			||||||
            for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
					 | 
				
			||||||
                BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
					 | 
				
			||||||
                Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (localBlock != block) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					 | 
				
			||||||
                if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) {
 | 
					 | 
				
			||||||
                    tileInventory = new InventoryLargeChest("container.chestDouble",
 | 
					 | 
				
			||||||
                            (TileEntityChest) localTileEntity, tileInventory);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    tileInventory = new InventoryLargeChest("container.chestDouble",
 | 
					 | 
				
			||||||
                            tileInventory, (TileEntityChest) localTileEntity);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            BlockChest blockChest = (BlockChest) block;
 | 
					 | 
				
			||||||
            if (blockChest.g == BlockChest.Type.BASIC) {
 | 
					 | 
				
			||||||
                player.b(StatisticList.ac);
 | 
					 | 
				
			||||||
            } else if (blockChest.g == BlockChest.Type.TRAP) {
 | 
					 | 
				
			||||||
                player.b(StatisticList.W);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
 | 
					 | 
				
			||||||
        if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
 | 
					 | 
				
			||||||
            player.openContainer(tileInventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest requires access to setting players' gamemode directly.
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					 | 
				
			||||||
        player.openContainer(tileInventory);
 | 
					 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        InventoryView view = bukkitPlayer.getOpenInventory();
 | 
					 | 
				
			||||||
        switch (view.getType()) {
 | 
					 | 
				
			||||||
            case CHEST:
 | 
					 | 
				
			||||||
            case ENDER_CHEST:
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            default:
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					 | 
				
			||||||
        player.activeContainer.b(player);
 | 
					 | 
				
			||||||
        player.activeContainer = player.defaultContainer;
 | 
					 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            // No need to warn repeatedly, error on startup and lack of function should be enough.
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            if (!this.playerInteractManagerGamemode.isAccessible()) {
 | 
					 | 
				
			||||||
                // Just in case, ensure accessible.
 | 
					 | 
				
			||||||
                this.playerInteractManagerGamemode.setAccessible(true);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_10_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,109 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_10_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
import java.util.UUID;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create a profile and entity to load the player data
 | 
					 | 
				
			||||||
        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getUniqueId().toString();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            UUID uuid = UUID.fromString(identifier);
 | 
					 | 
				
			||||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
					 | 
				
			||||||
            // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
            if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return player;
 | 
					 | 
				
			||||||
        } catch (IllegalArgumentException e) {
 | 
					 | 
				
			||||||
            // Not a UUID
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Bukkit.getOnlinePlayers();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,105 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_10_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.lang.reflect.Modifier;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
 | 
					 | 
				
			||||||
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.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.bukkitOwner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        setItemArrays(this, enderChest.getContents());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void setItemArrays(InventorySubcontainer subcontainer, ItemStack[] items) {
 | 
					 | 
				
			||||||
        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, items);
 | 
					 | 
				
			||||||
        } 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 {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.bukkitOwner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                setItemArrays(nmsPlayer.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();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,299 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_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 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.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final ItemStack[] extra = new ItemStack[4];
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void setItemArrays(PlayerInventory inventory, ItemStack[] items, ItemStack[] armor,
 | 
					 | 
				
			||||||
            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, new ItemStack[][] { 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 = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            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 ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        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() + 4;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // extraSlots is, for now, just an array with length 1. No need for special handling.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                itemstack = is[i].cloneAndSubtract(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            player.drop(itemstack, true);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        player.defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean hasCustomName() {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_11_R1</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_11_R1</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.spigotmc</groupId>
 | 
					 | 
				
			||||||
      <artifactId>spigot</artifactId>
 | 
					 | 
				
			||||||
      <version>1.11.2-R0.1-SNAPSHOT</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,295 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.block.BlockState;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryView;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.BlockPosition;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
 | 
					 | 
				
			||||||
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.ITileInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
 | 
					 | 
				
			||||||
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.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.World;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.EnumGamemode;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private Field playerInteractManagerGamemode;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public AnySilentContainer() {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode.setAccessible(true);
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        if (block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        BlockState state = block.getState();
 | 
					 | 
				
			||||||
        return state instanceof org.bukkit.block.Chest || state instanceof org.bukkit.block.ShulkerBox;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
					 | 
				
			||||||
        IBlockData blockData = world.getType(blockPosition);
 | 
					 | 
				
			||||||
        Block block = blockData.getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockShulkerBox) {
 | 
					 | 
				
			||||||
            return isBlockedShulkerBox(world, blockPosition, blockData);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.getType(blockPosition.up()).m();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check if chest is blocked or has an ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(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);
 | 
					 | 
				
			||||||
            Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (localBlock != block) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					 | 
				
			||||||
            if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (isBlockedChest(world, localBlockPosition)) {
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedShulkerBox(World world, BlockPosition blockPosition, IBlockData blockData) {
 | 
					 | 
				
			||||||
        // For reference, look at net.minecraft.server.BlockShulkerBox
 | 
					 | 
				
			||||||
        TileEntity tile = world.getTileEntity(blockPosition);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof TileEntityShulkerBox)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumDirection enumDirection = blockData.get(BlockShulkerBox.a);
 | 
					 | 
				
			||||||
        if (((TileEntityShulkerBox) tile).p() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
 | 
					 | 
				
			||||||
            AxisAlignedBB axisAlignedBB = Block.j.b(0.5F * enumDirection.getAdjacentX(),
 | 
					 | 
				
			||||||
                    0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
 | 
					 | 
				
			||||||
                    .a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
 | 
					 | 
				
			||||||
                            enumDirection.getAdjacentZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                // 1.11.2
 | 
					 | 
				
			||||||
                return world.a(axisAlignedBB.a(blockPosition.shift(enumDirection)));
 | 
					 | 
				
			||||||
            } catch (NoSuchMethodError e) {
 | 
					 | 
				
			||||||
                // 1.11
 | 
					 | 
				
			||||||
                return world.b(axisAlignedBB.a(blockPosition.shift(enumDirection)));
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, BlockPosition blockPosition) {
 | 
					 | 
				
			||||||
        // For reference, loot at net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        return world.getType(blockPosition.up()).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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is pretty much API-only
 | 
					 | 
				
			||||||
        if (silentchest && b.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            player.b(StatisticList.getStatistic("stat.enderchestOpened"));
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        final World world = player.world;
 | 
					 | 
				
			||||||
        final BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
					 | 
				
			||||||
        final Object tile = world.getTileEntity(blockPosition);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest.  See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            player.b(StatisticList.getStatistic("stat.enderchestOpened"));
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof ITileInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ITileInventory tileInventory = (ITileInventory) tile;
 | 
					 | 
				
			||||||
        Block block = world.getType(blockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockChest) {
 | 
					 | 
				
			||||||
            for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
					 | 
				
			||||||
                BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
					 | 
				
			||||||
                Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (localBlock != block) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					 | 
				
			||||||
                if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) {
 | 
					 | 
				
			||||||
                    tileInventory = new InventoryLargeChest("container.chestDouble",
 | 
					 | 
				
			||||||
                            (TileEntityChest) localTileEntity, tileInventory);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    tileInventory = new InventoryLargeChest("container.chestDouble",
 | 
					 | 
				
			||||||
                            tileInventory, (TileEntityChest) localTileEntity);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            BlockChest blockChest = (BlockChest) block;
 | 
					 | 
				
			||||||
            if (blockChest.g == BlockChest.Type.BASIC) {
 | 
					 | 
				
			||||||
                player.b(StatisticList.getStatistic("stat.chestOpened"));
 | 
					 | 
				
			||||||
            } else if (blockChest.g == BlockChest.Type.TRAP) {
 | 
					 | 
				
			||||||
                player.b(StatisticList.getStatistic("stat.trappedChestTriggered"));
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockShulkerBox) {
 | 
					 | 
				
			||||||
            player.b(StatisticList.getStatistic("stat.shulkerBoxOpened"));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
 | 
					 | 
				
			||||||
        if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
 | 
					 | 
				
			||||||
            player.openContainer(tileInventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest requires access to setting players' gamemode directly.
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					 | 
				
			||||||
        player.openContainer(tileInventory);
 | 
					 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        InventoryView view = bukkitPlayer.getOpenInventory();
 | 
					 | 
				
			||||||
        switch (view.getType()) {
 | 
					 | 
				
			||||||
        case CHEST:
 | 
					 | 
				
			||||||
        case ENDER_CHEST:
 | 
					 | 
				
			||||||
        case SHULKER_BOX:
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					 | 
				
			||||||
        player.activeContainer.b(player);
 | 
					 | 
				
			||||||
        player.activeContainer = player.defaultContainer;
 | 
					 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            // No need to warn repeatedly, error on startup and lack of function should be enough.
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            if (!this.playerInteractManagerGamemode.isAccessible()) {
 | 
					 | 
				
			||||||
                // Just in case, ensure accessible.
 | 
					 | 
				
			||||||
                this.playerInteractManagerGamemode.setAccessible(true);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,109 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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.util.Collection;
 | 
					 | 
				
			||||||
import java.util.UUID;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create a profile and entity to load the player data
 | 
					 | 
				
			||||||
        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getUniqueId().toString();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            UUID uuid = UUID.fromString(identifier);
 | 
					 | 
				
			||||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
					 | 
				
			||||||
            // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
            if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return player;
 | 
					 | 
				
			||||||
        } catch (IllegalArgumentException e) {
 | 
					 | 
				
			||||||
            // Not a UUID
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Bukkit.getOnlinePlayers();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,106 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
 | 
					 | 
				
			||||||
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.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.bukkitOwner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        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 {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.bukkitOwner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                setItemLists(nmsPlayer.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();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,262 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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;
 | 
					 | 
				
			||||||
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.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        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(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 = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            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.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.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;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        list.set(i, itemstack);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean hasCustomName() {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,293 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_12_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.Statistic;
 | 
					 | 
				
			||||||
import org.bukkit.block.BlockState;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryView;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.Block;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.BlockChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.BlockPosition;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.BlockShulkerBox;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.Entity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.EntityOcelot;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.EnumDirection;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.EnumGamemode;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.IBlockData;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.ITileInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.TileEntity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.TileEntityShulkerBox;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private Field playerInteractManagerGamemode;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public AnySilentContainer() {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode.setAccessible(true);
 | 
					 | 
				
			||||||
        } catch (NoSuchFieldException | SecurityException e) {
 | 
					 | 
				
			||||||
            System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(final org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        if (block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        BlockState state = block.getState();
 | 
					 | 
				
			||||||
        return state instanceof org.bukkit.block.Chest
 | 
					 | 
				
			||||||
                || state instanceof org.bukkit.block.ShulkerBox;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(final Player p, final org.bukkit.block.Block b) {
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
					 | 
				
			||||||
        IBlockData blockData = world.getType(blockPosition);
 | 
					 | 
				
			||||||
        Block block = blockData.getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockShulkerBox) {
 | 
					 | 
				
			||||||
            return this.isBlockedShulkerBox(world, blockPosition, blockData);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.getType(blockPosition.up()).m();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check if chest is blocked or has an ocelot on top
 | 
					 | 
				
			||||||
        if (this.isBlockedChest(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);
 | 
					 | 
				
			||||||
            Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (localBlock != block) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					 | 
				
			||||||
            if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (this.isBlockedChest(world, localBlockPosition)) {
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedShulkerBox(final World world, final BlockPosition blockPosition,
 | 
					 | 
				
			||||||
                                        final IBlockData blockData) {
 | 
					 | 
				
			||||||
        // For reference, look at net.minecraft.server.BlockShulkerBox
 | 
					 | 
				
			||||||
        TileEntity tile = world.getTileEntity(blockPosition);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof TileEntityShulkerBox)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumDirection enumDirection = blockData.get(BlockShulkerBox.a);
 | 
					 | 
				
			||||||
        if (((TileEntityShulkerBox) tile).p() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
 | 
					 | 
				
			||||||
            AxisAlignedBB axisAlignedBB = Block.j.b(0.5F * enumDirection.getAdjacentX(),
 | 
					 | 
				
			||||||
                    0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
 | 
					 | 
				
			||||||
                    .a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
 | 
					 | 
				
			||||||
                            enumDirection.getAdjacentZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return world.a(axisAlignedBB.a(blockPosition.shift(enumDirection)));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(final World world, final BlockPosition blockPosition) {
 | 
					 | 
				
			||||||
        // For reference, loot at net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        return world.getType(blockPosition.up()).l() || this.hasOcelotOnTop(world, blockPosition);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean hasOcelotOnTop(final World world, final 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(final Player bukkitPlayer, final boolean silentchest,
 | 
					 | 
				
			||||||
            final org.bukkit.block.Block bukkitBlock) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && bukkitBlock.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
 | 
					 | 
				
			||||||
            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        final World world = player.world;
 | 
					 | 
				
			||||||
        final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
 | 
					 | 
				
			||||||
        final Object tile = world.getTileEntity(blockPosition);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof ITileInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ITileInventory tileInventory = (ITileInventory) tile;
 | 
					 | 
				
			||||||
        Block block = world.getType(blockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockChest) {
 | 
					 | 
				
			||||||
            for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
					 | 
				
			||||||
                BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
					 | 
				
			||||||
                Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (localBlock != block) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					 | 
				
			||||||
                if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (localEnumDirection == EnumDirection.WEST
 | 
					 | 
				
			||||||
                        || localEnumDirection == EnumDirection.NORTH) {
 | 
					 | 
				
			||||||
                    tileInventory = new InventoryLargeChest("container.chestDouble",
 | 
					 | 
				
			||||||
                            (TileEntityChest) localTileEntity, tileInventory);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    tileInventory = new InventoryLargeChest("container.chestDouble", tileInventory,
 | 
					 | 
				
			||||||
                            (TileEntityChest) localTileEntity);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            BlockChest blockChest = (BlockChest) block;
 | 
					 | 
				
			||||||
            if (blockChest.g == BlockChest.Type.BASIC) {
 | 
					 | 
				
			||||||
                bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
 | 
					 | 
				
			||||||
            } else if (blockChest.g == BlockChest.Type.TRAP) {
 | 
					 | 
				
			||||||
                bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockShulkerBox) {
 | 
					 | 
				
			||||||
            bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
 | 
					 | 
				
			||||||
        if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
 | 
					 | 
				
			||||||
            player.openContainer(tileInventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest requires access to setting players' gamemode directly.
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					 | 
				
			||||||
        player.openContainer(tileInventory);
 | 
					 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        InventoryView view = bukkitPlayer.getOpenInventory();
 | 
					 | 
				
			||||||
        switch (view.getType()) {
 | 
					 | 
				
			||||||
        case CHEST:
 | 
					 | 
				
			||||||
        case ENDER_CHEST:
 | 
					 | 
				
			||||||
        case SHULKER_BOX:
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					 | 
				
			||||||
        player.activeContainer.b(player);
 | 
					 | 
				
			||||||
        player.activeContainer = player.defaultContainer;
 | 
					 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
 | 
					 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					 | 
				
			||||||
            // No need to warn repeatedly, error on startup and lack of function should be enough.
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            if (!this.playerInteractManagerGamemode.isAccessible()) {
 | 
					 | 
				
			||||||
                // Just in case, ensure accessible.
 | 
					 | 
				
			||||||
                this.playerInteractManagerGamemode.setAccessible(true);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
 | 
					 | 
				
			||||||
        } catch (IllegalArgumentException | IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,80 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_12_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(final Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(final Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(final Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
 | 
					 | 
				
			||||||
                inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(final Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
 | 
					 | 
				
			||||||
                inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,110 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_12_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
import java.util.UUID;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(final Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException(
 | 
					 | 
				
			||||||
                    "Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Bukkit.getOnlinePlayers();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(final String identifier) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            UUID uuid = UUID.fromString(identifier);
 | 
					 | 
				
			||||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
					 | 
				
			||||||
            // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
            if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return player;
 | 
					 | 
				
			||||||
        } catch (IllegalArgumentException e) {
 | 
					 | 
				
			||||||
            // Not a UUID
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(final OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getUniqueId().toString();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(final OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create a profile and entity to load the player data
 | 
					 | 
				
			||||||
        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,103 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_12_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;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialEnderChest extends InventorySubcontainer
 | 
					 | 
				
			||||||
        implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(final Player player, final Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.bukkitOwner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.setItemLists(this, this.enderChest.getContents());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return this.inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void setItemLists(final InventorySubcontainer subcontainer,
 | 
					 | 
				
			||||||
            final 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 | SecurityException | IllegalArgumentException
 | 
					 | 
				
			||||||
                | IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        this.playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(final Player player) {
 | 
					 | 
				
			||||||
        if (!this.playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.bukkitOwner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                this.setItemLists(nmsPlayer.getEnderChest(), this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            this.playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        this.enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,259 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_12_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_12_R1.ContainerUtil;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.NonNullList;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_12_R1.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.setItemArrays(this, this.player.inventory.items, this.player.inventory.armor,
 | 
					 | 
				
			||||||
                this.player.inventory.extraSlots);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(final EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return this.inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        NonNullList<ItemStack> list = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            return ItemStack.a;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return list.get(i);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (this.player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return this.player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return this.player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean hasCustomName() {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(final int i) {
 | 
					 | 
				
			||||||
        if (i == 0) {
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (i == 1) {
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (i == 2) {
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (i == 3) {
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(final int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 4;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, final ItemStack itemstack) {
 | 
					 | 
				
			||||||
        NonNullList<ItemStack> list = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            this.player.drop(itemstack, true);
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        list.set(i, itemstack);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void setItemArrays(final PlayerInventory inventory, final NonNullList<ItemStack> items,
 | 
					 | 
				
			||||||
            final NonNullList<ItemStack> armor, final NonNullList<ItemStack> extraSlots) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Prepare to remove final modifier
 | 
					 | 
				
			||||||
            Field modifiers = Field.class.getDeclaredField("modifiers");
 | 
					 | 
				
			||||||
            modifiers.setAccessible(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace main inventory list
 | 
					 | 
				
			||||||
            Field field = PlayerInventory.class.getField("items");
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, items);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace armor inventory list
 | 
					 | 
				
			||||||
            field = PlayerInventory.class.getField("armor");
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, armor);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace offhand inventory list
 | 
					 | 
				
			||||||
            field = PlayerInventory.class.getField("extraSlots");
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, extraSlots);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace list containing all inventory lists
 | 
					 | 
				
			||||||
            field = PlayerInventory.class.getDeclaredField("f");
 | 
					 | 
				
			||||||
            field.setAccessible(true);
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, Arrays.asList(items, armor, extraSlots));
 | 
					 | 
				
			||||||
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
 | 
					 | 
				
			||||||
            // Unable to set final fields to item lists, we're screwed. Noisily fail.
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        this.playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(final Player player) {
 | 
					 | 
				
			||||||
        if (!this.playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.setItemArrays(this.player.inventory, this.items, this.armor, this.extraSlots);
 | 
					 | 
				
			||||||
            this.playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, final int j) {
 | 
					 | 
				
			||||||
        NonNullList<ItemStack> list = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            return ItemStack.a;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return 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 = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            return ItemStack.a;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!list.get(i).isEmpty()) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = list.get(i);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            list.set(i, ItemStack.a);
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return ItemStack.a;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,80 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_13_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(final Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof com.lishid.openinv.internal.v1_13_R1.SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (com.lishid.openinv.internal.v1_13_R1.SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(final Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof com.lishid.openinv.internal.v1_13_R1.SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (com.lishid.openinv.internal.v1_13_R1.SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(final Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
 | 
					 | 
				
			||||||
                inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(final Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
 | 
					 | 
				
			||||||
                inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,99 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_13_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;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialEnderChest extends InventorySubcontainer
 | 
					 | 
				
			||||||
        implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(final Player player, final Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getDisplayName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize(), player);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.enderChest = PlayerDataManager.getHandle(player).getEnderChest();
 | 
					 | 
				
			||||||
        this.setItemLists(this, this.enderChest.getContents());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return this.inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void setItemLists(final InventorySubcontainer subcontainer, final 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 | SecurityException | IllegalArgumentException
 | 
					 | 
				
			||||||
                | IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        this.playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(final Player player) {
 | 
					 | 
				
			||||||
        if (!this.playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.bukkitOwner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                this.setItemLists(nmsPlayer.getEnderChest(), this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            this.playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        this.enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,258 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_13_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.lang.reflect.Modifier;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.ChatMessage;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.ContainerUtil;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.NonNullList;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.setItemArrays(this, this.player.inventory.items, this.player.inventory.armor,
 | 
					 | 
				
			||||||
                this.player.inventory.extraSlots);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(final EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return this.inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        NonNullList<ItemStack> list = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            return ItemStack.a;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return list.get(i);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public IChatBaseComponent getDisplayName() {
 | 
					 | 
				
			||||||
        return new ChatMessage(this.player.getName());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean hasCustomName() {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(final int i) {
 | 
					 | 
				
			||||||
        if (i == 0) {
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (i == 1) {
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (i == 2) {
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (i == 3) {
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(final int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 4;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, final ItemStack itemstack) {
 | 
					 | 
				
			||||||
        NonNullList<ItemStack> list = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            this.player.drop(itemstack, true);
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        list.set(i, itemstack);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void setItemArrays(final PlayerInventory inventory, final NonNullList<ItemStack> items,
 | 
					 | 
				
			||||||
            final NonNullList<ItemStack> armor, final NonNullList<ItemStack> extraSlots) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Prepare to remove final modifier
 | 
					 | 
				
			||||||
            Field modifiers = Field.class.getDeclaredField("modifiers");
 | 
					 | 
				
			||||||
            modifiers.setAccessible(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace main inventory list
 | 
					 | 
				
			||||||
            Field field = PlayerInventory.class.getField("items");
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, items);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace armor inventory list
 | 
					 | 
				
			||||||
            field = PlayerInventory.class.getField("armor");
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, armor);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace offhand inventory list
 | 
					 | 
				
			||||||
            field = PlayerInventory.class.getField("extraSlots");
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, extraSlots);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Access and replace list containing all inventory lists
 | 
					 | 
				
			||||||
            field = PlayerInventory.class.getDeclaredField("f");
 | 
					 | 
				
			||||||
            field.setAccessible(true);
 | 
					 | 
				
			||||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
					 | 
				
			||||||
            field.set(inventory, Arrays.asList(items, armor, extraSlots));
 | 
					 | 
				
			||||||
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
 | 
					 | 
				
			||||||
            // Unable to set final fields to item lists, we're screwed. Noisily fail.
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        this.playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(final Player player) {
 | 
					 | 
				
			||||||
        if (!this.playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.setItemArrays(this.player.inventory, this.items, this.armor, this.extraSlots);
 | 
					 | 
				
			||||||
            this.playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, final int j) {
 | 
					 | 
				
			||||||
        NonNullList<ItemStack> list = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            return ItemStack.a;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return 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 = this.getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= list.size()) {
 | 
					 | 
				
			||||||
            return ItemStack.a;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!list.get(i).isEmpty()) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = list.get(i);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            list.set(i, ItemStack.a);
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return ItemStack.a;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					  ~ Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
  ~
 | 
					  ~
 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					  ~ 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
 | 
					  ~ it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -21,31 +21,48 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvinternal</artifactId>
 | 
					    <artifactId>openinvinternal</artifactId>
 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvadapter1_12_R1</artifactId>
 | 
					  <artifactId>openinvadapter1_13_R2</artifactId>
 | 
				
			||||||
  <name>OpenInvAdapter1_12_R1</name>
 | 
					  <name>OpenInvAdapter1_13_R2</name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <dependencies>
 | 
					  <dependencies>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>org.spigotmc</groupId>
 | 
					      <groupId>org.spigotmc</groupId>
 | 
				
			||||||
      <artifactId>spigot</artifactId>
 | 
					      <artifactId>spigot</artifactId>
 | 
				
			||||||
      <version>1.12-R0.1-SNAPSHOT</version>
 | 
					      <version>1.13.2-R0.1-SNAPSHOT</version>
 | 
				
			||||||
      <scope>provided</scope>
 | 
					      <scope>provided</scope>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					      <groupId>com.lishid</groupId>
 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					      <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					      <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <build>
 | 
					  <build>
 | 
				
			||||||
    <plugins>
 | 
					    <plugins>
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					        <executions>
 | 
				
			||||||
 | 
					          <execution>
 | 
				
			||||||
 | 
					            <phase>package</phase>
 | 
				
			||||||
 | 
					            <goals>
 | 
				
			||||||
 | 
					              <goal>shade</goal>
 | 
				
			||||||
 | 
					            </goals>
 | 
				
			||||||
 | 
					          </execution>
 | 
				
			||||||
 | 
					        </executions>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <artifactId>maven-compiler-plugin</artifactId>
 | 
					        <artifactId>maven-compiler-plugin</artifactId>
 | 
				
			||||||
        <version>3.6.1</version>
 | 
					        <version>3.8.1</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <source>1.8</source>
 | 
					          <source>1.8</source>
 | 
				
			||||||
          <target>1.8</target>
 | 
					          <target>1.8</target>
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -14,42 +14,44 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_13_R1;
 | 
					package com.lishid.openinv.internal.v1_13_R2;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					import com.lishid.openinv.internal.IAnySilentContainer;
 | 
				
			||||||
 | 
					import java.lang.reflect.Field;
 | 
				
			||||||
import net.minecraft.server.v1_13_R1.BlockChestTrapped;
 | 
					import java.lang.reflect.InvocationTargetException;
 | 
				
			||||||
import net.minecraft.server.v1_13_R1.ChatMessage;
 | 
					import java.lang.reflect.Method;
 | 
				
			||||||
import net.minecraft.server.v1_13_R1.VoxelShapes;
 | 
					import net.minecraft.server.v1_13_R2.AxisAlignedBB;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.Block;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.BlockChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.BlockChestTrapped;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.BlockEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.BlockPosition;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.BlockPropertyChestType;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.BlockShulkerBox;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ChatMessage;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.Entity;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EntityOcelot;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EnumDirection;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EnumGamemode;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.IBlockData;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ITileInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.InventoryEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.InventoryLargeChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.PlayerInteractManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.TileEntity;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.TileEntityChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.TileEntityEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.TileEntityShulkerBox;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.VoxelShape;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.VoxelShapes;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.World;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.Statistic;
 | 
					import org.bukkit.Statistic;
 | 
				
			||||||
import org.bukkit.block.BlockState;
 | 
					import org.bukkit.block.BlockState;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.inventory.InventoryView;
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
import net.minecraft.server.v1_13_R1.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.Block;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.BlockChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.BlockPosition;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.BlockShulkerBox;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.Entity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.EntityOcelot;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.EnumDirection;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.EnumGamemode;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.IBlockData;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.ITileInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.TileEntity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.TileEntityShulkerBox;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.World;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -66,20 +68,20 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean isAnySilentContainer(final org.bukkit.block.Block block) {
 | 
					    public boolean isAnySilentContainer(@NotNull final org.bukkit.block.Block bukkitBlock) {
 | 
				
			||||||
        if (block.getType() == Material.ENDER_CHEST) {
 | 
					        if (bukkitBlock.getType() == Material.ENDER_CHEST) {
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        BlockState state = block.getState();
 | 
					        BlockState state = bukkitBlock.getState();
 | 
				
			||||||
        return state instanceof org.bukkit.block.Chest
 | 
					        return state instanceof org.bukkit.block.Chest
 | 
				
			||||||
                || state instanceof org.bukkit.block.ShulkerBox;
 | 
					                || state instanceof org.bukkit.block.ShulkerBox;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean isAnyContainerNeeded(final Player p, final org.bukkit.block.Block b) {
 | 
					    public boolean isAnyContainerNeeded(@NotNull final Player bukkitPlayer, @NotNull final org.bukkit.block.Block bukkitBlock) {
 | 
				
			||||||
        EntityPlayer player = com.lishid.openinv.internal.v1_13_R1.PlayerDataManager.getHandle(p);
 | 
					
 | 
				
			||||||
        World world = player.world;
 | 
					        World world = PlayerDataManager.getHandle(bukkitPlayer).world;
 | 
				
			||||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
					        BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
 | 
				
			||||||
        IBlockData blockData = world.getType(blockPosition);
 | 
					        IBlockData blockData = world.getType(blockPosition);
 | 
				
			||||||
        Block block = blockData.getBlock();
 | 
					        Block block = blockData.getBlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -98,21 +100,23 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Check for matching adjacent chests that are blocked or have an ocelot on top
 | 
					        // Check for matching adjacent chests that are blocked or have an ocelot on top
 | 
				
			||||||
        for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
					        BlockPropertyChestType chestType = blockData.get(BlockChest.b);
 | 
				
			||||||
            BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
					 | 
				
			||||||
            Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (localBlock != block) {
 | 
					        if (chestType == BlockPropertyChestType.SINGLE) {
 | 
				
			||||||
                continue;
 | 
					            return false;
 | 
				
			||||||
            }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					        BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.k(blockData));
 | 
				
			||||||
            if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					        IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (this.isBlockedChest(world, localBlockPosition)) {
 | 
					        if (adjacentBlockData.getBlock() == block) {
 | 
				
			||||||
                return true;
 | 
					
 | 
				
			||||||
 | 
					            BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
 | 
				
			||||||
 | 
					                    && adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return this.isBlockedChest(world, adjacentBlockPosition);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -130,7 +134,16 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        EnumDirection enumDirection = blockData.get(BlockShulkerBox.a);
 | 
					        EnumDirection enumDirection = blockData.get(BlockShulkerBox.a);
 | 
				
			||||||
        if (((TileEntityShulkerBox) tile).r() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
 | 
					        if (((TileEntityShulkerBox) tile).r() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
 | 
				
			||||||
            AxisAlignedBB axisAlignedBB = VoxelShapes.b().a()
 | 
					            AxisAlignedBB axisAlignedBB;
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                Method method = VoxelShape.class.getMethod("a");
 | 
				
			||||||
 | 
					                axisAlignedBB = (AxisAlignedBB) method.invoke(VoxelShapes.b());
 | 
				
			||||||
 | 
					            } catch (NoSuchMethodException e) {
 | 
				
			||||||
 | 
					                axisAlignedBB = VoxelShapes.b().getBoundingBox();
 | 
				
			||||||
 | 
					            } catch (InvocationTargetException | IllegalAccessException e) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            axisAlignedBB = axisAlignedBB
 | 
				
			||||||
                    .b(0.5F * enumDirection.getAdjacentX(), 0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
 | 
					                    .b(0.5F * enumDirection.getAdjacentX(), 0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
 | 
				
			||||||
                    .a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(), enumDirection.getAdjacentZ());
 | 
					                    .a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(), enumDirection.getAdjacentZ());
 | 
				
			||||||
            return !world.getCubes(null, axisAlignedBB.a(blockPosition.shift(enumDirection)));
 | 
					            return !world.getCubes(null, axisAlignedBB.a(blockPosition.shift(enumDirection)));
 | 
				
			||||||
@@ -159,17 +172,17 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean activateContainer(final Player bukkitPlayer, final boolean silentchest,
 | 
					    public boolean activateContainer(@NotNull final Player bukkitPlayer, final boolean silent,
 | 
				
			||||||
            final org.bukkit.block.Block bukkitBlock) {
 | 
					                                     @NotNull final org.bukkit.block.Block bukkitBlock) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					        // Silent ender chest is API-only
 | 
				
			||||||
        if (silentchest && bukkitBlock.getType() == Material.ENDER_CHEST) {
 | 
					        if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
 | 
				
			||||||
            bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
 | 
					            bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
 | 
				
			||||||
            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
					            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        EntityPlayer player = com.lishid.openinv.internal.v1_13_R1.PlayerDataManager.getHandle(bukkitPlayer);
 | 
					        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final World world = player.world;
 | 
					        final World world = player.world;
 | 
				
			||||||
        final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
 | 
					        final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
 | 
				
			||||||
@@ -193,31 +206,34 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ITileInventory tileInventory = (ITileInventory) tile;
 | 
					        ITileInventory tileInventory = (ITileInventory) tile;
 | 
				
			||||||
        Block block = world.getType(blockPosition).getBlock();
 | 
					        IBlockData blockData = world.getType(blockPosition);
 | 
				
			||||||
 | 
					        Block block = blockData.getBlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (block instanceof BlockChest) {
 | 
					        if (block instanceof BlockChest) {
 | 
				
			||||||
            for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
					 | 
				
			||||||
                BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
					 | 
				
			||||||
                Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (localBlock != block) {
 | 
					            BlockPropertyChestType chestType = blockData.get(BlockChest.b);
 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
					            if (chestType != BlockPropertyChestType.SINGLE) {
 | 
				
			||||||
                if (!(localTileEntity instanceof TileEntityChest)) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (localEnumDirection == EnumDirection.WEST
 | 
					                BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.k(blockData));
 | 
				
			||||||
                        || localEnumDirection == EnumDirection.NORTH) {
 | 
					                IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
 | 
				
			||||||
                    tileInventory = new InventoryLargeChest(new ChatMessage("container.chestDouble"),
 | 
					
 | 
				
			||||||
                            (TileEntityChest) localTileEntity, tileInventory);
 | 
					                if (adjacentBlockData.getBlock() == block) {
 | 
				
			||||||
                } else {
 | 
					
 | 
				
			||||||
                    tileInventory = new InventoryLargeChest(new ChatMessage("container.chestDouble"),
 | 
					                    BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
 | 
				
			||||||
                            tileInventory, (TileEntityChest) localTileEntity);
 | 
					
 | 
				
			||||||
 | 
					                    if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
 | 
				
			||||||
 | 
					                            && adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        TileEntity adjacentTile = world.getTileEntity(adjacentBlockPosition);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        if (adjacentTile instanceof TileEntityChest) {
 | 
				
			||||||
 | 
					                            ITileInventory rightChest = chestType == BlockPropertyChestType.RIGHT ? tileInventory : (ITileInventory) adjacentTile;
 | 
				
			||||||
 | 
					                            ITileInventory leftChest = chestType == BlockPropertyChestType.RIGHT ? (ITileInventory) adjacentTile : tileInventory;
 | 
				
			||||||
 | 
					                            tileInventory = new InventoryLargeChest(new ChatMessage("container.chestDouble"), rightChest, leftChest);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (block instanceof BlockChestTrapped) {
 | 
					            if (block instanceof BlockChestTrapped) {
 | 
				
			||||||
@@ -232,7 +248,7 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
 | 
					        // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
 | 
				
			||||||
        if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
 | 
					        if (!silent || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
 | 
				
			||||||
            player.openContainer(tileInventory);
 | 
					            player.openContainer(tileInventory);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -250,7 +266,7 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {
 | 
					    public void deactivateContainer(@NotNull final Player bukkitPlayer) {
 | 
				
			||||||
        if (this.playerInteractManagerGamemode == null) {
 | 
					        if (this.playerInteractManagerGamemode == null) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -265,7 +281,7 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        EntityPlayer player = com.lishid.openinv.internal.v1_13_R1.PlayerDataManager.getHandle(bukkitPlayer);
 | 
					        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					 * Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -14,26 +14,23 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_13_R1;
 | 
					package com.lishid.openinv.internal.v1_13_R2;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
import java.util.UUID;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					import com.lishid.openinv.internal.IPlayerDataManager;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					import com.mojang.authlib.GameProfile;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.DimensionManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.MinecraftServer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.PlayerInteractManager;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.Server;
 | 
					import org.bukkit.Server;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
import net.minecraft.server.v1_13_R1.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_13_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_13_R1.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -58,46 +55,20 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					    public Player loadPlayer(@NotNull final OfflinePlayer offline) {
 | 
				
			||||||
        return Bukkit.getOnlinePlayers();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(final String identifier) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            UUID uuid = UUID.fromString(identifier);
 | 
					 | 
				
			||||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
					 | 
				
			||||||
            // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
            if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return player;
 | 
					 | 
				
			||||||
        } catch (IllegalArgumentException e) {
 | 
					 | 
				
			||||||
            // Not a UUID
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(final OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getUniqueId().toString();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(final OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure player has data
 | 
					        // Ensure player has data
 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					        if (!offline.hasPlayedBefore()) {
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create a profile and entity to load the player data
 | 
					        // Create a profile and entity to load the player data
 | 
				
			||||||
        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
					        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
 | 
					        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
 | 
				
			||||||
                new PlayerInteractManager(server.getWorldServer(0)));
 | 
					                new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Get the bukkit entity
 | 
					        // Get the bukkit entity
 | 
				
			||||||
        Player target = entity == null ? null : entity.getBukkitEntity();
 | 
					        Player target = entity.getBukkitEntity();
 | 
				
			||||||
        if (target != null) {
 | 
					        if (target != null) {
 | 
				
			||||||
            // Load data
 | 
					            // Load data
 | 
				
			||||||
            target.loadData();
 | 
					            target.loadData();
 | 
				
			||||||
@@ -106,4 +77,9 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
        return target;
 | 
					        return target;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
 | 
				
			||||||
 | 
					        return player.openInventory(inventory.getBukkitInventory());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,266 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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_13_R2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.AutoRecipeOutput;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.AutoRecipeStackManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ContainerUtil;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EntityHuman;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.IChatBaseComponent;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.IInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.IInventoryListener;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.InventoryEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ItemStack;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.NonNullList;
 | 
				
			||||||
 | 
					import org.bukkit.Location;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
 | 
				
			||||||
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SpecialEnderChest implements IInventory, ISpecialEnderChest, AutoRecipeOutput {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private EntityPlayer owner;
 | 
				
			||||||
 | 
					    private final IChatBaseComponent displayName;
 | 
				
			||||||
 | 
					    private final CraftInventory inventory;
 | 
				
			||||||
 | 
					    private NonNullList<ItemStack> items;
 | 
				
			||||||
 | 
					    private boolean playerOnline;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SpecialEnderChest(final Player player, final Boolean online) {
 | 
				
			||||||
 | 
					        this.owner = PlayerDataManager.getHandle(player);
 | 
				
			||||||
 | 
					        this.displayName = this.owner.getEnderChest().getDisplayName();
 | 
				
			||||||
 | 
					        this.inventory = new CraftInventory(this);
 | 
				
			||||||
 | 
					        this.items = this.owner.getEnderChest().items;
 | 
				
			||||||
 | 
					        this.playerOnline = online;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public @NotNull Inventory getBukkitInventory() {
 | 
				
			||||||
 | 
					        return this.inventory;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isInUse() {
 | 
				
			||||||
 | 
					        return !this.getViewers().isEmpty();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOffline() {
 | 
				
			||||||
 | 
					        this.playerOnline = false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOnline(@NotNull final Player player) {
 | 
				
			||||||
 | 
					        if (!this.playerOnline) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                this.owner = PlayerDataManager.getHandle(player);
 | 
				
			||||||
 | 
					                InventoryEnderChest enderChest = owner.getEnderChest();
 | 
				
			||||||
 | 
					                for (int i = 0; i < enderChest.getSize(); ++i) {
 | 
				
			||||||
 | 
					                    enderChest.setItem(i, this.items.get(i));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                this.items = enderChest.items;
 | 
				
			||||||
 | 
					            } catch (Exception ignored) {}
 | 
				
			||||||
 | 
					            this.playerOnline = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void update() {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().update();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<ItemStack> getContents() {
 | 
				
			||||||
 | 
					        return this.items;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onOpen(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().onOpen(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onClose(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().onClose(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<HumanEntity> getViewers() {
 | 
				
			||||||
 | 
					        return this.owner.getEnderChest().getViewers();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setMaxStackSize(int i) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().setMaxStackSize(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public InventoryHolder getOwner() {
 | 
				
			||||||
 | 
					        return this.owner.getEnderChest().getOwner();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Location getLocation() {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void a(IInventoryListener iinventorylistener) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().a(iinventorylistener);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void b(IInventoryListener iinventorylistener) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().b(iinventorylistener);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ItemStack getItem(int i) {
 | 
				
			||||||
 | 
					        return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ItemStack splitStack(int i, int j) {
 | 
				
			||||||
 | 
					        ItemStack itemstack = ContainerUtil.a(this.items, i, j);
 | 
				
			||||||
 | 
					        if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					            this.update();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return itemstack;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ItemStack a(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        ItemStack itemstack1 = itemstack.cloneItemStack();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (int i = 0; i < this.getSize(); ++i) {
 | 
				
			||||||
 | 
					            ItemStack itemstack2 = this.getItem(i);
 | 
				
			||||||
 | 
					            if (itemstack2.isEmpty()) {
 | 
				
			||||||
 | 
					                this.setItem(i, itemstack1);
 | 
				
			||||||
 | 
					                this.update();
 | 
				
			||||||
 | 
					                return ItemStack.a;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (ItemStack.c(itemstack2, itemstack1)) {
 | 
				
			||||||
 | 
					                int j = Math.min(this.getMaxStackSize(), itemstack2.getMaxStackSize());
 | 
				
			||||||
 | 
					                int k = Math.min(itemstack1.getCount(), j - itemstack2.getCount());
 | 
				
			||||||
 | 
					                if (k > 0) {
 | 
				
			||||||
 | 
					                    itemstack2.add(k);
 | 
				
			||||||
 | 
					                    itemstack1.subtract(k);
 | 
				
			||||||
 | 
					                    if (itemstack1.isEmpty()) {
 | 
				
			||||||
 | 
					                        this.update();
 | 
				
			||||||
 | 
					                        return ItemStack.a;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (itemstack1.getCount() != itemstack.getCount()) {
 | 
				
			||||||
 | 
					            this.update();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return itemstack1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ItemStack splitWithoutUpdate(int i) {
 | 
				
			||||||
 | 
					        ItemStack itemstack = this.items.get(i);
 | 
				
			||||||
 | 
					        if (itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            this.items.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					            return itemstack;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setItem(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        this.items.set(i, itemstack);
 | 
				
			||||||
 | 
					        if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) {
 | 
				
			||||||
 | 
					            itemstack.setCount(this.getMaxStackSize());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.update();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getSize() {
 | 
				
			||||||
 | 
					        return this.owner.getEnderChest().getSize();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean P_() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public IChatBaseComponent getDisplayName() {
 | 
				
			||||||
 | 
					        return this.displayName;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Nullable
 | 
				
			||||||
 | 
					    public IChatBaseComponent getCustomName() {
 | 
				
			||||||
 | 
					        return this.displayName;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean hasCustomName() {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void a(@Nullable IChatBaseComponent ichatbasecomponent) {
 | 
				
			||||||
 | 
					        // Ignored - name is always player's name.
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getMaxStackSize() {
 | 
				
			||||||
 | 
					        return 64;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean a(EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void startOpen(EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void closeContainer(EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean b(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getProperty(int i) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setProperty(int i, int j) {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int h() {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void clear() {
 | 
				
			||||||
 | 
					        this.items.clear();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
 | 
					            autorecipestackmanager.b(itemstack);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,736 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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_13_R2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.collect.ImmutableList;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.Iterator;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.function.Predicate;
 | 
				
			||||||
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.AutoRecipeStackManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ChatMessage;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ContainerUtil;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.CrashReport;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.CrashReportSystemDetails;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EntityHuman;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.IBlockData;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.IChatBaseComponent;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.Item;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ItemArmor;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ItemStack;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.NBTTagCompound;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.NBTTagList;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.NonNullList;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.PlayerInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.ReportedException;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_13_R2.World;
 | 
				
			||||||
 | 
					import org.bukkit.Location;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
 | 
				
			||||||
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final CraftInventory inventory = new CraftInventory(this);
 | 
				
			||||||
 | 
					    private boolean playerOnline;
 | 
				
			||||||
 | 
					    private NonNullList<ItemStack> items, armor, extraSlots;
 | 
				
			||||||
 | 
					    private List<NonNullList<ItemStack>> f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
 | 
				
			||||||
 | 
					        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
				
			||||||
 | 
					        this.playerOnline = online;
 | 
				
			||||||
 | 
					        this.items = this.player.inventory.items;
 | 
				
			||||||
 | 
					        this.armor = this.player.inventory.armor;
 | 
				
			||||||
 | 
					        this.extraSlots = this.player.inventory.extraSlots;
 | 
				
			||||||
 | 
					        this.f = ImmutableList.of(this.items, this.armor, this.extraSlots);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOnline(@NotNull final Player player) {
 | 
				
			||||||
 | 
					        if (!this.playerOnline) {
 | 
				
			||||||
 | 
					            EntityPlayer entityPlayer = PlayerDataManager.getHandle(player);
 | 
				
			||||||
 | 
					            entityPlayer.inventory.transaction.addAll(this.transaction);
 | 
				
			||||||
 | 
					            this.player = entityPlayer;
 | 
				
			||||||
 | 
					            for (int i = 0; i < getSize(); ++i) {
 | 
				
			||||||
 | 
					                this.player.inventory.setItem(i, getRawItem(i));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            this.player.inventory.itemInHandIndex = this.itemInHandIndex;
 | 
				
			||||||
 | 
					            this.items = this.player.inventory.items;
 | 
				
			||||||
 | 
					            this.armor = this.player.inventory.armor;
 | 
				
			||||||
 | 
					            this.extraSlots = this.player.inventory.extraSlots;
 | 
				
			||||||
 | 
					            this.f = ImmutableList.of(this.items, this.armor, this.extraSlots);
 | 
				
			||||||
 | 
					            this.playerOnline = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean a(final EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public @NotNull Inventory getBukkitInventory() {
 | 
				
			||||||
 | 
					        return inventory;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack getItem(int i) {
 | 
				
			||||||
 | 
					        List<ItemStack> list = this.items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.armor;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            i = this.getReversedItemSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.extraSlots;
 | 
				
			||||||
 | 
					        } else if (list == this.armor) {
 | 
				
			||||||
 | 
					            i = this.getReversedArmorSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return list.get(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private ItemStack getRawItem(int i) {
 | 
				
			||||||
 | 
					        NonNullList<ItemStack> list = null;
 | 
				
			||||||
 | 
					        for (NonNullList<ItemStack> next : this.f) {
 | 
				
			||||||
 | 
					            if (i < next.size()) {
 | 
				
			||||||
 | 
					                list = next;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            i -= next.size();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return list == null ? ItemStack.a : list.get(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public IChatBaseComponent getDisplayName() {
 | 
				
			||||||
 | 
					        return new ChatMessage(this.player.getName());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean hasCustomName() {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int getReversedArmorSlotNum(final int i) {
 | 
				
			||||||
 | 
					        if (i == 0) {
 | 
				
			||||||
 | 
					            return 3;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (i == 1) {
 | 
				
			||||||
 | 
					            return 2;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (i == 2) {
 | 
				
			||||||
 | 
					            return 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (i == 3) {
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return i;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int getReversedItemSlotNum(final int i) {
 | 
				
			||||||
 | 
					        if (i >= 27) {
 | 
				
			||||||
 | 
					            return i - 27;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return i + 9;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int getSize() {
 | 
				
			||||||
 | 
					        return super.getSize() + 4;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isInUse() {
 | 
				
			||||||
 | 
					        return !this.getViewers().isEmpty();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setItem(int i, final ItemStack itemstack) {
 | 
				
			||||||
 | 
					        List<ItemStack> list = this.items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.armor;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            i = this.getReversedItemSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.extraSlots;
 | 
				
			||||||
 | 
					        } else if (list == this.armor) {
 | 
				
			||||||
 | 
					            i = this.getReversedArmorSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            this.player.drop(itemstack, true);
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        list.set(i, itemstack);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOffline() {
 | 
				
			||||||
 | 
					        this.playerOnline = false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack splitStack(int i, final int j) {
 | 
				
			||||||
 | 
					        NonNullList<ItemStack> list = this.items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.armor;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            i = this.getReversedItemSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.extraSlots;
 | 
				
			||||||
 | 
					        } else if (list == this.armor) {
 | 
				
			||||||
 | 
					            i = this.getReversedArmorSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return 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 = this.getReversedItemSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.extraSlots;
 | 
				
			||||||
 | 
					        } else if (list == this.armor) {
 | 
				
			||||||
 | 
					            i = this.getReversedArmorSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!list.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					            ItemStack itemstack = list.get(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            list.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					            return itemstack;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return ItemStack.a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<ItemStack> getContents() {
 | 
				
			||||||
 | 
					        List<ItemStack> combined = new ArrayList<>(this.items.size() + this.armor.size() + this.extraSlots.size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (List<ItemStack> sub : this.f) {
 | 
				
			||||||
 | 
					            combined.addAll(sub);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return combined;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<ItemStack> getArmorContents() {
 | 
				
			||||||
 | 
					        return this.armor;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onOpen(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.transaction.add(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onClose(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.transaction.remove(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<HumanEntity> getViewers() {
 | 
				
			||||||
 | 
					        return this.transaction;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public InventoryHolder getOwner() {
 | 
				
			||||||
 | 
					        return this.player.getBukkitEntity();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Location getLocation() {
 | 
				
			||||||
 | 
					        return this.player.getBukkitEntity().getLocation();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ItemStack getItemInHand() {
 | 
				
			||||||
 | 
					        return e(this.itemInHandIndex) ? this.items.get(this.itemInHandIndex) : ItemStack.a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static int getHotbarSize() {
 | 
				
			||||||
 | 
					        return 9;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean a(ItemStack itemstack, ItemStack itemstack1) {
 | 
				
			||||||
 | 
					        return !itemstack.isEmpty() && this.b(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < itemstack.getMaxStackSize() && itemstack.getCount() < this.getMaxStackSize();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean b(ItemStack itemstack, ItemStack itemstack1) {
 | 
				
			||||||
 | 
					        return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int canHold(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        int remains = itemstack.getCount();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            ItemStack itemstack1 = this.getItem(i);
 | 
				
			||||||
 | 
					            if (itemstack1.isEmpty()) {
 | 
				
			||||||
 | 
					                return itemstack.getCount();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!this.a(itemstack, itemstack1)) {
 | 
				
			||||||
 | 
					                remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (remains <= 0) {
 | 
				
			||||||
 | 
					                return itemstack.getCount();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return itemstack.getCount() - remains;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getFirstEmptySlotIndex() {
 | 
				
			||||||
 | 
					        for(int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            if (this.items.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void d(int i) {
 | 
				
			||||||
 | 
					        this.itemInHandIndex = this.l();
 | 
				
			||||||
 | 
					        ItemStack itemstack = this.items.get(this.itemInHandIndex);
 | 
				
			||||||
 | 
					        this.items.set(this.itemInHandIndex, this.items.get(i));
 | 
				
			||||||
 | 
					        this.items.set(i, itemstack);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean e(int i) {
 | 
				
			||||||
 | 
					        return i >= 0 && i < 9;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int c(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        for(int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            ItemStack itemstack1 = this.items.get(i);
 | 
				
			||||||
 | 
					            if (!this.items.get(i).isEmpty() && this.b(itemstack, this.items.get(i)) && !this.items.get(i).f() && !itemstack1.hasEnchantments() && !itemstack1.hasName()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int l() {
 | 
				
			||||||
 | 
					        int i;
 | 
				
			||||||
 | 
					        int j;
 | 
				
			||||||
 | 
					        for(j = 0; j < 9; ++j) {
 | 
				
			||||||
 | 
					            i = (this.itemInHandIndex + j) % 9;
 | 
				
			||||||
 | 
					            if (this.items.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(j = 0; j < 9; ++j) {
 | 
				
			||||||
 | 
					            i = (this.itemInHandIndex + j) % 9;
 | 
				
			||||||
 | 
					            if (!this.items.get(i).hasEnchantments()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return this.itemInHandIndex;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int a(Predicate<ItemStack> predicate, int i) {
 | 
				
			||||||
 | 
					        int j = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int k;
 | 
				
			||||||
 | 
					        for(k = 0; k < this.getSize(); ++k) {
 | 
				
			||||||
 | 
					            ItemStack itemstack = this.getItem(k);
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty() && predicate.test(itemstack)) {
 | 
				
			||||||
 | 
					                int l = i <= 0 ? itemstack.getCount() : Math.min(i - j, itemstack.getCount());
 | 
				
			||||||
 | 
					                j += l;
 | 
				
			||||||
 | 
					                if (i != 0) {
 | 
				
			||||||
 | 
					                    itemstack.subtract(l);
 | 
				
			||||||
 | 
					                    if (itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                        this.setItem(k, ItemStack.a);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (i > 0 && j >= i) {
 | 
				
			||||||
 | 
					                        return j;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!this.getCarried().isEmpty() && predicate.test(this.getCarried())) {
 | 
				
			||||||
 | 
					            k = i <= 0 ? this.getCarried().getCount() : Math.min(i - j, this.getCarried().getCount());
 | 
				
			||||||
 | 
					            j += k;
 | 
				
			||||||
 | 
					            if (i != 0) {
 | 
				
			||||||
 | 
					                this.getCarried().subtract(k);
 | 
				
			||||||
 | 
					                if (this.getCarried().isEmpty()) {
 | 
				
			||||||
 | 
					                    this.setCarried(ItemStack.a);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (i > 0 && j >= i) {
 | 
				
			||||||
 | 
					                    return j;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return j;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int i(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        int i = this.firstPartial(itemstack);
 | 
				
			||||||
 | 
					        if (i == -1) {
 | 
				
			||||||
 | 
					            i = this.getFirstEmptySlotIndex();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return i == -1 ? itemstack.getCount() : this.d(i, itemstack);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int d(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        Item item = itemstack.getItem();
 | 
				
			||||||
 | 
					        int j = itemstack.getCount();
 | 
				
			||||||
 | 
					        ItemStack itemstack1 = this.getItem(i);
 | 
				
			||||||
 | 
					        if (itemstack1.isEmpty()) {
 | 
				
			||||||
 | 
					            itemstack1 = new ItemStack(item, 0);
 | 
				
			||||||
 | 
					            if (itemstack.hasTag()) {
 | 
				
			||||||
 | 
					                itemstack1.setTag(itemstack.getTag().clone());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            this.setItem(i, itemstack1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int k = j;
 | 
				
			||||||
 | 
					        if (j > itemstack1.getMaxStackSize() - itemstack1.getCount()) {
 | 
				
			||||||
 | 
					            k = itemstack1.getMaxStackSize() - itemstack1.getCount();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (k > this.getMaxStackSize() - itemstack1.getCount()) {
 | 
				
			||||||
 | 
					            k = this.getMaxStackSize() - itemstack1.getCount();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (k == 0) {
 | 
				
			||||||
 | 
					            return j;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            j -= k;
 | 
				
			||||||
 | 
					            itemstack1.add(k);
 | 
				
			||||||
 | 
					            itemstack1.d(5);
 | 
				
			||||||
 | 
					            return j;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int firstPartial(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        if (this.a(this.getItem(this.itemInHandIndex), itemstack)) {
 | 
				
			||||||
 | 
					            return this.itemInHandIndex;
 | 
				
			||||||
 | 
					        } else if (this.a(this.getItem(40), itemstack)) {
 | 
				
			||||||
 | 
					            return 40;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            for(int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					                if (this.a(this.items.get(i), itemstack)) {
 | 
				
			||||||
 | 
					                    return i;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return -1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void p() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (NonNullList<ItemStack> itemStacks : this.f) {
 | 
				
			||||||
 | 
					            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
				
			||||||
 | 
					                if (!itemStacks.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                    itemStacks.get(i).a(this.player.world, this.player, i, this.itemInHandIndex == i);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean pickup(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        return this.c(-1, itemstack);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean c(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        if (itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                if (itemstack.f()) {
 | 
				
			||||||
 | 
					                    if (i == -1) {
 | 
				
			||||||
 | 
					                        i = this.getFirstEmptySlotIndex();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (i >= 0) {
 | 
				
			||||||
 | 
					                        this.items.set(i, itemstack.cloneItemStack());
 | 
				
			||||||
 | 
					                        this.items.get(i).d(5);
 | 
				
			||||||
 | 
					                        itemstack.setCount(0);
 | 
				
			||||||
 | 
					                        return true;
 | 
				
			||||||
 | 
					                    } else if (this.player.abilities.canInstantlyBuild) {
 | 
				
			||||||
 | 
					                        itemstack.setCount(0);
 | 
				
			||||||
 | 
					                        return true;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        return false;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    int j;
 | 
				
			||||||
 | 
					                    do {
 | 
				
			||||||
 | 
					                        j = itemstack.getCount();
 | 
				
			||||||
 | 
					                        if (i == -1) {
 | 
				
			||||||
 | 
					                            itemstack.setCount(this.i(itemstack));
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            itemstack.setCount(this.d(i, itemstack));
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    } while(!itemstack.isEmpty() && itemstack.getCount() < j);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (itemstack.getCount() == j && this.player.abilities.canInstantlyBuild) {
 | 
				
			||||||
 | 
					                        itemstack.setCount(0);
 | 
				
			||||||
 | 
					                        return true;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        return itemstack.getCount() < j;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } catch (Throwable var6) {
 | 
				
			||||||
 | 
					                CrashReport crashreport = CrashReport.a(var6, "Adding item to inventory");
 | 
				
			||||||
 | 
					                CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Item being added");
 | 
				
			||||||
 | 
					                crashreportsystemdetails.a("Item ID", Item.getId(itemstack.getItem()));
 | 
				
			||||||
 | 
					                crashreportsystemdetails.a("Item data", itemstack.getDamage());
 | 
				
			||||||
 | 
					                crashreportsystemdetails.a("Item name", () -> itemstack.getName().getString());
 | 
				
			||||||
 | 
					                throw new ReportedException(crashreport);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void a(World world, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        if (!world.isClientSide) {
 | 
				
			||||||
 | 
					            while(!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                int i = this.firstPartial(itemstack);
 | 
				
			||||||
 | 
					                if (i == -1) {
 | 
				
			||||||
 | 
					                    i = this.getFirstEmptySlotIndex();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (i == -1) {
 | 
				
			||||||
 | 
					                    this.player.drop(itemstack, false);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                int j = itemstack.getMaxStackSize() - this.getItem(i).getCount();
 | 
				
			||||||
 | 
					                if (this.c(i, itemstack.cloneAndSubtract(j))) {
 | 
				
			||||||
 | 
					                    ((EntityPlayer)this.player).playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, i, this.getItem(i)));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void f(ItemStack itemstack) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (NonNullList<ItemStack> nonnulllist : this.f) {
 | 
				
			||||||
 | 
					            for (int i = 0; i < nonnulllist.size(); ++i) {
 | 
				
			||||||
 | 
					                if (nonnulllist.get(i) == itemstack) {
 | 
				
			||||||
 | 
					                    nonnulllist.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public float a(IBlockData iblockdata) {
 | 
				
			||||||
 | 
					        return this.items.get(this.itemInHandIndex).a(iblockdata);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public NBTTagList a(NBTTagList nbttaglist) {
 | 
				
			||||||
 | 
					        NBTTagCompound nbttagcompound;
 | 
				
			||||||
 | 
					        int i;
 | 
				
			||||||
 | 
					        for(i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            if (!this.items.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                nbttagcompound = new NBTTagCompound();
 | 
				
			||||||
 | 
					                nbttagcompound.setByte("Slot", (byte) i);
 | 
				
			||||||
 | 
					                this.items.get(i).save(nbttagcompound);
 | 
				
			||||||
 | 
					                nbttaglist.add(nbttagcompound);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(i = 0; i < this.armor.size(); ++i) {
 | 
				
			||||||
 | 
					            if (!this.armor.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                nbttagcompound = new NBTTagCompound();
 | 
				
			||||||
 | 
					                nbttagcompound.setByte("Slot", (byte) (i + 100));
 | 
				
			||||||
 | 
					                this.armor.get(i).save(nbttagcompound);
 | 
				
			||||||
 | 
					                nbttaglist.add(nbttagcompound);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(i = 0; i < this.extraSlots.size(); ++i) {
 | 
				
			||||||
 | 
					            if (!this.extraSlots.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                nbttagcompound = new NBTTagCompound();
 | 
				
			||||||
 | 
					                nbttagcompound.setByte("Slot", (byte) (i + 150));
 | 
				
			||||||
 | 
					                this.extraSlots.get(i).save(nbttagcompound);
 | 
				
			||||||
 | 
					                nbttaglist.add(nbttagcompound);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return nbttaglist;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void b(NBTTagList nbttaglist) {
 | 
				
			||||||
 | 
					        this.items.clear();
 | 
				
			||||||
 | 
					        this.armor.clear();
 | 
				
			||||||
 | 
					        this.extraSlots.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(int i = 0; i < nbttaglist.size(); ++i) {
 | 
				
			||||||
 | 
					            NBTTagCompound nbttagcompound = nbttaglist.getCompound(i);
 | 
				
			||||||
 | 
					            int j = nbttagcompound.getByte("Slot") & 255;
 | 
				
			||||||
 | 
					            ItemStack itemstack = ItemStack.a(nbttagcompound);
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                if (j < this.items.size()) {
 | 
				
			||||||
 | 
					                    this.items.set(j, itemstack);
 | 
				
			||||||
 | 
					                } else if (j >= 100 && j < this.armor.size() + 100) {
 | 
				
			||||||
 | 
					                    this.armor.set(j - 100, itemstack);
 | 
				
			||||||
 | 
					                } else if (j >= 150 && j < this.extraSlots.size() + 150) {
 | 
				
			||||||
 | 
					                    this.extraSlots.set(j - 150, itemstack);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean P_() {
 | 
				
			||||||
 | 
					        Iterator iterator = this.items.iterator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ItemStack itemstack;
 | 
				
			||||||
 | 
					        while(iterator.hasNext()) {
 | 
				
			||||||
 | 
					            itemstack = (ItemStack)iterator.next();
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        iterator = this.armor.iterator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while(iterator.hasNext()) {
 | 
				
			||||||
 | 
					            itemstack = (ItemStack)iterator.next();
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        iterator = this.extraSlots.iterator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while(iterator.hasNext()) {
 | 
				
			||||||
 | 
					            itemstack = (ItemStack)iterator.next();
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Nullable
 | 
				
			||||||
 | 
					    public IChatBaseComponent getCustomName() {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean b(IBlockData iblockdata) {
 | 
				
			||||||
 | 
					        return this.getItem(this.itemInHandIndex).b(iblockdata);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void a(float f) {
 | 
				
			||||||
 | 
					        if (f > 0.0F) {
 | 
				
			||||||
 | 
					            f /= 4.0F;
 | 
				
			||||||
 | 
					            if (f < 1.0F) {
 | 
				
			||||||
 | 
					                f = 1.0F;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (ItemStack itemstack : this.armor) {
 | 
				
			||||||
 | 
					                if (itemstack.getItem() instanceof ItemArmor) {
 | 
				
			||||||
 | 
					                    itemstack.damage((int) f, this.player);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void dropContents() {
 | 
				
			||||||
 | 
					        for (NonNullList<ItemStack> itemStacks : this.f) {
 | 
				
			||||||
 | 
					            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
				
			||||||
 | 
					                ItemStack itemstack = itemStacks.get(i);
 | 
				
			||||||
 | 
					                if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                    itemStacks.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					                    this.player.a(itemstack, true, false);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean h(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        return this.f.stream().flatMap(NonNullList::stream).anyMatch(itemStack1 -> !itemStack1.isEmpty() && itemStack1.doMaterialsMatch(itemstack));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void a(PlayerInventory playerinventory) {
 | 
				
			||||||
 | 
					        for (int i = 0; i < playerinventory.getSize(); ++i) {
 | 
				
			||||||
 | 
					            this.setItem(i, playerinventory.getItem(i));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.itemInHandIndex = playerinventory.itemInHandIndex;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void clear() {
 | 
				
			||||||
 | 
					        this.f.forEach(NonNullList::clear);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
				
			||||||
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
 | 
					            autorecipestackmanager.a(itemstack);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2018 lishid. All rights reserved.
 | 
					  ~ Copyright (C) 2011-2019 lishid. All rights reserved.
 | 
				
			||||||
  ~
 | 
					  ~
 | 
				
			||||||
  ~ This program is free software: you can redistribute it and/or modify
 | 
					  ~ 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
 | 
					  ~ it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -21,31 +22,48 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvinternal</artifactId>
 | 
					    <artifactId>openinvinternal</artifactId>
 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvadapter1_13_R1</artifactId>
 | 
					  <artifactId>openinvadapter1_14_R1</artifactId>
 | 
				
			||||||
  <name>OpenInvAdapter1_13_R1</name>
 | 
					  <name>OpenInvAdapter1_14_R1</name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <dependencies>
 | 
					  <dependencies>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>org.spigotmc</groupId>
 | 
					      <groupId>org.spigotmc</groupId>
 | 
				
			||||||
      <artifactId>spigot</artifactId>
 | 
					      <artifactId>spigot</artifactId>
 | 
				
			||||||
      <version>1.13-pre7-R0.1-SNAPSHOT</version>
 | 
					      <version>1.14.3-R0.1-SNAPSHOT</version>
 | 
				
			||||||
      <scope>provided</scope>
 | 
					      <scope>provided</scope>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					      <groupId>com.lishid</groupId>
 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					      <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					      <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <build>
 | 
					  <build>
 | 
				
			||||||
    <plugins>
 | 
					    <plugins>
 | 
				
			||||||
 | 
					      <plugin>
 | 
				
			||||||
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
 | 
					        <configuration>
 | 
				
			||||||
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
 | 
					        </configuration>
 | 
				
			||||||
 | 
					        <executions>
 | 
				
			||||||
 | 
					          <execution>
 | 
				
			||||||
 | 
					            <phase>package</phase>
 | 
				
			||||||
 | 
					            <goals>
 | 
				
			||||||
 | 
					              <goal>shade</goal>
 | 
				
			||||||
 | 
					            </goals>
 | 
				
			||||||
 | 
					          </execution>
 | 
				
			||||||
 | 
					        </executions>
 | 
				
			||||||
 | 
					      </plugin>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <artifactId>maven-compiler-plugin</artifactId>
 | 
					        <artifactId>maven-compiler-plugin</artifactId>
 | 
				
			||||||
        <version>3.6.1</version>
 | 
					        <version>3.8.1</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <source>1.8</source>
 | 
					          <source>1.8</source>
 | 
				
			||||||
          <target>1.8</target>
 | 
					          <target>1.8</target>
 | 
				
			||||||
@@ -54,4 +72,4 @@
 | 
				
			|||||||
    </plugins>
 | 
					    </plugins>
 | 
				
			||||||
  </build>
 | 
					  </build>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</project>
 | 
					</project>
 | 
				
			||||||
@@ -0,0 +1,332 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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_14_R1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.IAnySilentContainer;
 | 
				
			||||||
 | 
					import java.lang.reflect.Field;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.Block;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.BlockBarrel;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.BlockChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.BlockChestTrapped;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.BlockEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.BlockPosition;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.BlockPropertyChestType;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.BlockShulkerBox;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ChatMessage;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.Container;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ContainerChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EnumChatFormat;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EnumGamemode;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.IBlockData;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.IChatBaseComponent;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ITileInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.InventoryEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.InventoryLargeChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.PlayerInteractManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.PlayerInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.TileEntity;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.TileEntityChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.TileEntityEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.TileEntityLootable;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.TileInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.World;
 | 
				
			||||||
 | 
					import org.bukkit.Material;
 | 
				
			||||||
 | 
					import org.bukkit.Statistic;
 | 
				
			||||||
 | 
					import org.bukkit.block.Barrel;
 | 
				
			||||||
 | 
					import org.bukkit.block.BlockFace;
 | 
				
			||||||
 | 
					import org.bukkit.block.BlockState;
 | 
				
			||||||
 | 
					import org.bukkit.block.EnderChest;
 | 
				
			||||||
 | 
					import org.bukkit.block.ShulkerBox;
 | 
				
			||||||
 | 
					import org.bukkit.block.data.BlockData;
 | 
				
			||||||
 | 
					import org.bukkit.block.data.Directional;
 | 
				
			||||||
 | 
					import org.bukkit.block.data.type.Chest;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Cat;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
 | 
					import org.bukkit.util.BoundingBox;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Field playerInteractManagerGamemode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public AnySilentContainer() {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
 | 
				
			||||||
 | 
					            this.playerInteractManagerGamemode.setAccessible(true);
 | 
				
			||||||
 | 
					        } catch (NoSuchFieldException | SecurityException e) {
 | 
				
			||||||
 | 
					            System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isAnySilentContainer(@NotNull final org.bukkit.block.Block bukkitBlock) {
 | 
				
			||||||
 | 
					        if (bukkitBlock.getType() == Material.ENDER_CHEST) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        BlockState state = bukkitBlock.getState();
 | 
				
			||||||
 | 
					        return state instanceof org.bukkit.block.Chest
 | 
				
			||||||
 | 
					                || state instanceof org.bukkit.block.ShulkerBox
 | 
				
			||||||
 | 
					                || state instanceof org.bukkit.block.Barrel;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isAnyContainerNeeded(@NotNull final Player p, @NotNull final org.bukkit.block.Block block) {
 | 
				
			||||||
 | 
					        BlockState blockState = block.getState();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Barrels do not require AnyContainer.
 | 
				
			||||||
 | 
					        if (blockState instanceof Barrel) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Enderchests require a non-occluding block on top to open.
 | 
				
			||||||
 | 
					        if (blockState instanceof EnderChest) {
 | 
				
			||||||
 | 
					            return block.getRelative(0, 1, 0).getType().isOccluding();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Shulker boxes require 1/2 a block clear in the direction they open.
 | 
				
			||||||
 | 
					        if (blockState instanceof ShulkerBox) {
 | 
				
			||||||
 | 
					            BoundingBox boundingBox = block.getBoundingBox();
 | 
				
			||||||
 | 
					            if (boundingBox.getVolume() > 1) {
 | 
				
			||||||
 | 
					                // Shulker box is already open.
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            BlockData blockData = block.getBlockData();
 | 
				
			||||||
 | 
					            if (!(blockData instanceof Directional)) {
 | 
				
			||||||
 | 
					                // Shouldn't be possible. Just in case, demand AnyChest.
 | 
				
			||||||
 | 
					                return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Directional directional = (Directional) blockData;
 | 
				
			||||||
 | 
					            BlockFace face = directional.getFacing();
 | 
				
			||||||
 | 
					            boundingBox.shift(face.getDirection());
 | 
				
			||||||
 | 
					            // Return whether or not bounding boxes overlap.
 | 
				
			||||||
 | 
					            return block.getRelative(face, 1).getBoundingBox().overlaps(boundingBox);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!(blockState instanceof org.bukkit.block.Chest)) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (isBlockedChest(block)) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        BlockData blockData = block.getBlockData();
 | 
				
			||||||
 | 
					        if (!(blockData instanceof Chest) || ((Chest) blockData).getType() == Chest.Type.SINGLE) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Chest chest = (Chest) blockData;
 | 
				
			||||||
 | 
					        int ordinal = (chest.getFacing().ordinal() + 4 + (chest.getType() == Chest.Type.RIGHT ? -1 : 1)) % 4;
 | 
				
			||||||
 | 
					        BlockFace relativeFace = BlockFace.values()[ordinal];
 | 
				
			||||||
 | 
					        org.bukkit.block.Block relative = block.getRelative(relativeFace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (relative.getType() != block.getType()) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        BlockData relativeData = relative.getBlockData();
 | 
				
			||||||
 | 
					        if (!(relativeData instanceof Chest)) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Chest relativeChest = (Chest) relativeData;
 | 
				
			||||||
 | 
					        if (relativeChest.getFacing() != chest.getFacing()
 | 
				
			||||||
 | 
					                || relativeChest.getType() != (chest.getType() == Chest.Type.RIGHT ? Chest.Type.LEFT : Chest.Type.RIGHT)) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return isBlockedChest(relative);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean isBlockedChest(org.bukkit.block.Block block) {
 | 
				
			||||||
 | 
					        org.bukkit.block.Block relative = block.getRelative(0, 1, 0);
 | 
				
			||||||
 | 
					        return relative.getType().isOccluding()
 | 
				
			||||||
 | 
					                || block.getWorld().getNearbyEntities(BoundingBox.of(relative), entity -> entity instanceof Cat).size() > 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean activateContainer(@NotNull final Player bukkitPlayer, final boolean silentchest,
 | 
				
			||||||
 | 
					                                     @NotNull final org.bukkit.block.Block bukkitBlock) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Silent ender chest is API-only
 | 
				
			||||||
 | 
					        if (silentchest && bukkitBlock.getType() == Material.ENDER_CHEST) {
 | 
				
			||||||
 | 
					            bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
 | 
				
			||||||
 | 
					            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final World world = player.world;
 | 
				
			||||||
 | 
					        final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
 | 
				
			||||||
 | 
					        final TileEntity tile = world.getTileEntity(blockPosition);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (tile == null) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (tile instanceof TileEntityEnderChest) {
 | 
				
			||||||
 | 
					            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
				
			||||||
 | 
					            InventoryEnderChest enderChest = player.getEnderChest();
 | 
				
			||||||
 | 
					            enderChest.a((TileEntityEnderChest) tile);
 | 
				
			||||||
 | 
					            player.openContainer(new TileInventory((containerCounter, playerInventory, ignored) ->
 | 
				
			||||||
 | 
					                    ContainerChest.a(containerCounter, playerInventory, enderChest), BlockEnderChest.d));
 | 
				
			||||||
 | 
					            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!(tile instanceof ITileInventory)) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ITileInventory tileInventory = (ITileInventory) tile;
 | 
				
			||||||
 | 
					        IBlockData blockData = world.getType(blockPosition);
 | 
				
			||||||
 | 
					        Block block = blockData.getBlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (block instanceof BlockChest) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            BlockPropertyChestType chestType = blockData.get(BlockChest.b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (chestType != BlockPropertyChestType.SINGLE) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.j(blockData));
 | 
				
			||||||
 | 
					                IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (adjacentBlockData.getBlock() == block) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
 | 
				
			||||||
 | 
					                            && adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        TileEntity adjacentTile = world.getTileEntity(adjacentBlockPosition);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        if (adjacentTile instanceof TileEntityChest && tileInventory instanceof  TileEntityChest) {
 | 
				
			||||||
 | 
					                            TileEntityChest rightChest = chestType == BlockPropertyChestType.RIGHT ? ((TileEntityChest) tileInventory) : (TileEntityChest) adjacentTile;
 | 
				
			||||||
 | 
					                            TileEntityChest leftChest = chestType == BlockPropertyChestType.RIGHT ? (TileEntityChest) adjacentTile : ((TileEntityChest) tileInventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            if (rightChest.lootTable != null || leftChest.lootTable != null) {
 | 
				
			||||||
 | 
					                                player.a(new ChatMessage("Loot not generated! Please disable /silentcontainer.").a(EnumChatFormat.RED), true);
 | 
				
			||||||
 | 
					                                return false;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            tileInventory = new ITileInventory() {
 | 
				
			||||||
 | 
					                                public Container createMenu(int containerCounter, PlayerInventory playerInventory, EntityHuman entityHuman) {
 | 
				
			||||||
 | 
					                                    leftChest.d(playerInventory.player);
 | 
				
			||||||
 | 
					                                    rightChest.d(playerInventory.player);
 | 
				
			||||||
 | 
					                                    return ContainerChest.b(containerCounter, playerInventory, new InventoryLargeChest(rightChest, leftChest));
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                public IChatBaseComponent getScoreboardDisplayName() {
 | 
				
			||||||
 | 
					                                    return new ChatMessage("container.chestDouble");
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                            };
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (block instanceof BlockChestTrapped) {
 | 
				
			||||||
 | 
					                bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (block instanceof BlockShulkerBox) {
 | 
				
			||||||
 | 
					            bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (block instanceof BlockBarrel) {
 | 
				
			||||||
 | 
					            bukkitPlayer.incrementStatistic(Statistic.OPEN_BARREL);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
 | 
				
			||||||
 | 
					        if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
 | 
				
			||||||
 | 
					            player.openContainer(tileInventory);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // SilentChest requires access to setting players' gamemode directly.
 | 
				
			||||||
 | 
					        if (this.playerInteractManagerGamemode == null) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (tile instanceof TileEntityLootable) {
 | 
				
			||||||
 | 
					            TileEntityLootable lootable = (TileEntityLootable) tile;
 | 
				
			||||||
 | 
					            if (lootable.lootTable != null) {
 | 
				
			||||||
 | 
					                player.a(new ChatMessage("Loot not generated! Please disable /silentcontainer.").a(EnumChatFormat.RED), true);
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
				
			||||||
 | 
					        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
				
			||||||
 | 
					        player.openContainer(tileInventory);
 | 
				
			||||||
 | 
					        this.forceGameMode(player, gamemode);
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void deactivateContainer(@NotNull final Player bukkitPlayer) {
 | 
				
			||||||
 | 
					        if (this.playerInteractManagerGamemode == null) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        InventoryView view = bukkitPlayer.getOpenInventory();
 | 
				
			||||||
 | 
					        switch (view.getType()) {
 | 
				
			||||||
 | 
					            case CHEST:
 | 
				
			||||||
 | 
					            case ENDER_CHEST:
 | 
				
			||||||
 | 
					            case SHULKER_BOX:
 | 
				
			||||||
 | 
					            case BARREL:
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
				
			||||||
 | 
					        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
				
			||||||
 | 
					        player.activeContainer.b(player);
 | 
				
			||||||
 | 
					        player.activeContainer = player.defaultContainer;
 | 
				
			||||||
 | 
					        this.forceGameMode(player, gamemode);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
 | 
				
			||||||
 | 
					        if (this.playerInteractManagerGamemode == null) {
 | 
				
			||||||
 | 
					            // No need to warn repeatedly, error on startup and lack of function should be enough.
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            if (!this.playerInteractManagerGamemode.isAccessible()) {
 | 
				
			||||||
 | 
					                // Just in case, ensure accessible.
 | 
				
			||||||
 | 
					                this.playerInteractManagerGamemode.setAccessible(true);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
 | 
				
			||||||
 | 
					        } catch (IllegalArgumentException | IllegalAccessException e) {
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,171 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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_14_R1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.IPlayerDataManager;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
 | 
					import com.mojang.authlib.GameProfile;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ChatComponentText;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.Container;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.Containers;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.DimensionManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.MinecraftServer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.PlayerInteractManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.PlayerInventory;
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
 | 
					import org.bukkit.Server;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer;
 | 
				
			||||||
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.event.inventory.InventoryType;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static EntityPlayer getHandle(final Player player) {
 | 
				
			||||||
 | 
					        if (player instanceof CraftPlayer) {
 | 
				
			||||||
 | 
					            return ((CraftPlayer) player).getHandle();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Server server = player.getServer();
 | 
				
			||||||
 | 
					        EntityPlayer nmsPlayer = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (server instanceof CraftServer) {
 | 
				
			||||||
 | 
					            nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (nmsPlayer == null) {
 | 
				
			||||||
 | 
					            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
				
			||||||
 | 
					            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return nmsPlayer;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Player loadPlayer(@NotNull final OfflinePlayer offline) {
 | 
				
			||||||
 | 
					        // Ensure player has data
 | 
				
			||||||
 | 
					        if (!offline.hasPlayedBefore()) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Create a profile and entity to load the player data
 | 
				
			||||||
 | 
					        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
				
			||||||
 | 
					        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
				
			||||||
 | 
					        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
 | 
				
			||||||
 | 
					                new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Get the bukkit entity
 | 
				
			||||||
 | 
					        Player target = entity.getBukkitEntity();
 | 
				
			||||||
 | 
					        if (target != null) {
 | 
				
			||||||
 | 
					            // Load data
 | 
				
			||||||
 | 
					            target.loadData();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // Return the entity
 | 
				
			||||||
 | 
					        return target;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        EntityPlayer nmsPlayer = getHandle(player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (nmsPlayer == null || nmsPlayer.playerConnection == null) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String title;
 | 
				
			||||||
 | 
					        if (inventory instanceof SpecialEnderChest) {
 | 
				
			||||||
 | 
					            HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner();
 | 
				
			||||||
 | 
					            //noinspection ConstantConditions // Owner name can be null when loaded under certain conditions.
 | 
				
			||||||
 | 
					            title = (owner.getName() != null ? owner.getName() : owner.getUniqueId().toString()) + "'s Ender Chest";
 | 
				
			||||||
 | 
					        } else if (inventory instanceof SpecialPlayerInventory) {
 | 
				
			||||||
 | 
					            EntityHuman owner = ((PlayerInventory) inventory).player;
 | 
				
			||||||
 | 
					            title = (owner.getName() != null ? owner.getName() : owner.getUniqueID().toString()) + "'s Inventory";
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            return player.openInventory(inventory.getBukkitInventory());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Container container = new CraftContainer(new InventoryView() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public @NotNull Inventory getTopInventory() {
 | 
				
			||||||
 | 
					                return inventory.getBukkitInventory();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public @NotNull Inventory getBottomInventory() {
 | 
				
			||||||
 | 
					                return player.getInventory();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public @NotNull HumanEntity getPlayer() {
 | 
				
			||||||
 | 
					                return player;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public @NotNull InventoryType getType() {
 | 
				
			||||||
 | 
					                return inventory.getBukkitInventory().getType();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public @NotNull String getTitle() {
 | 
				
			||||||
 | 
					                return title;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }, nmsPlayer, nmsPlayer.nextContainerCounter()) {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public Containers<?> getType() {
 | 
				
			||||||
 | 
					                switch (inventory.getBukkitInventory().getSize()) {
 | 
				
			||||||
 | 
					                    case 9:
 | 
				
			||||||
 | 
					                        return Containers.GENERIC_9X1;
 | 
				
			||||||
 | 
					                    case 18:
 | 
				
			||||||
 | 
					                        return Containers.GENERIC_9X2;
 | 
				
			||||||
 | 
					                    case 27:
 | 
				
			||||||
 | 
					                    default:
 | 
				
			||||||
 | 
					                        return Containers.GENERIC_9X3;
 | 
				
			||||||
 | 
					                    case 36:
 | 
				
			||||||
 | 
					                        return Containers.GENERIC_9X4;
 | 
				
			||||||
 | 
					                    case 45:
 | 
				
			||||||
 | 
					                        return Containers.GENERIC_9X5;
 | 
				
			||||||
 | 
					                    case 41: // PLAYER
 | 
				
			||||||
 | 
					                    case 54:
 | 
				
			||||||
 | 
					                        return Containers.GENERIC_9X6;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        container.setTitle(new ChatComponentText(title));
 | 
				
			||||||
 | 
					        container = CraftEventFactory.callInventoryOpenEvent(nmsPlayer, container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (container == null) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        nmsPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, container.getType(),
 | 
				
			||||||
 | 
					                new ChatComponentText(container.getBukkitView().getTitle())));
 | 
				
			||||||
 | 
					        nmsPlayer.activeContainer = container;
 | 
				
			||||||
 | 
					        container.addSlotListener(nmsPlayer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return container.getBukkitView();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,255 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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_14_R1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.AutoRecipeStackManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ContainerUtil;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.IInventoryListener;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.InventoryEnderChest;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ItemStack;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.NonNullList;
 | 
				
			||||||
 | 
					import org.bukkit.Location;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory;
 | 
				
			||||||
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEnderChest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final CraftInventory inventory;
 | 
				
			||||||
 | 
					    private EntityPlayer owner;
 | 
				
			||||||
 | 
					    private NonNullList<ItemStack> items;
 | 
				
			||||||
 | 
					    private boolean playerOnline;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SpecialEnderChest(final Player player, final Boolean online) {
 | 
				
			||||||
 | 
					        super(PlayerDataManager.getHandle(player));
 | 
				
			||||||
 | 
					        this.inventory = new CraftInventory(this);
 | 
				
			||||||
 | 
					        this.owner = PlayerDataManager.getHandle(player);
 | 
				
			||||||
 | 
					        this.playerOnline = online;
 | 
				
			||||||
 | 
					        this.items = this.owner.getEnderChest().items;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public @NotNull CraftInventory getBukkitInventory() {
 | 
				
			||||||
 | 
					        return inventory;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isInUse() {
 | 
				
			||||||
 | 
					        return !this.getViewers().isEmpty();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOffline() {
 | 
				
			||||||
 | 
					        this.playerOnline = false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOnline(@NotNull final Player player) {
 | 
				
			||||||
 | 
					        if (!this.playerOnline) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                this.owner = PlayerDataManager.getHandle(player);
 | 
				
			||||||
 | 
					                InventoryEnderChest enderChest = owner.getEnderChest();
 | 
				
			||||||
 | 
					                for (int i = 0; i < enderChest.getSize(); ++i) {
 | 
				
			||||||
 | 
					                    enderChest.setItem(i, this.items.get(i));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                this.items = enderChest.items;
 | 
				
			||||||
 | 
					            } catch (Exception ignored) {}
 | 
				
			||||||
 | 
					            this.playerOnline = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void update() {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().update();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<ItemStack> getContents() {
 | 
				
			||||||
 | 
					        return this.items;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onOpen(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().onOpen(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onClose(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().onClose(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<HumanEntity> getViewers() {
 | 
				
			||||||
 | 
					        return this.owner.getEnderChest().getViewers();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setMaxStackSize(int i) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().setMaxStackSize(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public InventoryHolder getOwner() {
 | 
				
			||||||
 | 
					        return this.owner.getEnderChest().getOwner();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Location getLocation() {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void a(IInventoryListener iinventorylistener) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().a(iinventorylistener);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void b(IInventoryListener iinventorylistener) {
 | 
				
			||||||
 | 
					        this.owner.getEnderChest().b(iinventorylistener);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack getItem(int i) {
 | 
				
			||||||
 | 
					        return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack splitStack(int i, int j) {
 | 
				
			||||||
 | 
					        ItemStack itemstack = ContainerUtil.a(this.items, i, j);
 | 
				
			||||||
 | 
					        if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					            this.update();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return itemstack;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack a(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        ItemStack itemstack1 = itemstack.cloneItemStack();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (int i = 0; i < this.getSize(); ++i) {
 | 
				
			||||||
 | 
					            ItemStack itemstack2 = this.getItem(i);
 | 
				
			||||||
 | 
					            if (itemstack2.isEmpty()) {
 | 
				
			||||||
 | 
					                this.setItem(i, itemstack1);
 | 
				
			||||||
 | 
					                this.update();
 | 
				
			||||||
 | 
					                return ItemStack.a;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (ItemStack.c(itemstack2, itemstack1)) {
 | 
				
			||||||
 | 
					                int j = Math.min(this.getMaxStackSize(), itemstack2.getMaxStackSize());
 | 
				
			||||||
 | 
					                int k = Math.min(itemstack1.getCount(), j - itemstack2.getCount());
 | 
				
			||||||
 | 
					                if (k > 0) {
 | 
				
			||||||
 | 
					                    itemstack2.add(k);
 | 
				
			||||||
 | 
					                    itemstack1.subtract(k);
 | 
				
			||||||
 | 
					                    if (itemstack1.isEmpty()) {
 | 
				
			||||||
 | 
					                        this.update();
 | 
				
			||||||
 | 
					                        return ItemStack.a;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (itemstack1.getCount() != itemstack.getCount()) {
 | 
				
			||||||
 | 
					            this.update();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return itemstack1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack splitWithoutUpdate(int i) {
 | 
				
			||||||
 | 
					        ItemStack itemstack = this.items.get(i);
 | 
				
			||||||
 | 
					        if (itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            this.items.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					            return itemstack;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setItem(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        this.items.set(i, itemstack);
 | 
				
			||||||
 | 
					        if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) {
 | 
				
			||||||
 | 
					            itemstack.setCount(this.getMaxStackSize());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.update();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int getSize() {
 | 
				
			||||||
 | 
					        return this.owner.getEnderChest().getSize();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isNotEmpty() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int getMaxStackSize() {
 | 
				
			||||||
 | 
					        return 64;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean a(EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void startOpen(EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void closeContainer(EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean b(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void clear() {
 | 
				
			||||||
 | 
					        this.items.clear();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
 | 
					            autorecipestackmanager.b(itemstack);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,754 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2011-2019 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_14_R1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.collect.ImmutableList;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
				
			||||||
 | 
					import com.lishid.openinv.util.Pair;
 | 
				
			||||||
 | 
					import com.lishid.openinv.util.SingleFieldList;
 | 
				
			||||||
 | 
					import java.util.Iterator;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.function.Predicate;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.AutoRecipeStackManager;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ChatMessage;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ContainerUtil;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.CrashReport;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.CrashReportSystemDetails;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.EnumItemSlot;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.IBlockData;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.IChatBaseComponent;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.IInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.Item;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ItemArmor;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ItemStack;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.NBTTagCompound;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.NBTTagList;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.PacketPlayOutSetSlot;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.PlayerInventory;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.ReportedException;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_14_R1.World;
 | 
				
			||||||
 | 
					import org.bukkit.Location;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCrafting;
 | 
				
			||||||
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final CraftInventory inventory;
 | 
				
			||||||
 | 
					    private boolean playerOnline;
 | 
				
			||||||
 | 
					    private EntityHuman player;
 | 
				
			||||||
 | 
					    private List<ItemStack> items, armor, extraSlots, crafting;
 | 
				
			||||||
 | 
					    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") // Backing field is mutable.
 | 
				
			||||||
 | 
					    // TODO: cursor requires an additional slot listener
 | 
				
			||||||
 | 
					    private final List<ItemStack> cursor = new SingleFieldList<>(this::getCarried, this::setCarried);
 | 
				
			||||||
 | 
					    private List<List<ItemStack>> f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
 | 
				
			||||||
 | 
					        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
				
			||||||
 | 
					        this.inventory = new CraftInventory(this);
 | 
				
			||||||
 | 
					        this.playerOnline = online;
 | 
				
			||||||
 | 
					        this.player = super.player;
 | 
				
			||||||
 | 
					        this.items = this.player.inventory.items;
 | 
				
			||||||
 | 
					        this.armor = this.player.inventory.armor;
 | 
				
			||||||
 | 
					        this.extraSlots = this.player.inventory.extraSlots;
 | 
				
			||||||
 | 
					        this.crafting = this.getCrafting().getContents();
 | 
				
			||||||
 | 
					        this.f = ImmutableList.of(this.items, this.armor, this.extraSlots, this.crafting, this.cursor);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private IInventory getCrafting() {
 | 
				
			||||||
 | 
					        return ((CraftInventoryCrafting) this.player.defaultContainer.getBukkitView().getTopInventory()).getInventory();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOnline(@NotNull final Player player) {
 | 
				
			||||||
 | 
					        if (!this.playerOnline) {
 | 
				
			||||||
 | 
					            EntityPlayer entityPlayer = PlayerDataManager.getHandle(player);
 | 
				
			||||||
 | 
					            entityPlayer.inventory.transaction.addAll(this.transaction);
 | 
				
			||||||
 | 
					            this.player = entityPlayer;
 | 
				
			||||||
 | 
					            for (int i = 0; i < getSize(); ++i) {
 | 
				
			||||||
 | 
					                this.player.inventory.setItem(i, getRawItem(i));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            // Crafting/cursor are not insertable while player is offline and do not need special treatment.
 | 
				
			||||||
 | 
					            this.player.inventory.itemInHandIndex = this.itemInHandIndex;
 | 
				
			||||||
 | 
					            this.items = this.player.inventory.items;
 | 
				
			||||||
 | 
					            this.armor = this.player.inventory.armor;
 | 
				
			||||||
 | 
					            this.extraSlots = this.player.inventory.extraSlots;
 | 
				
			||||||
 | 
					            this.crafting = this.getCrafting().getContents();
 | 
				
			||||||
 | 
					            this.f = ImmutableList.of(this.items, this.armor, this.extraSlots, this.crafting, this.cursor);
 | 
				
			||||||
 | 
					            this.playerOnline = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean a(final EntityHuman entityhuman) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public @NotNull CraftInventory getBukkitInventory() {
 | 
				
			||||||
 | 
					        return this.inventory;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack getItem(int i) {
 | 
				
			||||||
 | 
					        List<ItemStack> list = this.items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.armor;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            i = this.getReversedItemSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					            list = this.extraSlots;
 | 
				
			||||||
 | 
					        } else if (list == this.armor) {
 | 
				
			||||||
 | 
					            i = this.getReversedArmorSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return list.get(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private ItemStack getRawItem(int i) {
 | 
				
			||||||
 | 
					        List<ItemStack> list = null;
 | 
				
			||||||
 | 
					        for (List<ItemStack> next : this.f) {
 | 
				
			||||||
 | 
					            if (i < next.size()) {
 | 
				
			||||||
 | 
					                list = next;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            i -= next.size();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return list == null ? ItemStack.a : list.get(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public IChatBaseComponent getDisplayName() {
 | 
				
			||||||
 | 
					        return new ChatMessage(this.player.getName());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean hasCustomName() {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int getReversedArmorSlotNum(final int i) {
 | 
				
			||||||
 | 
					        if (i == 0) {
 | 
				
			||||||
 | 
					            return 3;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (i == 1) {
 | 
				
			||||||
 | 
					            return 2;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (i == 2) {
 | 
				
			||||||
 | 
					            return 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (i == 3) {
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return i;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int getReversedItemSlotNum(final int i) {
 | 
				
			||||||
 | 
					        if (i >= 27) {
 | 
				
			||||||
 | 
					            return i - 27;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return i + 9;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int getSize() {
 | 
				
			||||||
 | 
					        return 54;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isInUse() {
 | 
				
			||||||
 | 
					        return !this.getViewers().isEmpty();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Pair<List<ItemStack>, Integer> getLocalizedIndex(int i) {
 | 
				
			||||||
 | 
					        List<ItemStack> localList = null;
 | 
				
			||||||
 | 
					        for (List<ItemStack> list : this.f) {
 | 
				
			||||||
 | 
					            if (i < list.size()) {
 | 
				
			||||||
 | 
					                localList = list;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            i -= list.size();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (localList == this.armor) {
 | 
				
			||||||
 | 
					            i = this.getReversedArmorSlotNum(i);
 | 
				
			||||||
 | 
					        } else if (localList == this.items) {
 | 
				
			||||||
 | 
					            i = this.getReversedItemSlotNum(i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return new Pair<>(localList, i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setItem(int i, final ItemStack itemstack) {
 | 
				
			||||||
 | 
					        Pair<List<ItemStack>, Integer> localizedIndex = getLocalizedIndex(i);
 | 
				
			||||||
 | 
					        if (localizedIndex.getLeft() == null
 | 
				
			||||||
 | 
					                // TODO: should this be a constant instead of comparing to transient slot containers?
 | 
				
			||||||
 | 
					                || !playerOnline && (localizedIndex.getLeft() == crafting || localizedIndex.getLeft() == cursor)) {
 | 
				
			||||||
 | 
					            this.player.drop(itemstack, true);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            localizedIndex.getLeft().set(localizedIndex.getRight(), itemstack);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPlayerOffline() {
 | 
				
			||||||
 | 
					        this.playerOnline = false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack splitStack(int i, final int j) {
 | 
				
			||||||
 | 
					        Pair<List<ItemStack>, Integer> localizedIndex = getLocalizedIndex(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (localizedIndex.getLeft() == null) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return localizedIndex.getLeft().get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(localizedIndex.getLeft(), localizedIndex.getRight(), j);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack splitWithoutUpdate(int i) {
 | 
				
			||||||
 | 
					        Pair<List<ItemStack>, Integer> localizedIndex = getLocalizedIndex(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (localizedIndex.getLeft() == null) {
 | 
				
			||||||
 | 
					            return ItemStack.a;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        List<ItemStack> list = localizedIndex.getLeft();
 | 
				
			||||||
 | 
					        i = localizedIndex.getRight();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!list.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					            ItemStack itemstack = list.get(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            list.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					            return itemstack;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return ItemStack.a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<ItemStack> getContents() {
 | 
				
			||||||
 | 
					        return this.f.stream().flatMap(List::stream).collect(Collectors.toList());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<ItemStack> getArmorContents() {
 | 
				
			||||||
 | 
					        return this.armor;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onOpen(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.transaction.add(who);
 | 
				
			||||||
 | 
					        this.getCrafting().getViewers().add(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onClose(CraftHumanEntity who) {
 | 
				
			||||||
 | 
					        this.transaction.remove(who);
 | 
				
			||||||
 | 
					        this.getCrafting().getViewers().remove(who);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<HumanEntity> getViewers() {
 | 
				
			||||||
 | 
					        return this.transaction;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public InventoryHolder getOwner() {
 | 
				
			||||||
 | 
					        return this.player.getBukkitEntity();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Location getLocation() {
 | 
				
			||||||
 | 
					        return this.player.getBukkitEntity().getLocation();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public ItemStack getItemInHand() {
 | 
				
			||||||
 | 
					        return d(this.itemInHandIndex) ? this.items.get(this.itemInHandIndex) : ItemStack.a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean a(ItemStack itemstack, ItemStack itemstack1) {
 | 
				
			||||||
 | 
					        return !itemstack.isEmpty() && this.b(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < itemstack.getMaxStackSize() && itemstack.getCount() < this.getMaxStackSize();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean b(ItemStack itemstack, ItemStack itemstack1) {
 | 
				
			||||||
 | 
					        return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int canHold(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        int remains = itemstack.getCount();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            ItemStack itemstack1 = this.getItem(i);
 | 
				
			||||||
 | 
					            if (itemstack1.isEmpty()) {
 | 
				
			||||||
 | 
					                return itemstack.getCount();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!this.a(itemstack, itemstack1)) {
 | 
				
			||||||
 | 
					                remains -= Math.min(itemstack1.getMaxStackSize(), this.getMaxStackSize()) - itemstack1.getCount();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (remains <= 0) {
 | 
				
			||||||
 | 
					                return itemstack.getCount();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return itemstack.getCount() - remains;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int getFirstEmptySlotIndex() {
 | 
				
			||||||
 | 
					        for (int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            if (this.items.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void c(int i) {
 | 
				
			||||||
 | 
					        this.itemInHandIndex = this.i();
 | 
				
			||||||
 | 
					        ItemStack itemstack = this.items.get(this.itemInHandIndex);
 | 
				
			||||||
 | 
					        this.items.set(this.itemInHandIndex, this.items.get(i));
 | 
				
			||||||
 | 
					        this.items.set(i, itemstack);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int c(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        for (int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            ItemStack itemstack1 = this.items.get(i);
 | 
				
			||||||
 | 
					            if (!this.items.get(i).isEmpty() && this.b(itemstack, this.items.get(i)) && !this.items.get(i).f() && !itemstack1.hasEnchantments() && !itemstack1.hasName()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int i() {
 | 
				
			||||||
 | 
					        int i;
 | 
				
			||||||
 | 
					        int j;
 | 
				
			||||||
 | 
					        for (j = 0; j < 9; ++j) {
 | 
				
			||||||
 | 
					            i = (this.itemInHandIndex + j) % 9;
 | 
				
			||||||
 | 
					            if (this.items.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (j = 0; j < 9; ++j) {
 | 
				
			||||||
 | 
					            i = (this.itemInHandIndex + j) % 9;
 | 
				
			||||||
 | 
					            if (!this.items.get(i).hasEnchantments()) {
 | 
				
			||||||
 | 
					                return i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return this.itemInHandIndex;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int a(Predicate<ItemStack> predicate, int i) {
 | 
				
			||||||
 | 
					        int j = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int k;
 | 
				
			||||||
 | 
					        for (k = 0; k < this.getSize(); ++k) {
 | 
				
			||||||
 | 
					            ItemStack itemstack = this.getItem(k);
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty() && predicate.test(itemstack)) {
 | 
				
			||||||
 | 
					                int l = i <= 0 ? itemstack.getCount() : Math.min(i - j, itemstack.getCount());
 | 
				
			||||||
 | 
					                j += l;
 | 
				
			||||||
 | 
					                if (i != 0) {
 | 
				
			||||||
 | 
					                    itemstack.subtract(l);
 | 
				
			||||||
 | 
					                    if (itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                        this.setItem(k, ItemStack.a);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (i > 0 && j >= i) {
 | 
				
			||||||
 | 
					                        return j;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!this.getCarried().isEmpty() && predicate.test(this.getCarried())) {
 | 
				
			||||||
 | 
					            k = i <= 0 ? this.getCarried().getCount() : Math.min(i - j, this.getCarried().getCount());
 | 
				
			||||||
 | 
					            j += k;
 | 
				
			||||||
 | 
					            if (i != 0) {
 | 
				
			||||||
 | 
					                this.getCarried().subtract(k);
 | 
				
			||||||
 | 
					                if (this.getCarried().isEmpty()) {
 | 
				
			||||||
 | 
					                    this.setCarried(ItemStack.a);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (i > 0 && j >= i) {
 | 
				
			||||||
 | 
					                    return j;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return j;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int i(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        int i = this.firstPartial(itemstack);
 | 
				
			||||||
 | 
					        if (i == -1) {
 | 
				
			||||||
 | 
					            i = this.getFirstEmptySlotIndex();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return i == -1 ? itemstack.getCount() : this.d(i, itemstack);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int d(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        Item item = itemstack.getItem();
 | 
				
			||||||
 | 
					        int j = itemstack.getCount();
 | 
				
			||||||
 | 
					        ItemStack itemstack1 = this.getItem(i);
 | 
				
			||||||
 | 
					        if (itemstack1.isEmpty()) {
 | 
				
			||||||
 | 
					            itemstack1 = new ItemStack(item, 0);
 | 
				
			||||||
 | 
					            if (itemstack.hasTag()) {
 | 
				
			||||||
 | 
					                itemstack1.setTag(itemstack.getTag().clone());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            this.setItem(i, itemstack1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int k = j;
 | 
				
			||||||
 | 
					        if (j > itemstack1.getMaxStackSize() - itemstack1.getCount()) {
 | 
				
			||||||
 | 
					            k = itemstack1.getMaxStackSize() - itemstack1.getCount();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (k > this.getMaxStackSize() - itemstack1.getCount()) {
 | 
				
			||||||
 | 
					            k = this.getMaxStackSize() - itemstack1.getCount();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (k == 0) {
 | 
				
			||||||
 | 
					            return j;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            j -= k;
 | 
				
			||||||
 | 
					            itemstack1.add(k);
 | 
				
			||||||
 | 
					            itemstack1.d(5);
 | 
				
			||||||
 | 
					            return j;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int firstPartial(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        if (this.a(this.getItem(this.itemInHandIndex), itemstack)) {
 | 
				
			||||||
 | 
					            return this.itemInHandIndex;
 | 
				
			||||||
 | 
					        } else if (this.a(this.getItem(40), itemstack)) {
 | 
				
			||||||
 | 
					            return 40;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            for (int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					                if (this.a(this.items.get(i), itemstack)) {
 | 
				
			||||||
 | 
					                    return i;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return -1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void j() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (List<ItemStack> itemStacks : this.f) {
 | 
				
			||||||
 | 
					            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
				
			||||||
 | 
					                if (!itemStacks.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                    itemStacks.get(i).a(this.player.world, this.player, i, this.itemInHandIndex == i);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean pickup(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        return this.c(-1, itemstack);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean c(int i, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        if (itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                if (itemstack.f()) {
 | 
				
			||||||
 | 
					                    if (i == -1) {
 | 
				
			||||||
 | 
					                        i = this.getFirstEmptySlotIndex();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (i >= 0) {
 | 
				
			||||||
 | 
					                        this.items.set(i, itemstack.cloneItemStack());
 | 
				
			||||||
 | 
					                        this.items.get(i).d(5);
 | 
				
			||||||
 | 
					                        itemstack.setCount(0);
 | 
				
			||||||
 | 
					                        return true;
 | 
				
			||||||
 | 
					                    } else if (this.player.abilities.canInstantlyBuild) {
 | 
				
			||||||
 | 
					                        itemstack.setCount(0);
 | 
				
			||||||
 | 
					                        return true;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        return false;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    int j;
 | 
				
			||||||
 | 
					                    do {
 | 
				
			||||||
 | 
					                        j = itemstack.getCount();
 | 
				
			||||||
 | 
					                        if (i == -1) {
 | 
				
			||||||
 | 
					                            itemstack.setCount(this.i(itemstack));
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            itemstack.setCount(this.d(i, itemstack));
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    } while(!itemstack.isEmpty() && itemstack.getCount() < j);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (itemstack.getCount() == j && this.player.abilities.canInstantlyBuild) {
 | 
				
			||||||
 | 
					                        itemstack.setCount(0);
 | 
				
			||||||
 | 
					                        return true;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        return itemstack.getCount() < j;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } catch (Throwable var6) {
 | 
				
			||||||
 | 
					                CrashReport crashreport = CrashReport.a(var6, "Adding item to inventory");
 | 
				
			||||||
 | 
					                CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Item being added");
 | 
				
			||||||
 | 
					                crashreportsystemdetails.a("Item ID", Item.getId(itemstack.getItem()));
 | 
				
			||||||
 | 
					                crashreportsystemdetails.a("Item data", itemstack.getDamage());
 | 
				
			||||||
 | 
					                crashreportsystemdetails.a("Item name", () -> itemstack.getName().getString());
 | 
				
			||||||
 | 
					                throw new ReportedException(crashreport);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void a(World world, ItemStack itemstack) {
 | 
				
			||||||
 | 
					        if (!world.isClientSide) {
 | 
				
			||||||
 | 
					            while(!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                int i = this.firstPartial(itemstack);
 | 
				
			||||||
 | 
					                if (i == -1) {
 | 
				
			||||||
 | 
					                    i = this.getFirstEmptySlotIndex();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (i == -1) {
 | 
				
			||||||
 | 
					                    this.player.drop(itemstack, false);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                int j = itemstack.getMaxStackSize() - this.getItem(i).getCount();
 | 
				
			||||||
 | 
					                if (this.c(i, itemstack.cloneAndSubtract(j))) {
 | 
				
			||||||
 | 
					                    ((EntityPlayer)this.player).playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, i, this.getItem(i)));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void f(ItemStack itemstack) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (List<ItemStack> list : this.f) {
 | 
				
			||||||
 | 
					            for (int i = 0; i < list.size(); ++i) {
 | 
				
			||||||
 | 
					                if (list.get(i) == itemstack) {
 | 
				
			||||||
 | 
					                    list.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public float a(IBlockData iblockdata) {
 | 
				
			||||||
 | 
					        return this.items.get(this.itemInHandIndex).a(iblockdata);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public NBTTagList a(NBTTagList nbttaglist) {
 | 
				
			||||||
 | 
					        NBTTagCompound nbttagcompound;
 | 
				
			||||||
 | 
					        int i;
 | 
				
			||||||
 | 
					        for (i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
 | 
					            if (!this.items.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                nbttagcompound = new NBTTagCompound();
 | 
				
			||||||
 | 
					                nbttagcompound.setByte("Slot", (byte) i);
 | 
				
			||||||
 | 
					                this.items.get(i).save(nbttagcompound);
 | 
				
			||||||
 | 
					                nbttaglist.add(nbttagcompound);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (i = 0; i < this.armor.size(); ++i) {
 | 
				
			||||||
 | 
					            if (!this.armor.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                nbttagcompound = new NBTTagCompound();
 | 
				
			||||||
 | 
					                nbttagcompound.setByte("Slot", (byte) (i + 100));
 | 
				
			||||||
 | 
					                this.armor.get(i).save(nbttagcompound);
 | 
				
			||||||
 | 
					                nbttaglist.add(nbttagcompound);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (i = 0; i < this.extraSlots.size(); ++i) {
 | 
				
			||||||
 | 
					            if (!this.extraSlots.get(i).isEmpty()) {
 | 
				
			||||||
 | 
					                nbttagcompound = new NBTTagCompound();
 | 
				
			||||||
 | 
					                nbttagcompound.setByte("Slot", (byte) (i + 150));
 | 
				
			||||||
 | 
					                this.extraSlots.get(i).save(nbttagcompound);
 | 
				
			||||||
 | 
					                nbttaglist.add(nbttagcompound);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return nbttaglist;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void b(NBTTagList nbttaglist) {
 | 
				
			||||||
 | 
					        this.items.clear();
 | 
				
			||||||
 | 
					        this.armor.clear();
 | 
				
			||||||
 | 
					        this.extraSlots.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(int i = 0; i < nbttaglist.size(); ++i) {
 | 
				
			||||||
 | 
					            NBTTagCompound nbttagcompound = nbttaglist.getCompound(i);
 | 
				
			||||||
 | 
					            int j = nbttagcompound.getByte("Slot") & 255;
 | 
				
			||||||
 | 
					            ItemStack itemstack = ItemStack.a(nbttagcompound);
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                if (j < this.items.size()) {
 | 
				
			||||||
 | 
					                    this.items.set(j, itemstack);
 | 
				
			||||||
 | 
					                } else if (j >= 100 && j < this.armor.size() + 100) {
 | 
				
			||||||
 | 
					                    this.armor.set(j - 100, itemstack);
 | 
				
			||||||
 | 
					                } else if (j >= 150 && j < this.extraSlots.size() + 150) {
 | 
				
			||||||
 | 
					                    this.extraSlots.set(j - 150, itemstack);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isNotEmpty() {
 | 
				
			||||||
 | 
					        Iterator iterator = this.items.iterator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ItemStack itemstack;
 | 
				
			||||||
 | 
					        while (iterator.hasNext()) {
 | 
				
			||||||
 | 
					            itemstack = (ItemStack)iterator.next();
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        iterator = this.armor.iterator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while (iterator.hasNext()) {
 | 
				
			||||||
 | 
					            itemstack = (ItemStack)iterator.next();
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        iterator = this.extraSlots.iterator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while (iterator.hasNext()) {
 | 
				
			||||||
 | 
					            itemstack = (ItemStack)iterator.next();
 | 
				
			||||||
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Nullable
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public IChatBaseComponent getCustomName() {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean b(IBlockData iblockdata) {
 | 
				
			||||||
 | 
					        return this.getItem(this.itemInHandIndex).b(iblockdata);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void a(float f) {
 | 
				
			||||||
 | 
					        if (f > 0.0F) {
 | 
				
			||||||
 | 
					            f /= 4.0F;
 | 
				
			||||||
 | 
					            if (f < 1.0F) {
 | 
				
			||||||
 | 
					                f = 1.0F;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (int i = 0; i < this.armor.size(); ++i) {
 | 
				
			||||||
 | 
					                ItemStack itemstack = this.armor.get(0);
 | 
				
			||||||
 | 
					                int index = i;
 | 
				
			||||||
 | 
					                if (itemstack.getItem() instanceof ItemArmor) {
 | 
				
			||||||
 | 
					                    itemstack.damage((int) f, this.player, (entityhuman) -> entityhuman.c(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, index)));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void dropContents() {
 | 
				
			||||||
 | 
					        for (List<ItemStack> itemStacks : this.f) {
 | 
				
			||||||
 | 
					            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
				
			||||||
 | 
					                ItemStack itemstack = itemStacks.get(i);
 | 
				
			||||||
 | 
					                if (!itemstack.isEmpty()) {
 | 
				
			||||||
 | 
					                    itemStacks.set(i, ItemStack.a);
 | 
				
			||||||
 | 
					                    this.player.a(itemstack, true, false);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean h(ItemStack itemstack) {
 | 
				
			||||||
 | 
					        return this.f.stream().flatMap(List::stream).anyMatch(itemStack1 -> !itemStack1.isEmpty() && itemStack1.doMaterialsMatch(itemstack));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void a(PlayerInventory playerinventory) {
 | 
				
			||||||
 | 
					        for (int i = 0; i < playerinventory.getSize(); ++i) {
 | 
				
			||||||
 | 
					            this.setItem(i, playerinventory.getItem(i));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.itemInHandIndex = playerinventory.itemInHandIndex;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void clear() {
 | 
				
			||||||
 | 
					        this.f.forEach(List::clear);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
				
			||||||
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
 | 
					            autorecipestackmanager.a(itemstack);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_4_R1</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_4_R1</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>craftbukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.4.7-R1.0</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,171 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.Container;
 | 
					 | 
				
			||||||
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.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.event.CraftEventFactory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block or ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
					 | 
				
			||||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
					 | 
				
			||||||
        return world.t(x, y + 1, z) || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof IInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IInventory inventory = (IInventory) tile;
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer(inventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Call InventoryOpenEvent
 | 
					 | 
				
			||||||
            Container container = new SilentContainerChest(player.inventory, inventory);
 | 
					 | 
				
			||||||
            container = CraftEventFactory.callInventoryOpenEvent(player, container);
 | 
					 | 
				
			||||||
            if (container == null) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Open window
 | 
					 | 
				
			||||||
            int windowId = player.nextContainerCounter();
 | 
					 | 
				
			||||||
            player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize()));
 | 
					 | 
				
			||||||
            player.activeContainer = container;
 | 
					 | 
				
			||||||
            player.activeContainer.windowId = windowId;
 | 
					 | 
				
			||||||
            player.activeContainer.addSlotListener(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            p.sendMessage(ChatColor.RED + "Error while sending silent container.");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,102 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create an entity to load the player data
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
					 | 
				
			||||||
                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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
 | 
					 | 
				
			||||||
        // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
        if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Arrays.asList(Bukkit.getOnlinePlayers());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        // Send close signal
 | 
					 | 
				
			||||||
        i2.f();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman entityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (playerinventory.getCarried() != null) {
 | 
					 | 
				
			||||||
            ItemStack carried = playerinventory.getCarried();
 | 
					 | 
				
			||||||
            playerinventory.setCarried(null);
 | 
					 | 
				
			||||||
            entityHuman.drop(carried);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,130 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 net.minecraft.server.v1_4_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
    private CraftPlayer owner;
 | 
					 | 
				
			||||||
    private int maxStack = MAX_STACK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
					 | 
				
			||||||
                field.setAccessible(true);
 | 
					 | 
				
			||||||
                field.set(playerEnderChest, this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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 void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,235 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.player.inventory.items = this.items;
 | 
					 | 
				
			||||||
            this.player.inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        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
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            player.drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        player.defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_5_R2</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_5_R2</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>craftbukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.5.1-R0.2</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,171 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.Container;
 | 
					 | 
				
			||||||
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.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block or ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
					 | 
				
			||||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
					 | 
				
			||||||
        return world.t(x, y + 1, z) || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof IInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IInventory inventory = (IInventory) tile;
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer(inventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Call InventoryOpenEvent
 | 
					 | 
				
			||||||
            Container container = new SilentContainerChest(player.inventory, inventory);
 | 
					 | 
				
			||||||
            container = CraftEventFactory.callInventoryOpenEvent(player, container);
 | 
					 | 
				
			||||||
            if (container == null) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Open window
 | 
					 | 
				
			||||||
            int windowId = player.nextContainerCounter();
 | 
					 | 
				
			||||||
            player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
 | 
					 | 
				
			||||||
            player.activeContainer = container;
 | 
					 | 
				
			||||||
            player.activeContainer.windowId = windowId;
 | 
					 | 
				
			||||||
            player.activeContainer.addSlotListener(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            p.sendMessage(ChatColor.RED + "Error while sending silent container.");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,101 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create an entity to load the player data
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
					 | 
				
			||||||
                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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
 | 
					 | 
				
			||||||
        // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
        if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Arrays.asList(Bukkit.getOnlinePlayers());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        // Send close signal
 | 
					 | 
				
			||||||
        i2.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman entityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (playerinventory.getCarried() != null) {
 | 
					 | 
				
			||||||
            ItemStack carried = playerinventory.getCarried();
 | 
					 | 
				
			||||||
            playerinventory.setCarried(null);
 | 
					 | 
				
			||||||
            entityHuman.drop(carried);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,131 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 net.minecraft.server.v1_5_R2.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
    private CraftPlayer owner;
 | 
					 | 
				
			||||||
    private int maxStack = MAX_STACK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().c(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
					 | 
				
			||||||
                field.setAccessible(true);
 | 
					 | 
				
			||||||
                field.set(playerEnderChest, this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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 void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,227 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.player.inventory.items = this.items;
 | 
					 | 
				
			||||||
            this.player.inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        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
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            player.drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        player.defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_5_R3</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_5_R3</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>craftbukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.5.2-R1.0</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,171 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.Container;
 | 
					 | 
				
			||||||
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.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.Packet100OpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block or ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
					 | 
				
			||||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
					 | 
				
			||||||
        return world.t(x, y + 1, z) || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof IInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IInventory inventory = (IInventory) tile;
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer(inventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Call InventoryOpenEvent
 | 
					 | 
				
			||||||
            Container container = new SilentContainerChest(player.inventory, inventory);
 | 
					 | 
				
			||||||
            container = CraftEventFactory.callInventoryOpenEvent(player, container);
 | 
					 | 
				
			||||||
            if (container == null) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Open window
 | 
					 | 
				
			||||||
            int windowId = player.nextContainerCounter();
 | 
					 | 
				
			||||||
            player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
 | 
					 | 
				
			||||||
            player.activeContainer = container;
 | 
					 | 
				
			||||||
            player.activeContainer.windowId = windowId;
 | 
					 | 
				
			||||||
            player.activeContainer.addSlotListener(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            p.sendMessage(ChatColor.RED + "Error while sending silent container.");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,101 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create an entity to load the player data
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
					 | 
				
			||||||
                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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
 | 
					 | 
				
			||||||
        // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
        if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Arrays.asList(Bukkit.getOnlinePlayers());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        // Send close signal
 | 
					 | 
				
			||||||
        i2.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman entityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (playerinventory.getCarried() != null) {
 | 
					 | 
				
			||||||
            ItemStack carried = playerinventory.getCarried();
 | 
					 | 
				
			||||||
            playerinventory.setCarried(null);
 | 
					 | 
				
			||||||
            entityHuman.drop(carried);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,131 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 net.minecraft.server.v1_5_R3.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
    private CraftPlayer owner;
 | 
					 | 
				
			||||||
    private int maxStack = MAX_STACK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().c(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
					 | 
				
			||||||
                field.setAccessible(true);
 | 
					 | 
				
			||||||
                field.set(playerEnderChest, this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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 void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,227 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.player.inventory.items = this.items;
 | 
					 | 
				
			||||||
            this.player.inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        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
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            player.drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        player.defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_6_R1</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_6_R1</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>craftbukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.6.1-R0.1-SNAPSHOT</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,171 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.Container;
 | 
					 | 
				
			||||||
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.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.Packet100OpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.event.CraftEventFactory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block or ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
					 | 
				
			||||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
					 | 
				
			||||||
        return world.t(x, y + 1, z) || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof IInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IInventory inventory = (IInventory) tile;
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer(inventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Call InventoryOpenEvent
 | 
					 | 
				
			||||||
            Container container = new SilentContainerChest(player.inventory, inventory);
 | 
					 | 
				
			||||||
            container = CraftEventFactory.callInventoryOpenEvent(player, container);
 | 
					 | 
				
			||||||
            if (container == null) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Open window
 | 
					 | 
				
			||||||
            int windowId = player.nextContainerCounter();
 | 
					 | 
				
			||||||
            player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
 | 
					 | 
				
			||||||
            player.activeContainer = container;
 | 
					 | 
				
			||||||
            player.activeContainer.windowId = windowId;
 | 
					 | 
				
			||||||
            player.activeContainer.addSlotListener(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            p.sendMessage(ChatColor.RED + "Error while sending silent container.");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,101 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create an entity to load the player data
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
					 | 
				
			||||||
                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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
 | 
					 | 
				
			||||||
        // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
        if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Arrays.asList(Bukkit.getOnlinePlayers());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        // Send close signal
 | 
					 | 
				
			||||||
        i2.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman entityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (playerinventory.getCarried() != null) {
 | 
					 | 
				
			||||||
            ItemStack carried = playerinventory.getCarried();
 | 
					 | 
				
			||||||
            playerinventory.setCarried(null);
 | 
					 | 
				
			||||||
            entityHuman.drop(carried);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,131 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 net.minecraft.server.v1_6_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
    private CraftPlayer owner;
 | 
					 | 
				
			||||||
    private int maxStack = MAX_STACK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().c(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
					 | 
				
			||||||
                field.setAccessible(true);
 | 
					 | 
				
			||||||
                field.set(playerEnderChest, this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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 void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,227 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            this.player = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
            this.player.inventory.items = this.items;
 | 
					 | 
				
			||||||
            this.player.inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        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
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        } else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            player.drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        player.defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27) {
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,44 +0,0 @@
 | 
				
			|||||||
<!--
 | 
					 | 
				
			||||||
  ~ Copyright (C) 2011-2018 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/>.
 | 
					 | 
				
			||||||
  -->
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<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>openinvinternal</artifactId>
 | 
					 | 
				
			||||||
    <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
  </parent>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <artifactId>openinvadapter1_6_R2</artifactId>
 | 
					 | 
				
			||||||
  <name>OpenInvAdapter1_6_R2</name>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <dependencies>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>org.bukkit</groupId>
 | 
					 | 
				
			||||||
      <artifactId>craftbukkit</artifactId>
 | 
					 | 
				
			||||||
      <version>1.6.2-R1.0</version>
 | 
					 | 
				
			||||||
      <scope>provided</scope>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
    <dependency>
 | 
					 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					 | 
				
			||||||
      <artifactId>openinvcommon</artifactId>
 | 
					 | 
				
			||||||
      <version>3.3.4-A1</version>
 | 
					 | 
				
			||||||
    </dependency>
 | 
					 | 
				
			||||||
  </dependencies>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -1,171 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.AxisAlignedBB;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.Container;
 | 
					 | 
				
			||||||
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.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.Packet100OpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.World;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (block instanceof BlockEnderChest) {
 | 
					 | 
				
			||||||
            // Ender chests are not blocked by ocelots.
 | 
					 | 
				
			||||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block or ocelot on top
 | 
					 | 
				
			||||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
					 | 
				
			||||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
					 | 
				
			||||||
        return world.t(x, y + 1, z) || 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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer player = PlayerDataManager.getHandle(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Silent ender chest is API-only
 | 
					 | 
				
			||||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
					 | 
				
			||||||
            p.openInventory(p.getEnderChest());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile == null) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (tile instanceof TileEntityEnderChest) {
 | 
					 | 
				
			||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					 | 
				
			||||||
            player.openContainer(enderChest);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!(tile instanceof IInventory)) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IInventory inventory = (IInventory) tile;
 | 
					 | 
				
			||||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
					 | 
				
			||||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
					 | 
				
			||||||
            inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // AnyChest only
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer(inventory);
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // SilentChest
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Call InventoryOpenEvent
 | 
					 | 
				
			||||||
            Container container = new SilentContainerChest(player.inventory, inventory);
 | 
					 | 
				
			||||||
            container = CraftEventFactory.callInventoryOpenEvent(player, container);
 | 
					 | 
				
			||||||
            if (container == null) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Open window
 | 
					 | 
				
			||||||
            int windowId = player.nextContainerCounter();
 | 
					 | 
				
			||||||
            player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
 | 
					 | 
				
			||||||
            player.activeContainer = container;
 | 
					 | 
				
			||||||
            player.activeContainer.windowId = windowId;
 | 
					 | 
				
			||||||
            player.activeContainer.addSlotListener(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (Exception e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            p.sendMessage(ChatColor.RED + "Error while sending silent container.");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void deactivateContainer(final Player bukkitPlayer) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,78 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.IInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            return (SpecialPlayerInventory) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
					 | 
				
			||||||
        IInventory inv;
 | 
					 | 
				
			||||||
        if (inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            return (SpecialEnderChest) inv;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,101 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.PlayerInteractManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the player has data
 | 
					 | 
				
			||||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create an entity to load the player data
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
					 | 
				
			||||||
                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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getPlayerDataID(OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        return offline.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public OfflinePlayer getPlayerByID(String identifier) {
 | 
					 | 
				
			||||||
        OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
 | 
					 | 
				
			||||||
        // Ensure player is a real player, otherwise return null
 | 
					 | 
				
			||||||
        if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Collection<? extends Player> getOnlinePlayers() {
 | 
					 | 
				
			||||||
        return Arrays.asList(Bukkit.getOnlinePlayers());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Server server = player.getServer();
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (server instanceof CraftServer) {
 | 
					 | 
				
			||||||
            nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer == null) {
 | 
					 | 
				
			||||||
            // Could use reflection to examine fields, but it's honestly not worth the bother.
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return nmsPlayer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.ItemStack;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.PlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        // Send close signal
 | 
					 | 
				
			||||||
        i2.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman entityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (playerinventory.getCarried() != null) {
 | 
					 | 
				
			||||||
            ItemStack carried = playerinventory.getCarried();
 | 
					 | 
				
			||||||
            playerinventory.setCarried(null);
 | 
					 | 
				
			||||||
            entityHuman.drop(carried);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,131 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2018 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_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 net.minecraft.server.v1_6_R2.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.IInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.InventorySubcontainer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.ItemStack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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 SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final InventoryEnderChest enderChest;
 | 
					 | 
				
			||||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
					 | 
				
			||||||
    private boolean playerOnline;
 | 
					 | 
				
			||||||
    private CraftPlayer owner;
 | 
					 | 
				
			||||||
    private int maxStack = MAX_STACK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
					 | 
				
			||||||
        super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().c(),
 | 
					 | 
				
			||||||
                PlayerDataManager.getHandle(player).getEnderChest().getSize());
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
        this.enderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
 | 
					 | 
				
			||||||
                this.owner = nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
                InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
 | 
					 | 
				
			||||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
					 | 
				
			||||||
                field.setAccessible(true);
 | 
					 | 
				
			||||||
                field.set(playerEnderChest, this.items);
 | 
					 | 
				
			||||||
            } catch (Exception e) {}
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setPlayerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean isInUse() {
 | 
					 | 
				
			||||||
        return !this.getViewers().isEmpty();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @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 void update() {
 | 
					 | 
				
			||||||
        super.update();
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user