Compare commits
	
		
			4 Commits
		
	
	
		
			4.1.1
			...
			feature/cu
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					1dd28ac0eb | ||
| 
						 | 
					ff76f2b95a | ||
| 
						 | 
					b92543e078 | ||
| 
						 | 
					252ca34e42 | 
@@ -80,14 +80,6 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
 | 
				
			|||||||
    <td>OpenInv.editinv</td>
 | 
					    <td>OpenInv.editinv</td>
 | 
				
			||||||
    <td>Required to make changes to open inventories.</td>
 | 
					    <td>Required to make changes to open inventories.</td>
 | 
				
			||||||
  </tr>
 | 
					  </tr>
 | 
				
			||||||
  <tr>
 | 
					 | 
				
			||||||
      <td>OpenInv.openonline</td>
 | 
					 | 
				
			||||||
      <td>Allows users to open online players' inventories. For compatibility reasons this is granted by the nodes OpenInv.openinv and OpenInv.openender.</td>
 | 
					 | 
				
			||||||
  </tr>
 | 
					 | 
				
			||||||
  <tr>
 | 
					 | 
				
			||||||
      <td>OpenInv.openoffline</td>
 | 
					 | 
				
			||||||
      <td>Allows users to open offline players' inventories. For compatibility reasons this is granted by the nodes OpenInv.openinv and OpenInv.openender.</td>
 | 
					 | 
				
			||||||
  </tr>
 | 
					 | 
				
			||||||
  <tr>
 | 
					  <tr>
 | 
				
			||||||
    <td>OpenInv.openender</td>
 | 
					    <td>OpenInv.openender</td>
 | 
				
			||||||
    <td>Required to use /openender.</td>
 | 
					    <td>Required to use /openender.</td>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								api/pom.xml
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								api/pom.xml
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2020 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>4.1.2-SNAPSHOT</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvapi</artifactId>
 | 
					  <artifactId>openinvapi</artifactId>
 | 
				
			||||||
@@ -43,6 +43,23 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  <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.8.1</version>
 | 
					        <version>3.8.1</version>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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-2020 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-2020 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-2020 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-2020 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-2020 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-2020 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-2020 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-2020 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>4.1.2-SNAPSHOT</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvassembly</artifactId>
 | 
					  <artifactId>openinvassembly</artifactId>
 | 
				
			||||||
@@ -34,7 +34,7 @@
 | 
				
			|||||||
    <plugins>
 | 
					    <plugins>
 | 
				
			||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <artifactId>maven-assembly-plugin</artifactId>
 | 
					        <artifactId>maven-assembly-plugin</artifactId>
 | 
				
			||||||
        <version>3.2.0</version>
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
        <executions>
 | 
					        <executions>
 | 
				
			||||||
          <execution>
 | 
					          <execution>
 | 
				
			||||||
            <id>reactor-uberjar</id>
 | 
					            <id>reactor-uberjar</id>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2020 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
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										74
									
								
								common/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								common/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
				
			|||||||
 | 
					<!--
 | 
				
			||||||
 | 
					  ~ 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/>.
 | 
				
			||||||
 | 
					  -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
				
			||||||
 | 
					    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
				
			||||||
 | 
					  <modelVersion>4.0.0</modelVersion>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <parent>
 | 
				
			||||||
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
 | 
					    <artifactId>openinvparent</artifactId>
 | 
				
			||||||
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
 | 
					  <name>OpenInvCommon</name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <dependencies>
 | 
				
			||||||
 | 
					    <dependency>
 | 
				
			||||||
 | 
					      <groupId>com.lishid</groupId>
 | 
				
			||||||
 | 
					      <artifactId>openinvapi</artifactId>
 | 
				
			||||||
 | 
					      <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>
 | 
				
			||||||
 | 
					  </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>
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -32,16 +32,7 @@ public interface IPlayerDataManager {
 | 
				
			|||||||
     * @param offline the OfflinePlayer
 | 
					     * @param offline the OfflinePlayer
 | 
				
			||||||
     * @return the Player loaded
 | 
					     * @return the Player loaded
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nullable
 | 
					    @Nullable Player loadPlayer(@NotNull OfflinePlayer offline);
 | 
				
			||||||
    Player loadPlayer(@NotNull OfflinePlayer offline);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Creates a new Player from an existing one that will function slightly better offline.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return the Player
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    Player inject(@NotNull Player player);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Opens an ISpecialInventory for a Player.
 | 
					     * Opens an ISpecialInventory for a Player.
 | 
				
			||||||
@@ -51,14 +42,6 @@ public interface IPlayerDataManager {
 | 
				
			|||||||
     *`
 | 
					     *`
 | 
				
			||||||
     * @return the InventoryView opened
 | 
					     * @return the InventoryView opened
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
 | 
					    InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void sendSystemMessage(@NotNull Player player, @NotNull String message);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    default String getLocale(Player player) {
 | 
					 | 
				
			||||||
        return player.getLocale();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -24,7 +24,6 @@ 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 java.util.Objects;
 | 
				
			||||||
import java.util.function.Function;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 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.
 | 
				
			||||||
@@ -36,7 +35,7 @@ public class Cache<K, V> {
 | 
				
			|||||||
    private final Map<K, V> internal;
 | 
					    private final Map<K, V> internal;
 | 
				
			||||||
    private final Multimap<Long, K> expiry;
 | 
					    private final Multimap<Long, K> expiry;
 | 
				
			||||||
    private final long retention;
 | 
					    private final long retention;
 | 
				
			||||||
    private final Function<V, Boolean> inUseCheck, postRemoval;
 | 
					    private final Function<V> inUseCheck, postRemoval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Constructs a Cache with the specified retention duration, in use function, and post-removal function.
 | 
					     * Constructs a Cache with the specified retention duration, in use function, and post-removal function.
 | 
				
			||||||
@@ -45,7 +44,7 @@ public class Cache<K, V> {
 | 
				
			|||||||
     * @param inUseCheck Function used to check if a key is considered in use
 | 
					     * @param inUseCheck Function used to check if a key is considered in use
 | 
				
			||||||
     * @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, Boolean> inUseCheck, final Function<V, Boolean> postRemoval) {
 | 
					    public Cache(final long retention, final Function<V> inUseCheck, final Function<V> postRemoval) {
 | 
				
			||||||
        this.internal = new HashMap<>();
 | 
					        this.internal = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.expiry = TreeMultimap.create(Long::compareTo, (k1, k2) -> Objects.equals(k1, k2) ? 0 : 1);
 | 
					        this.expiry = TreeMultimap.create(Long::compareTo, (k1, k2) -> Objects.equals(k1, k2) ? 0 : 1);
 | 
				
			||||||
@@ -136,7 +135,7 @@ public class Cache<K, V> {
 | 
				
			|||||||
    public void invalidateAll() {
 | 
					    public void invalidateAll() {
 | 
				
			||||||
        synchronized (this.internal) {
 | 
					        synchronized (this.internal) {
 | 
				
			||||||
            for (V value : this.internal.values()) {
 | 
					            for (V value : this.internal.values()) {
 | 
				
			||||||
                this.postRemoval.apply(value);
 | 
					                this.postRemoval.run(value);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            this.expiry.clear();
 | 
					            this.expiry.clear();
 | 
				
			||||||
            this.internal.clear();
 | 
					            this.internal.clear();
 | 
				
			||||||
@@ -161,7 +160,7 @@ public class Cache<K, V> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                iterator.remove();
 | 
					                iterator.remove();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (this.inUseCheck.apply(this.internal.get(entry.getValue()))) {
 | 
					                if (this.inUseCheck.run(this.internal.get(entry.getValue()))) {
 | 
				
			||||||
                    inUse.add(entry.getValue());
 | 
					                    inUse.add(entry.getValue());
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -172,7 +171,7 @@ public class Cache<K, V> {
 | 
				
			|||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                this.postRemoval.apply(value);
 | 
					                this.postRemoval.run(value);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            long nextExpiry = now + this.retention;
 | 
					            long nextExpiry = now + this.retention;
 | 
				
			||||||
							
								
								
									
										28
									
								
								common/src/main/java/com/lishid/openinv/util/Function.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								common/src/main/java/com/lishid/openinv/util/Function.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Abstraction for some simple cache calls.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Jikoo
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public abstract class Function<V> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public abstract boolean run(V value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
							
								
								
									
										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-2020 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
 | 
				
			||||||
@@ -33,9 +33,7 @@ public enum Permissions {
 | 
				
			|||||||
    SEARCH("search"),
 | 
					    SEARCH("search"),
 | 
				
			||||||
    EDITINV("editinv"),
 | 
					    EDITINV("editinv"),
 | 
				
			||||||
    EDITENDER("editender"),
 | 
					    EDITENDER("editender"),
 | 
				
			||||||
    OPENSELF("openself"),
 | 
					    OPENSELF("openself");
 | 
				
			||||||
    OPENONLINE("openonline"),
 | 
					 | 
				
			||||||
    OPENOFFLINE("openoffline");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final String permission;
 | 
					    private final String permission;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -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,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2020 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>4.1.2-SNAPSHOT</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvinternal</artifactId>
 | 
					  <artifactId>openinvinternal</artifactId>
 | 
				
			||||||
@@ -34,8 +34,8 @@
 | 
				
			|||||||
      <id>all</id>
 | 
					      <id>all</id>
 | 
				
			||||||
      <modules>
 | 
					      <modules>
 | 
				
			||||||
        <module>v1_8_R3</module>
 | 
					        <module>v1_8_R3</module>
 | 
				
			||||||
 | 
					        <module>v1_13_R2</module>
 | 
				
			||||||
        <module>v1_14_R1</module>
 | 
					        <module>v1_14_R1</module>
 | 
				
			||||||
        <module>v1_15_R1</module>
 | 
					 | 
				
			||||||
      </modules>
 | 
					      </modules>
 | 
				
			||||||
    </profile>
 | 
					    </profile>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,5 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					 | 
				
			||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -22,23 +21,23 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvinternal</artifactId>
 | 
					    <artifactId>openinvinternal</artifactId>
 | 
				
			||||||
    <version>4.1.2-SNAPSHOT</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvadapter1_15_R1</artifactId>
 | 
					  <artifactId>openinvadapter1_13_R2</artifactId>
 | 
				
			||||||
  <name>OpenInvAdapter1_15_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.15.1-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>openinvplugincore</artifactId>
 | 
					      <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
      <version>4.1.2-SNAPSHOT</version>
 | 
					      <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -47,7 +46,7 @@
 | 
				
			|||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <groupId>org.apache.maven.plugins</groupId>
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
        <artifactId>maven-shade-plugin</artifactId>
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
        <version>3.2.2</version>
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <minimizeJar>true</minimizeJar>
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
        </configuration>
 | 
					        </configuration>
 | 
				
			||||||
@@ -0,0 +1,309 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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.IAnySilentContainer;
 | 
				
			||||||
 | 
					import java.lang.reflect.Field;
 | 
				
			||||||
 | 
					import java.lang.reflect.InvocationTargetException;
 | 
				
			||||||
 | 
					import java.lang.reflect.Method;
 | 
				
			||||||
 | 
					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.Statistic;
 | 
				
			||||||
 | 
					import org.bukkit.block.BlockState;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
 | 
					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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isAnyContainerNeeded(@NotNull final Player bukkitPlayer, @NotNull final org.bukkit.block.Block bukkitBlock) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        World world = PlayerDataManager.getHandle(bukkitPlayer).world;
 | 
				
			||||||
 | 
					        BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.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()).isOccluding();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 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
 | 
				
			||||||
 | 
					        BlockPropertyChestType chestType = blockData.get(BlockChest.b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (chestType == BlockPropertyChestType.SINGLE) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.k(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)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return this.isBlockedChest(world, adjacentBlockPosition);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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).r() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
 | 
				
			||||||
 | 
					            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())
 | 
				
			||||||
 | 
					                    .a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(), enumDirection.getAdjacentZ());
 | 
				
			||||||
 | 
					            return !world.getCubes(null, 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()).isOccluding() || this.hasOcelotOnTop(world, blockPosition);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean hasOcelotOnTop(final World world, final BlockPosition blockPosition) {
 | 
				
			||||||
 | 
					        for (Entity entity : world.a(EntityOcelot.class,
 | 
				
			||||||
 | 
					                new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
 | 
				
			||||||
 | 
					                        blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
 | 
				
			||||||
 | 
					                        blockPosition.getZ() + 1))) {
 | 
				
			||||||
 | 
					            EntityOcelot entityOcelot = (EntityOcelot) entity;
 | 
				
			||||||
 | 
					            if (entityOcelot.isSitting()) {
 | 
				
			||||||
 | 
					                return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean activateContainer(@NotNull final Player bukkitPlayer, final boolean silent,
 | 
				
			||||||
 | 
					                                     @NotNull final org.bukkit.block.Block bukkitBlock) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Silent ender chest is API-only
 | 
				
			||||||
 | 
					        if (silent && 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;
 | 
				
			||||||
 | 
					        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.k(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) {
 | 
				
			||||||
 | 
					                            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);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            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);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
 | 
				
			||||||
 | 
					        if (!silent || 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(@NotNull 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();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,85 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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.IPlayerDataManager;
 | 
				
			||||||
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
 | 
					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.OfflinePlayer;
 | 
				
			||||||
 | 
					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.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) {
 | 
				
			||||||
 | 
					        return player.openInventory(inventory.getBukkitInventory());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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,44 +14,50 @@
 | 
				
			|||||||
 * 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_15_R1;
 | 
					package com.lishid.openinv.internal.v1_13_R2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.AutoRecipeStackManager;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ContainerUtil;
 | 
					import net.minecraft.server.v1_13_R2.AutoRecipeOutput;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityHuman;
 | 
					import net.minecraft.server.v1_13_R2.AutoRecipeStackManager;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
 | 
					import net.minecraft.server.v1_13_R2.ContainerUtil;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.IInventoryListener;
 | 
					import net.minecraft.server.v1_13_R2.EntityHuman;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.InventoryEnderChest;
 | 
					import net.minecraft.server.v1_13_R2.EntityPlayer;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ItemStack;
 | 
					import net.minecraft.server.v1_13_R2.IChatBaseComponent;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.NonNullList;
 | 
					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.Location;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftHumanEntity;
 | 
					import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory;
 | 
					import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEnderChest {
 | 
					public class SpecialEnderChest implements IInventory, ISpecialEnderChest, AutoRecipeOutput {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final CraftInventory inventory;
 | 
					 | 
				
			||||||
    private EntityPlayer owner;
 | 
					    private EntityPlayer owner;
 | 
				
			||||||
 | 
					    private final IChatBaseComponent displayName;
 | 
				
			||||||
 | 
					    private final CraftInventory inventory;
 | 
				
			||||||
    private NonNullList<ItemStack> items;
 | 
					    private NonNullList<ItemStack> items;
 | 
				
			||||||
    private boolean playerOnline;
 | 
					    private boolean playerOnline;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public SpecialEnderChest(final Player player, final Boolean online) {
 | 
					    public SpecialEnderChest(final Player player, final Boolean online) {
 | 
				
			||||||
        super(PlayerDataManager.getHandle(player));
 | 
					 | 
				
			||||||
        this.inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
        this.owner = PlayerDataManager.getHandle(player);
 | 
					        this.owner = PlayerDataManager.getHandle(player);
 | 
				
			||||||
        this.playerOnline = online;
 | 
					        this.displayName = this.owner.getEnderChest().getDisplayName();
 | 
				
			||||||
 | 
					        this.inventory = new CraftInventory(this);
 | 
				
			||||||
        this.items = this.owner.getEnderChest().items;
 | 
					        this.items = this.owner.getEnderChest().items;
 | 
				
			||||||
 | 
					        this.playerOnline = online;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public @NotNull CraftInventory getBukkitInventory() {
 | 
					    public @NotNull Inventory getBukkitInventory() {
 | 
				
			||||||
        return inventory;
 | 
					        return this.inventory;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -84,57 +90,46 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
 | 
				
			|||||||
        this.owner.getEnderChest().update();
 | 
					        this.owner.getEnderChest().update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<ItemStack> getContents() {
 | 
					    public List<ItemStack> getContents() {
 | 
				
			||||||
        return this.items;
 | 
					        return this.items;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					    public void onOpen(CraftHumanEntity who) {
 | 
				
			||||||
        this.owner.getEnderChest().onOpen(who);
 | 
					        this.owner.getEnderChest().onOpen(who);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					    public void onClose(CraftHumanEntity who) {
 | 
				
			||||||
        this.owner.getEnderChest().onClose(who);
 | 
					        this.owner.getEnderChest().onClose(who);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					    public List<HumanEntity> getViewers() {
 | 
				
			||||||
        return this.owner.getEnderChest().getViewers();
 | 
					        return this.owner.getEnderChest().getViewers();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setMaxStackSize(int i) {
 | 
					    public void setMaxStackSize(int i) {
 | 
				
			||||||
        this.owner.getEnderChest().setMaxStackSize(i);
 | 
					        this.owner.getEnderChest().setMaxStackSize(i);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public InventoryHolder getOwner() {
 | 
					    public InventoryHolder getOwner() {
 | 
				
			||||||
        return this.owner.getEnderChest().getOwner();
 | 
					        return this.owner.getEnderChest().getOwner();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Location getLocation() {
 | 
					    public Location getLocation() {
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void a(IInventoryListener iinventorylistener) {
 | 
					    public void a(IInventoryListener iinventorylistener) {
 | 
				
			||||||
        this.owner.getEnderChest().a(iinventorylistener);
 | 
					        this.owner.getEnderChest().a(iinventorylistener);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(IInventoryListener iinventorylistener) {
 | 
					    public void b(IInventoryListener iinventorylistener) {
 | 
				
			||||||
        this.owner.getEnderChest().b(iinventorylistener);
 | 
					        this.owner.getEnderChest().b(iinventorylistener);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					    public ItemStack getItem(int i) {
 | 
				
			||||||
        return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
 | 
					        return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					    public ItemStack splitStack(int i, int j) {
 | 
				
			||||||
        ItemStack itemstack = ContainerUtil.a(this.items, i, j);
 | 
					        ItemStack itemstack = ContainerUtil.a(this.items, i, j);
 | 
				
			||||||
        if (!itemstack.isEmpty()) {
 | 
					        if (!itemstack.isEmpty()) {
 | 
				
			||||||
@@ -144,7 +139,6 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
 | 
				
			|||||||
        return itemstack;
 | 
					        return itemstack;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack a(ItemStack itemstack) {
 | 
					    public ItemStack a(ItemStack itemstack) {
 | 
				
			||||||
        ItemStack itemstack1 = itemstack.cloneItemStack();
 | 
					        ItemStack itemstack1 = itemstack.cloneItemStack();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -177,7 +171,6 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
 | 
				
			|||||||
        return itemstack1;
 | 
					        return itemstack1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					    public ItemStack splitWithoutUpdate(int i) {
 | 
				
			||||||
        ItemStack itemstack = this.items.get(i);
 | 
					        ItemStack itemstack = this.items.get(i);
 | 
				
			||||||
        if (itemstack.isEmpty()) {
 | 
					        if (itemstack.isEmpty()) {
 | 
				
			||||||
@@ -188,7 +181,6 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					    public void setItem(int i, ItemStack itemstack) {
 | 
				
			||||||
        this.items.set(i, itemstack);
 | 
					        this.items.set(i, itemstack);
 | 
				
			||||||
        if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) {
 | 
					        if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) {
 | 
				
			||||||
@@ -198,13 +190,11 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
 | 
				
			|||||||
        this.update();
 | 
					        this.update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					    public int getSize() {
 | 
				
			||||||
        return this.owner.getEnderChest().getSize();
 | 
					        return this.owner.getEnderChest().getSize();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public boolean P_() {
 | 
				
			||||||
    public boolean isNotEmpty() {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (ItemStack itemstack : this.items) {
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
            if (!itemstack.isEmpty()) {
 | 
					            if (!itemstack.isEmpty()) {
 | 
				
			||||||
@@ -215,35 +205,56 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    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() {
 | 
					    public int getMaxStackSize() {
 | 
				
			||||||
        return 64;
 | 
					        return 64;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					    public boolean a(EntityHuman entityhuman) {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void startOpen(EntityHuman entityhuman) {
 | 
					    public void startOpen(EntityHuman entityhuman) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void closeContainer(EntityHuman entityhuman) {
 | 
					    public void closeContainer(EntityHuman entityhuman) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean b(int i, ItemStack itemstack) {
 | 
					    public boolean b(int i, ItemStack itemstack) {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public int getProperty(int i) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setProperty(int i, int j) {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int h() {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void clear() {
 | 
					    public void clear() {
 | 
				
			||||||
        this.items.clear();
 | 
					        this.items.clear();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
					    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (ItemStack itemstack : this.items) {
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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,56 +14,53 @@
 | 
				
			|||||||
 * 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_15_R1;
 | 
					package com.lishid.openinv.internal.v1_13_R2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.collect.ImmutableList;
 | 
					import com.google.common.collect.ImmutableList;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.function.Predicate;
 | 
					import java.util.function.Predicate;
 | 
				
			||||||
import java.util.stream.Collectors;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.AutoRecipeStackManager;
 | 
					import net.minecraft.server.v1_13_R2.AutoRecipeStackManager;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ChatMessage;
 | 
					import net.minecraft.server.v1_13_R2.ChatMessage;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ContainerUtil;
 | 
					import net.minecraft.server.v1_13_R2.ContainerUtil;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.CrashReport;
 | 
					import net.minecraft.server.v1_13_R2.CrashReport;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.CrashReportSystemDetails;
 | 
					import net.minecraft.server.v1_13_R2.CrashReportSystemDetails;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityHuman;
 | 
					import net.minecraft.server.v1_13_R2.EntityHuman;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
 | 
					import net.minecraft.server.v1_13_R2.EntityPlayer;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EnumItemSlot;
 | 
					import net.minecraft.server.v1_13_R2.IBlockData;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.IBlockData;
 | 
					import net.minecraft.server.v1_13_R2.IChatBaseComponent;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
 | 
					import net.minecraft.server.v1_13_R2.Item;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.Item;
 | 
					import net.minecraft.server.v1_13_R2.ItemArmor;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ItemArmor;
 | 
					import net.minecraft.server.v1_13_R2.ItemStack;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ItemStack;
 | 
					import net.minecraft.server.v1_13_R2.NBTTagCompound;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.NBTTagCompound;
 | 
					import net.minecraft.server.v1_13_R2.NBTTagList;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.NBTTagList;
 | 
					import net.minecraft.server.v1_13_R2.NonNullList;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.NonNullList;
 | 
					import net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutSetSlot;
 | 
					import net.minecraft.server.v1_13_R2.PlayerInventory;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PlayerInventory;
 | 
					import net.minecraft.server.v1_13_R2.ReportedException;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ReportedException;
 | 
					import net.minecraft.server.v1_13_R2.World;
 | 
				
			||||||
import net.minecraft.server.v1_15_R1.World;
 | 
					 | 
				
			||||||
import org.bukkit.Location;
 | 
					import org.bukkit.Location;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftHumanEntity;
 | 
					import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory;
 | 
					import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
import org.jetbrains.annotations.Nullable;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final CraftInventory inventory;
 | 
					    private final CraftInventory inventory = new CraftInventory(this);
 | 
				
			||||||
    private boolean playerOnline;
 | 
					    private boolean playerOnline;
 | 
				
			||||||
    private EntityHuman player;
 | 
					 | 
				
			||||||
    private NonNullList<ItemStack> items, armor, extraSlots;
 | 
					    private NonNullList<ItemStack> items, armor, extraSlots;
 | 
				
			||||||
    private List<NonNullList<ItemStack>> f;
 | 
					    private List<NonNullList<ItemStack>> f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
 | 
					    public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
				
			||||||
        this.inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					        this.playerOnline = online;
 | 
				
			||||||
        this.player = super.player;
 | 
					 | 
				
			||||||
        this.items = this.player.inventory.items;
 | 
					        this.items = this.player.inventory.items;
 | 
				
			||||||
        this.armor = this.player.inventory.armor;
 | 
					        this.armor = this.player.inventory.armor;
 | 
				
			||||||
        this.extraSlots = this.player.inventory.extraSlots;
 | 
					        this.extraSlots = this.player.inventory.extraSlots;
 | 
				
			||||||
@@ -94,8 +91,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public @NotNull CraftInventory getBukkitInventory() {
 | 
					    public @NotNull Inventory getBukkitInventory() {
 | 
				
			||||||
        return this.inventory;
 | 
					        return inventory;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -171,7 +168,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public int getSize() {
 | 
					    public int getSize() {
 | 
				
			||||||
        return 45;
 | 
					        return super.getSize() + 4;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -212,7 +209,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public ItemStack splitStack(int i, final int j) {
 | 
					    public ItemStack splitStack(int i, final int j) {
 | 
				
			||||||
        List<ItemStack> list = this.items;
 | 
					        NonNullList<ItemStack> list = this.items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (i >= list.size()) {
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
            i -= list.size();
 | 
					            i -= list.size();
 | 
				
			||||||
@@ -237,7 +234,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					    public ItemStack splitWithoutUpdate(int i) {
 | 
				
			||||||
        List<ItemStack> list = this.items;
 | 
					        NonNullList<ItemStack> list = this.items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (i >= list.size()) {
 | 
					        if (i >= list.size()) {
 | 
				
			||||||
            i -= list.size();
 | 
					            i -= list.size();
 | 
				
			||||||
@@ -267,44 +264,46 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return ItemStack.a;
 | 
					        return ItemStack.a;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<ItemStack> getContents() {
 | 
					    public List<ItemStack> getContents() {
 | 
				
			||||||
        return this.f.stream().flatMap(List::stream).collect(Collectors.toList());
 | 
					        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;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<ItemStack> getArmorContents() {
 | 
					    public List<ItemStack> getArmorContents() {
 | 
				
			||||||
        return this.armor;
 | 
					        return this.armor;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					    public void onOpen(CraftHumanEntity who) {
 | 
				
			||||||
        this.transaction.add(who);
 | 
					        this.transaction.add(who);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					    public void onClose(CraftHumanEntity who) {
 | 
				
			||||||
        this.transaction.remove(who);
 | 
					        this.transaction.remove(who);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					    public List<HumanEntity> getViewers() {
 | 
				
			||||||
        return this.transaction;
 | 
					        return this.transaction;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public InventoryHolder getOwner() {
 | 
					    public InventoryHolder getOwner() {
 | 
				
			||||||
        return this.player.getBukkitEntity();
 | 
					        return this.player.getBukkitEntity();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Location getLocation() {
 | 
					    public Location getLocation() {
 | 
				
			||||||
        return this.player.getBukkitEntity().getLocation();
 | 
					        return this.player.getBukkitEntity().getLocation();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItemInHand() {
 | 
					    public ItemStack getItemInHand() {
 | 
				
			||||||
        return d(this.itemInHandIndex) ? this.items.get(this.itemInHandIndex) : ItemStack.a;
 | 
					        return e(this.itemInHandIndex) ? this.items.get(this.itemInHandIndex) : ItemStack.a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static int getHotbarSize() {
 | 
				
			||||||
 | 
					        return 9;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private boolean a(ItemStack itemstack, ItemStack itemstack1) {
 | 
					    private boolean a(ItemStack itemstack, ItemStack itemstack1) {
 | 
				
			||||||
@@ -315,7 +314,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
 | 
					        return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int canHold(ItemStack itemstack) {
 | 
					    public int canHold(ItemStack itemstack) {
 | 
				
			||||||
        int remains = itemstack.getCount();
 | 
					        int remains = itemstack.getCount();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -337,7 +335,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return itemstack.getCount() - remains;
 | 
					        return itemstack.getCount() - remains;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getFirstEmptySlotIndex() {
 | 
					    public int getFirstEmptySlotIndex() {
 | 
				
			||||||
        for(int i = 0; i < this.items.size(); ++i) {
 | 
					        for(int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
            if (this.items.get(i).isEmpty()) {
 | 
					            if (this.items.get(i).isEmpty()) {
 | 
				
			||||||
@@ -348,15 +345,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public void d(int i) {
 | 
				
			||||||
    public void c(int i) {
 | 
					        this.itemInHandIndex = this.l();
 | 
				
			||||||
        this.itemInHandIndex = this.i();
 | 
					 | 
				
			||||||
        ItemStack itemstack = this.items.get(this.itemInHandIndex);
 | 
					        ItemStack itemstack = this.items.get(this.itemInHandIndex);
 | 
				
			||||||
        this.items.set(this.itemInHandIndex, this.items.get(i));
 | 
					        this.items.set(this.itemInHandIndex, this.items.get(i));
 | 
				
			||||||
        this.items.set(i, itemstack);
 | 
					        this.items.set(i, itemstack);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public static boolean e(int i) {
 | 
				
			||||||
 | 
					        return i >= 0 && i < 9;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int c(ItemStack itemstack) {
 | 
					    public int c(ItemStack itemstack) {
 | 
				
			||||||
        for(int i = 0; i < this.items.size(); ++i) {
 | 
					        for(int i = 0; i < this.items.size(); ++i) {
 | 
				
			||||||
            ItemStack itemstack1 = this.items.get(i);
 | 
					            ItemStack itemstack1 = this.items.get(i);
 | 
				
			||||||
@@ -368,8 +367,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public int l() {
 | 
				
			||||||
    public int i() {
 | 
					 | 
				
			||||||
        int i;
 | 
					        int i;
 | 
				
			||||||
        int j;
 | 
					        int j;
 | 
				
			||||||
        for(j = 0; j < 9; ++j) {
 | 
					        for(j = 0; j < 9; ++j) {
 | 
				
			||||||
@@ -389,7 +387,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return this.itemInHandIndex;
 | 
					        return this.itemInHandIndex;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int a(Predicate<ItemStack> predicate, int i) {
 | 
					    public int a(Predicate<ItemStack> predicate, int i) {
 | 
				
			||||||
        int j = 0;
 | 
					        int j = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -471,7 +468,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int firstPartial(ItemStack itemstack) {
 | 
					    public int firstPartial(ItemStack itemstack) {
 | 
				
			||||||
        if (this.a(this.getItem(this.itemInHandIndex), itemstack)) {
 | 
					        if (this.a(this.getItem(this.itemInHandIndex), itemstack)) {
 | 
				
			||||||
            return this.itemInHandIndex;
 | 
					            return this.itemInHandIndex;
 | 
				
			||||||
@@ -488,10 +484,9 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public void p() {
 | 
				
			||||||
    public void j() {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (List<ItemStack> itemStacks : this.f) {
 | 
					        for (NonNullList<ItemStack> itemStacks : this.f) {
 | 
				
			||||||
            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
					            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
				
			||||||
                if (!itemStacks.get(i).isEmpty()) {
 | 
					                if (!itemStacks.get(i).isEmpty()) {
 | 
				
			||||||
                    itemStacks.get(i).a(this.player.world, this.player, i, this.itemInHandIndex == i);
 | 
					                    itemStacks.get(i).a(this.player.world, this.player, i, this.itemInHandIndex == i);
 | 
				
			||||||
@@ -501,12 +496,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean pickup(ItemStack itemstack) {
 | 
					    public boolean pickup(ItemStack itemstack) {
 | 
				
			||||||
        return this.c(-1, itemstack);
 | 
					        return this.c(-1, itemstack);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean c(int i, ItemStack itemstack) {
 | 
					    public boolean c(int i, ItemStack itemstack) {
 | 
				
			||||||
        if (itemstack.isEmpty()) {
 | 
					        if (itemstack.isEmpty()) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
@@ -557,7 +550,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void a(World world, ItemStack itemstack) {
 | 
					    public void a(World world, ItemStack itemstack) {
 | 
				
			||||||
        if (!world.isClientSide) {
 | 
					        if (!world.isClientSide) {
 | 
				
			||||||
            while(!itemstack.isEmpty()) {
 | 
					            while(!itemstack.isEmpty()) {
 | 
				
			||||||
@@ -580,25 +572,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void f(ItemStack itemstack) {
 | 
					    public void f(ItemStack itemstack) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (List<ItemStack> list : this.f) {
 | 
					        for (NonNullList<ItemStack> nonnulllist : this.f) {
 | 
				
			||||||
            for (int i = 0; i < list.size(); ++i) {
 | 
					            for (int i = 0; i < nonnulllist.size(); ++i) {
 | 
				
			||||||
                if (list.get(i) == itemstack) {
 | 
					                if (nonnulllist.get(i) == itemstack) {
 | 
				
			||||||
                    list.set(i, ItemStack.a);
 | 
					                    nonnulllist.set(i, ItemStack.a);
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public float a(IBlockData iblockdata) {
 | 
					    public float a(IBlockData iblockdata) {
 | 
				
			||||||
        return this.items.get(this.itemInHandIndex).a(iblockdata);
 | 
					        return this.items.get(this.itemInHandIndex).a(iblockdata);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public NBTTagList a(NBTTagList nbttaglist) {
 | 
					    public NBTTagList a(NBTTagList nbttaglist) {
 | 
				
			||||||
        NBTTagCompound nbttagcompound;
 | 
					        NBTTagCompound nbttagcompound;
 | 
				
			||||||
        int i;
 | 
					        int i;
 | 
				
			||||||
@@ -632,7 +621,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return nbttaglist;
 | 
					        return nbttaglist;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(NBTTagList nbttaglist) {
 | 
					    public void b(NBTTagList nbttaglist) {
 | 
				
			||||||
        this.items.clear();
 | 
					        this.items.clear();
 | 
				
			||||||
        this.armor.clear();
 | 
					        this.armor.clear();
 | 
				
			||||||
@@ -655,8 +643,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public boolean P_() {
 | 
				
			||||||
    public boolean isNotEmpty() {
 | 
					 | 
				
			||||||
        Iterator iterator = this.items.iterator();
 | 
					        Iterator iterator = this.items.iterator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ItemStack itemstack;
 | 
					        ItemStack itemstack;
 | 
				
			||||||
@@ -689,17 +676,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nullable
 | 
					    @Nullable
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public IChatBaseComponent getCustomName() {
 | 
					    public IChatBaseComponent getCustomName() {
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean b(IBlockData iblockdata) {
 | 
					    public boolean b(IBlockData iblockdata) {
 | 
				
			||||||
        return this.getItem(this.itemInHandIndex).canDestroySpecialBlock(iblockdata);
 | 
					        return this.getItem(this.itemInHandIndex).b(iblockdata);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void a(float f) {
 | 
					    public void a(float f) {
 | 
				
			||||||
        if (f > 0.0F) {
 | 
					        if (f > 0.0F) {
 | 
				
			||||||
            f /= 4.0F;
 | 
					            f /= 4.0F;
 | 
				
			||||||
@@ -707,19 +691,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
                f = 1.0F;
 | 
					                f = 1.0F;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (int i = 0; i < this.armor.size(); ++i) {
 | 
					            for (ItemStack itemstack : this.armor) {
 | 
				
			||||||
                ItemStack itemstack = this.armor.get(0);
 | 
					 | 
				
			||||||
                int index = i;
 | 
					 | 
				
			||||||
                if (itemstack.getItem() instanceof ItemArmor) {
 | 
					                if (itemstack.getItem() instanceof ItemArmor) {
 | 
				
			||||||
                    itemstack.damage((int) f, this.player, (entityhuman) -> entityhuman.c(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, index)));
 | 
					                    itemstack.damage((int) f, this.player);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void dropContents() {
 | 
					    public void dropContents() {
 | 
				
			||||||
        for (List<ItemStack> itemStacks : this.f) {
 | 
					        for (NonNullList<ItemStack> itemStacks : this.f) {
 | 
				
			||||||
            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
					            for (int i = 0; i < itemStacks.size(); ++i) {
 | 
				
			||||||
                ItemStack itemstack = itemStacks.get(i);
 | 
					                ItemStack itemstack = itemStacks.get(i);
 | 
				
			||||||
                if (!itemstack.isEmpty()) {
 | 
					                if (!itemstack.isEmpty()) {
 | 
				
			||||||
@@ -730,12 +711,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean h(ItemStack itemstack) {
 | 
					    public boolean h(ItemStack itemstack) {
 | 
				
			||||||
        return this.f.stream().flatMap(List::stream).anyMatch(itemStack1 -> !itemStack1.isEmpty() && itemStack1.doMaterialsMatch(itemstack));
 | 
					        return this.f.stream().flatMap(NonNullList::stream).anyMatch(itemStack1 -> !itemStack1.isEmpty() && itemStack1.doMaterialsMatch(itemstack));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void a(PlayerInventory playerinventory) {
 | 
					    public void a(PlayerInventory playerinventory) {
 | 
				
			||||||
        for (int i = 0; i < playerinventory.getSize(); ++i) {
 | 
					        for (int i = 0; i < playerinventory.getSize(); ++i) {
 | 
				
			||||||
            this.setItem(i, playerinventory.getItem(i));
 | 
					            this.setItem(i, playerinventory.getItem(i));
 | 
				
			||||||
@@ -744,12 +723,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        this.itemInHandIndex = playerinventory.itemInHandIndex;
 | 
					        this.itemInHandIndex = playerinventory.itemInHandIndex;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void clear() {
 | 
					    public void clear() {
 | 
				
			||||||
        this.f.forEach(List::clear);
 | 
					        this.f.forEach(NonNullList::clear);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
					    public void a(AutoRecipeStackManager autorecipestackmanager) {
 | 
				
			||||||
        for (ItemStack itemstack : this.items) {
 | 
					        for (ItemStack itemstack : this.items) {
 | 
				
			||||||
            autorecipestackmanager.a(itemstack);
 | 
					            autorecipestackmanager.a(itemstack);
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
  <parent>
 | 
					  <parent>
 | 
				
			||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinvinternal</artifactId>
 | 
					    <artifactId>openinvinternal</artifactId>
 | 
				
			||||||
    <version>4.1.2-SNAPSHOT</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvadapter1_14_R1</artifactId>
 | 
					  <artifactId>openinvadapter1_14_R1</artifactId>
 | 
				
			||||||
@@ -37,8 +37,8 @@
 | 
				
			|||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					      <groupId>com.lishid</groupId>
 | 
				
			||||||
      <artifactId>openinvplugincore</artifactId>
 | 
					      <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
      <version>4.1.2-SNAPSHOT</version>
 | 
					      <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -47,7 +47,7 @@
 | 
				
			|||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <groupId>org.apache.maven.plugins</groupId>
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
        <artifactId>maven-shade-plugin</artifactId>
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
        <version>3.2.2</version>
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <minimizeJar>true</minimizeJar>
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
        </configuration>
 | 
					        </configuration>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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,7 +16,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_14_R1;
 | 
					package com.lishid.openinv.internal.v1_14_R1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					import com.lishid.openinv.internal.IAnySilentContainer;
 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					import java.lang.reflect.Field;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.Block;
 | 
					import net.minecraft.server.v1_14_R1.Block;
 | 
				
			||||||
@@ -30,7 +29,6 @@ import net.minecraft.server.v1_14_R1.BlockShulkerBox;
 | 
				
			|||||||
import net.minecraft.server.v1_14_R1.ChatMessage;
 | 
					import net.minecraft.server.v1_14_R1.ChatMessage;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.Container;
 | 
					import net.minecraft.server.v1_14_R1.Container;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.ContainerChest;
 | 
					import net.minecraft.server.v1_14_R1.ContainerChest;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.Containers;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
					import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
					import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.EnumChatFormat;
 | 
					import net.minecraft.server.v1_14_R1.EnumChatFormat;
 | 
				
			||||||
@@ -191,32 +189,8 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
					            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
				
			||||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
					            InventoryEnderChest enderChest = player.getEnderChest();
 | 
				
			||||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
					            enderChest.a((TileEntityEnderChest) tile);
 | 
				
			||||||
            player.openContainer(new TileInventory((containerCounter, playerInventory, ignored) -> {
 | 
					            player.openContainer(new TileInventory((containerCounter, playerInventory, ignored) ->
 | 
				
			||||||
                Containers<?> containers;
 | 
					                    ContainerChest.a(containerCounter, playerInventory, enderChest), BlockEnderChest.d));
 | 
				
			||||||
                int rows = enderChest.getSize() / 9;
 | 
					 | 
				
			||||||
                switch (rows) {
 | 
					 | 
				
			||||||
                    case 1:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X1;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 2:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X2;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 3:
 | 
					 | 
				
			||||||
                    default:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X3;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 4:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X4;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 5:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X5;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 6:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X6;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                return new ContainerChest(containers, containerCounter, playerInventory, enderChest, rows);
 | 
					 | 
				
			||||||
            }, BlockEnderChest.d));
 | 
					 | 
				
			||||||
            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
					            bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -301,7 +275,7 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
        if (tile instanceof TileEntityLootable) {
 | 
					        if (tile instanceof TileEntityLootable) {
 | 
				
			||||||
            TileEntityLootable lootable = (TileEntityLootable) tile;
 | 
					            TileEntityLootable lootable = (TileEntityLootable) tile;
 | 
				
			||||||
            if (lootable.lootTable != null) {
 | 
					            if (lootable.lootTable != null) {
 | 
				
			||||||
                OpenInv.getPlugin(OpenInv.class).sendSystemMessage(bukkitPlayer, "messages.error.lootNotGenerated");
 | 
					                player.a(new ChatMessage("Loot not generated! Please disable /silentcontainer.").a(EnumChatFormat.RED), true);
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -335,8 +309,6 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
				
			||||||
        player.activeContainer.b(player);
 | 
					        player.activeContainer.b(player);
 | 
				
			||||||
        player.activeContainer.a(player, false);
 | 
					 | 
				
			||||||
        player.activeContainer.transferTo(player.defaultContainer, player.getBukkitEntity());
 | 
					 | 
				
			||||||
        player.activeContainer = player.defaultContainer;
 | 
					        player.activeContainer = player.defaultContainer;
 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					        this.forceGameMode(player, gamemode);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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,30 +16,19 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_14_R1;
 | 
					package com.lishid.openinv.internal.v1_14_R1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					import com.lishid.openinv.internal.IPlayerDataManager;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialInventory;
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					import com.mojang.authlib.GameProfile;
 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.io.FileOutputStream;
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.ChatComponentText;
 | 
					import net.minecraft.server.v1_14_R1.ChatComponentText;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.ChatMessageType;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.Container;
 | 
					import net.minecraft.server.v1_14_R1.Container;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.Containers;
 | 
					import net.minecraft.server.v1_14_R1.Containers;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.DimensionManager;
 | 
					import net.minecraft.server.v1_14_R1.DimensionManager;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.Entity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
					import net.minecraft.server.v1_14_R1.EntityHuman;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
					import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.MinecraftServer;
 | 
					import net.minecraft.server.v1_14_R1.MinecraftServer;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.PacketPlayOutChat;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
 | 
					import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
 | 
					import net.minecraft.server.v1_14_R1.PlayerInteractManager;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.PlayerInventory;
 | 
					import net.minecraft.server.v1_14_R1.PlayerInventory;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.WorldNBTStorage;
 | 
					 | 
				
			||||||
import org.apache.logging.log4j.LogManager;
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.Server;
 | 
					import org.bukkit.Server;
 | 
				
			||||||
@@ -53,23 +42,9 @@ import org.bukkit.event.inventory.InventoryType;
 | 
				
			|||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
import org.bukkit.inventory.InventoryView;
 | 
					import org.bukkit.inventory.InventoryView;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
import org.jetbrains.annotations.Nullable;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Field bukkitEntity;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public PlayerDataManager() {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            bukkitEntity = Entity.class.getDeclaredField("bukkitEntity");
 | 
					 | 
				
			||||||
        } catch (NoSuchFieldException e) {
 | 
					 | 
				
			||||||
            System.out.println("Unable to obtain field to inject custom save process - players' mounts may be deleted when loaded.");
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            bukkitEntity = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(final Player player) {
 | 
					    public static EntityPlayer getHandle(final Player player) {
 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					        if (player instanceof CraftPlayer) {
 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					            return ((CraftPlayer) player).getHandle();
 | 
				
			||||||
@@ -98,18 +73,11 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 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(),
 | 
					        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
				
			||||||
                offline.getName() != null ? offline.getName() : offline.getUniqueId().toString());
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
 | 
					        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
 | 
				
			||||||
                new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
 | 
					                new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            injectPlayer(entity);
 | 
					 | 
				
			||||||
        } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Get the bukkit entity
 | 
					        // Get the bukkit entity
 | 
				
			||||||
        Player target = entity.getBukkitEntity();
 | 
					        Player target = entity.getBukkitEntity();
 | 
				
			||||||
        if (target != null) {
 | 
					        if (target != null) {
 | 
				
			||||||
@@ -120,91 +88,27 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
        return target;
 | 
					        return target;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void injectPlayer(EntityPlayer player) throws IllegalAccessException {
 | 
					 | 
				
			||||||
        if (bukkitEntity == null) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        bukkitEntity.setAccessible(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        bukkitEntity.set(player, new CraftPlayer(player.server.server, player) {
 | 
					 | 
				
			||||||
            @Override
 | 
					 | 
				
			||||||
            public void saveData() {
 | 
					 | 
				
			||||||
                super.saveData();
 | 
					 | 
				
			||||||
                // See net.minecraft.server.WorldNBTStorage#save(EntityPlayer)
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    WorldNBTStorage worldNBTStorage = (WorldNBTStorage) player.server.getPlayerList().playerFileData;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    NBTTagCompound playerData = player.save(new NBTTagCompound());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (!isOnline()) {
 | 
					 | 
				
			||||||
                        // Special case: save old vehicle data
 | 
					 | 
				
			||||||
                        NBTTagCompound oldData = worldNBTStorage.load(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        if (oldData != null && oldData.hasKeyOfType("RootVehicle", 10)) {
 | 
					 | 
				
			||||||
                            // See net.minecraft.server.PlayerList#a(NetworkManager, EntityPlayer) and net.minecraft.server.EntityPlayer#b(NBTTagCompound)
 | 
					 | 
				
			||||||
                            playerData.set("RootVehicle", oldData.getCompound("RootVehicle"));
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    File file = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat.tmp");
 | 
					 | 
				
			||||||
                    File file1 = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    NBTCompressedStreamTools.a(playerData, new FileOutputStream(file));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (file1.exists()) {
 | 
					 | 
				
			||||||
                        file1.delete();
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    file.renameTo(file1);
 | 
					 | 
				
			||||||
                } catch (Exception e) {
 | 
					 | 
				
			||||||
                    LogManager.getLogger().warn("Failed to save player data for {}", player.getDisplayName().getString());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player inject(@NotNull Player player) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            EntityPlayer nmsPlayer = getHandle(player);
 | 
					 | 
				
			||||||
            injectPlayer(nmsPlayer);
 | 
					 | 
				
			||||||
            return nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            return player;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
 | 
					    public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        EntityPlayer nmsPlayer = getHandle(player);
 | 
					        EntityPlayer nmsPlayer = getHandle(player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (nmsPlayer.playerConnection == null) {
 | 
					        if (nmsPlayer == null || nmsPlayer.playerConnection == null) {
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String title;
 | 
					        String title;
 | 
				
			||||||
        if (inventory instanceof SpecialEnderChest) {
 | 
					        if (inventory instanceof SpecialEnderChest) {
 | 
				
			||||||
            HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner();
 | 
					            HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner();
 | 
				
			||||||
            title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.enderchest", "%player%", owner.getName());
 | 
					            //noinspection ConstantConditions // Owner name can be null when loaded under certain conditions.
 | 
				
			||||||
            if (title == null) {
 | 
					            title = (owner.getName() != null ? owner.getName() : owner.getUniqueId().toString()) + "'s Ender Chest";
 | 
				
			||||||
                title = owner.getName() + "'s Ender Chest";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        } else if (inventory instanceof SpecialPlayerInventory) {
 | 
					        } else if (inventory instanceof SpecialPlayerInventory) {
 | 
				
			||||||
            EntityHuman owner = ((PlayerInventory) inventory).player;
 | 
					            EntityHuman owner = ((PlayerInventory) inventory).player;
 | 
				
			||||||
            title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.player", "%player%", owner.getName());
 | 
					            title = (owner.getName() != null ? owner.getName() : owner.getUniqueID().toString()) + "'s Inventory";
 | 
				
			||||||
            if (title == null) {
 | 
					 | 
				
			||||||
                title = owner.getName() + "'s Inventory";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return player.openInventory(inventory.getBukkitInventory());
 | 
					            return player.openInventory(inventory.getBukkitInventory());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String finalTitle = title;
 | 
					 | 
				
			||||||
        Container container = new CraftContainer(new InventoryView() {
 | 
					        Container container = new CraftContainer(new InventoryView() {
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
            public @NotNull Inventory getTopInventory() {
 | 
					            public @NotNull Inventory getTopInventory() {
 | 
				
			||||||
@@ -224,7 +128,7 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
            public @NotNull String getTitle() {
 | 
					            public @NotNull String getTitle() {
 | 
				
			||||||
                return finalTitle;
 | 
					                return title;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }, nmsPlayer, nmsPlayer.nextContainerCounter()) {
 | 
					        }, nmsPlayer, nmsPlayer.nextContainerCounter()) {
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
@@ -239,9 +143,9 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
                        return Containers.GENERIC_9X3;
 | 
					                        return Containers.GENERIC_9X3;
 | 
				
			||||||
                    case 36:
 | 
					                    case 36:
 | 
				
			||||||
                        return Containers.GENERIC_9X4;
 | 
					                        return Containers.GENERIC_9X4;
 | 
				
			||||||
                    case 41: // PLAYER
 | 
					 | 
				
			||||||
                    case 45:
 | 
					                    case 45:
 | 
				
			||||||
                        return Containers.GENERIC_9X5;
 | 
					                        return Containers.GENERIC_9X5;
 | 
				
			||||||
 | 
					                    case 41: // PLAYER
 | 
				
			||||||
                    case 54:
 | 
					                    case 54:
 | 
				
			||||||
                        return Containers.GENERIC_9X6;
 | 
					                        return Containers.GENERIC_9X6;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -264,24 +168,4 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void sendSystemMessage(@NotNull Player player, @NotNull String message) {
 | 
					 | 
				
			||||||
        int newline = message.indexOf('\n');
 | 
					 | 
				
			||||||
        if (newline != -1) {
 | 
					 | 
				
			||||||
            // No newlines in action bar chat.
 | 
					 | 
				
			||||||
            message = message.substring(0, newline);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (message.isEmpty()) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = getHandle(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // For action bar chat, color codes are still supported but JSON text color is not allowed. Do not convert text.
 | 
					 | 
				
			||||||
        if (nmsPlayer.playerConnection != null) {
 | 
					 | 
				
			||||||
            nmsPlayer.playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(message), ChatMessageType.GAME_INFO));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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-2020 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,8 @@ package com.lishid.openinv.internal.v1_14_R1;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.google.common.collect.ImmutableList;
 | 
					import com.google.common.collect.ImmutableList;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					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.Iterator;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.function.Predicate;
 | 
					import java.util.function.Predicate;
 | 
				
			||||||
@@ -32,12 +34,12 @@ import net.minecraft.server.v1_14_R1.EntityPlayer;
 | 
				
			|||||||
import net.minecraft.server.v1_14_R1.EnumItemSlot;
 | 
					import net.minecraft.server.v1_14_R1.EnumItemSlot;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.IBlockData;
 | 
					import net.minecraft.server.v1_14_R1.IBlockData;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
 | 
					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.Item;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.ItemArmor;
 | 
					import net.minecraft.server.v1_14_R1.ItemArmor;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.ItemStack;
 | 
					import net.minecraft.server.v1_14_R1.ItemStack;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
 | 
					import net.minecraft.server.v1_14_R1.NBTTagCompound;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.NBTTagList;
 | 
					import net.minecraft.server.v1_14_R1.NBTTagList;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.NonNullList;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_14_R1.PacketPlayOutSetSlot;
 | 
					import net.minecraft.server.v1_14_R1.PacketPlayOutSetSlot;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.PlayerInventory;
 | 
					import net.minecraft.server.v1_14_R1.PlayerInventory;
 | 
				
			||||||
import net.minecraft.server.v1_14_R1.ReportedException;
 | 
					import net.minecraft.server.v1_14_R1.ReportedException;
 | 
				
			||||||
@@ -45,6 +47,7 @@ import net.minecraft.server.v1_14_R1.World;
 | 
				
			|||||||
import org.bukkit.Location;
 | 
					import org.bukkit.Location;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity;
 | 
					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.CraftInventory;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCrafting;
 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
@@ -56,8 +59,11 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
    private final CraftInventory inventory;
 | 
					    private final CraftInventory inventory;
 | 
				
			||||||
    private boolean playerOnline;
 | 
					    private boolean playerOnline;
 | 
				
			||||||
    private EntityHuman player;
 | 
					    private EntityHuman player;
 | 
				
			||||||
    private NonNullList<ItemStack> items, armor, extraSlots;
 | 
					    private List<ItemStack> items, armor, extraSlots, crafting;
 | 
				
			||||||
    private List<NonNullList<ItemStack>> f;
 | 
					    @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) {
 | 
					    public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
 | 
				
			||||||
        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
					        super(PlayerDataManager.getHandle(bukkitPlayer));
 | 
				
			||||||
@@ -67,7 +73,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        this.items = this.player.inventory.items;
 | 
					        this.items = this.player.inventory.items;
 | 
				
			||||||
        this.armor = this.player.inventory.armor;
 | 
					        this.armor = this.player.inventory.armor;
 | 
				
			||||||
        this.extraSlots = this.player.inventory.extraSlots;
 | 
					        this.extraSlots = this.player.inventory.extraSlots;
 | 
				
			||||||
        this.f = ImmutableList.of(this.items, this.armor, this.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
 | 
					    @Override
 | 
				
			||||||
@@ -79,11 +90,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
            for (int i = 0; i < getSize(); ++i) {
 | 
					            for (int i = 0; i < getSize(); ++i) {
 | 
				
			||||||
                this.player.inventory.setItem(i, getRawItem(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.player.inventory.itemInHandIndex = this.itemInHandIndex;
 | 
				
			||||||
            this.items = this.player.inventory.items;
 | 
					            this.items = this.player.inventory.items;
 | 
				
			||||||
            this.armor = this.player.inventory.armor;
 | 
					            this.armor = this.player.inventory.armor;
 | 
				
			||||||
            this.extraSlots = this.player.inventory.extraSlots;
 | 
					            this.extraSlots = this.player.inventory.extraSlots;
 | 
				
			||||||
            this.f = ImmutableList.of(this.items, this.armor, this.extraSlots);
 | 
					            this.crafting = this.getCrafting().getContents();
 | 
				
			||||||
 | 
					            this.f = ImmutableList.of(this.items, this.armor, this.extraSlots, this.crafting, this.cursor);
 | 
				
			||||||
            this.playerOnline = true;
 | 
					            this.playerOnline = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -124,8 +137,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private ItemStack getRawItem(int i) {
 | 
					    private ItemStack getRawItem(int i) {
 | 
				
			||||||
        NonNullList<ItemStack> list = null;
 | 
					        List<ItemStack> list = null;
 | 
				
			||||||
        for (NonNullList<ItemStack> next : this.f) {
 | 
					        for (List<ItemStack> next : this.f) {
 | 
				
			||||||
            if (i < next.size()) {
 | 
					            if (i < next.size()) {
 | 
				
			||||||
                list = next;
 | 
					                list = next;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
@@ -171,7 +184,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public int getSize() {
 | 
					    public int getSize() {
 | 
				
			||||||
        return 45;
 | 
					        return 54;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -179,30 +192,35 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        return !this.getViewers().isEmpty();
 | 
					        return !this.getViewers().isEmpty();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    private Pair<List<ItemStack>, Integer> getLocalizedIndex(int i) {
 | 
				
			||||||
    public void setItem(int i, final ItemStack itemstack) {
 | 
					        List<ItemStack> localList = null;
 | 
				
			||||||
        List<ItemStack> list = this.items;
 | 
					        for (List<ItemStack> list : this.f) {
 | 
				
			||||||
 | 
					            if (i < list.size()) {
 | 
				
			||||||
        if (i >= list.size()) {
 | 
					                localList = list;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            i -= list.size();
 | 
					            i -= list.size();
 | 
				
			||||||
            list = this.armor;
 | 
					        }
 | 
				
			||||||
        } else {
 | 
					
 | 
				
			||||||
 | 
					        if (localList == this.armor) {
 | 
				
			||||||
 | 
					            i = this.getReversedArmorSlotNum(i);
 | 
				
			||||||
 | 
					        } else if (localList == this.items) {
 | 
				
			||||||
            i = this.getReversedItemSlotNum(i);
 | 
					            i = this.getReversedItemSlotNum(i);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (i >= list.size()) {
 | 
					        return new Pair<>(localList, i);
 | 
				
			||||||
            i -= list.size();
 | 
					 | 
				
			||||||
            list = this.extraSlots;
 | 
					 | 
				
			||||||
        } else if (list == this.armor) {
 | 
					 | 
				
			||||||
            i = this.getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (i >= list.size()) {
 | 
					    @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);
 | 
					            this.player.drop(itemstack, true);
 | 
				
			||||||
            return;
 | 
					        } else {
 | 
				
			||||||
 | 
					            localizedIndex.getLeft().set(localizedIndex.getRight(), itemstack);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        list.set(i, itemstack);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -212,51 +230,26 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public ItemStack splitStack(int i, final int j) {
 | 
					    public ItemStack splitStack(int i, final int j) {
 | 
				
			||||||
        List<ItemStack> list = this.items;
 | 
					        Pair<List<ItemStack>, Integer> localizedIndex = getLocalizedIndex(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (i >= list.size()) {
 | 
					        if (localizedIndex.getLeft() == null) {
 | 
				
			||||||
            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 ItemStack.a;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
 | 
					        return localizedIndex.getLeft().get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(localizedIndex.getLeft(), localizedIndex.getRight(), j);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					    public ItemStack splitWithoutUpdate(int i) {
 | 
				
			||||||
        List<ItemStack> list = this.items;
 | 
					        Pair<List<ItemStack>, Integer> localizedIndex = getLocalizedIndex(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (i >= list.size()) {
 | 
					        if (localizedIndex.getLeft() == null) {
 | 
				
			||||||
            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 ItemStack.a;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        List<ItemStack> list = localizedIndex.getLeft();
 | 
				
			||||||
 | 
					        i = localizedIndex.getRight();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!list.get(i).isEmpty()) {
 | 
					        if (!list.get(i).isEmpty()) {
 | 
				
			||||||
            ItemStack itemstack = list.get(i);
 | 
					            ItemStack itemstack = list.get(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -280,11 +273,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					    public void onOpen(CraftHumanEntity who) {
 | 
				
			||||||
        this.transaction.add(who);
 | 
					        this.transaction.add(who);
 | 
				
			||||||
 | 
					        this.getCrafting().getViewers().add(who);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					    public void onClose(CraftHumanEntity who) {
 | 
				
			||||||
        this.transaction.remove(who);
 | 
					        this.transaction.remove(who);
 | 
				
			||||||
 | 
					        this.getCrafting().getViewers().remove(who);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -326,7 +321,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!this.a(itemstack, itemstack1)) {
 | 
					            if (!this.a(itemstack, itemstack1)) {
 | 
				
			||||||
                remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount();
 | 
					                remains -= Math.min(itemstack1.getMaxStackSize(), this.getMaxStackSize()) - itemstack1.getCount();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (remains <= 0) {
 | 
					            if (remains <= 0) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,360 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2020 lishid. All rights reserved.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * 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_15_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.Block;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.BlockBarrel;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.BlockChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.BlockChestTrapped;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.BlockEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.BlockPosition;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.BlockPropertyChestType;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.BlockShulkerBox;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ChatMessage;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.Container;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ContainerChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.Containers;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EnumChatFormat;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EnumGamemode;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.IBlockData;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ITileInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.InventoryEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.InventoryLargeChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PlayerInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.TileEntity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.TileEntityChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.TileEntityEnderChest;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.TileEntityLootable;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.TileInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_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) -> {
 | 
					 | 
				
			||||||
                Containers containers;
 | 
					 | 
				
			||||||
                int rows = enderChest.getSize() / 9;
 | 
					 | 
				
			||||||
                switch (rows) {
 | 
					 | 
				
			||||||
                    case 1:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X1;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 2:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X2;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 3:
 | 
					 | 
				
			||||||
                    default:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X3;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 4:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X4;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 5:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X5;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    case 6:
 | 
					 | 
				
			||||||
                        containers = Containers.GENERIC_9X6;
 | 
					 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                return new ContainerChest(containers, containerCounter, playerInventory, enderChest, rows);
 | 
					 | 
				
			||||||
            }, BlockEnderChest.e));
 | 
					 | 
				
			||||||
            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.c);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (chestType != BlockPropertyChestType.SINGLE) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.i(blockData));
 | 
					 | 
				
			||||||
                IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (adjacentBlockData.getBlock() == block) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.c);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    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) {
 | 
					 | 
				
			||||||
                OpenInv.getPlugin(OpenInv.class).sendSystemMessage(bukkitPlayer, "messages.error.lootNotGenerated");
 | 
					 | 
				
			||||||
                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.a(player, false);
 | 
					 | 
				
			||||||
        player.activeContainer.transferTo(player.defaultContainer, player.getBukkitEntity());
 | 
					 | 
				
			||||||
        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,289 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2020 lishid. All rights reserved.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * 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_15_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialInventory;
 | 
					 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.io.FileOutputStream;
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ChatComponentText;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.ChatMessageType;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.Container;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.Containers;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.DimensionManager;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.Entity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityHuman;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.MinecraftServer;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.NBTCompressedStreamTools;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.NBTTagCompound;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutChat;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutOpenWindow;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PlayerInteractManager;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.PlayerInventory;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_15_R1.WorldNBTStorage;
 | 
					 | 
				
			||||||
import org.apache.logging.log4j.LogManager;
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_15_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;
 | 
					 | 
				
			||||||
import org.jetbrains.annotations.Nullable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private Field bukkitEntity;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public PlayerDataManager() {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            bukkitEntity = Entity.class.getDeclaredField("bukkitEntity");
 | 
					 | 
				
			||||||
        } catch (NoSuchFieldException e) {
 | 
					 | 
				
			||||||
            System.out.println("Unable to obtain field to inject custom save process - players' mounts may be deleted when loaded.");
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            bukkitEntity = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    @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
 | 
					 | 
				
			||||||
        // See net.minecraft.server.PlayerList#attemptLogin
 | 
					 | 
				
			||||||
        GameProfile profile = new GameProfile(offline.getUniqueId(),
 | 
					 | 
				
			||||||
                offline.getName() != null ? offline.getName() : offline.getUniqueId().toString());
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
 | 
					 | 
				
			||||||
                new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            injectPlayer(entity);
 | 
					 | 
				
			||||||
        } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Get the bukkit entity
 | 
					 | 
				
			||||||
        Player target = entity.getBukkitEntity();
 | 
					 | 
				
			||||||
        if (target != null) {
 | 
					 | 
				
			||||||
            // Load data
 | 
					 | 
				
			||||||
            target.loadData();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        // Return the entity
 | 
					 | 
				
			||||||
        return target;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    void injectPlayer(EntityPlayer player) throws IllegalAccessException {
 | 
					 | 
				
			||||||
        if (bukkitEntity == null) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        bukkitEntity.setAccessible(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        bukkitEntity.set(player, new CraftPlayer(player.server.server, player) {
 | 
					 | 
				
			||||||
            @Override
 | 
					 | 
				
			||||||
            public void saveData() {
 | 
					 | 
				
			||||||
                super.saveData();
 | 
					 | 
				
			||||||
                // See net.minecraft.server.WorldNBTStorage#save(EntityPlayer)
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    WorldNBTStorage worldNBTStorage = (WorldNBTStorage) player.server.getPlayerList().playerFileData;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    NBTTagCompound playerData = player.save(new NBTTagCompound());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (!isOnline()) {
 | 
					 | 
				
			||||||
                        // Special case: save old vehicle data
 | 
					 | 
				
			||||||
                        NBTTagCompound oldData = worldNBTStorage.load(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        if (oldData != null && oldData.hasKeyOfType("RootVehicle", 10)) {
 | 
					 | 
				
			||||||
                            // See net.minecraft.server.PlayerList#a(NetworkManager, EntityPlayer) and net.minecraft.server.EntityPlayer#b(NBTTagCompound)
 | 
					 | 
				
			||||||
                            playerData.set("RootVehicle", oldData.getCompound("RootVehicle"));
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    File file = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat.tmp");
 | 
					 | 
				
			||||||
                    File file1 = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    NBTCompressedStreamTools.a(playerData, new FileOutputStream(file));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (file1.exists()) {
 | 
					 | 
				
			||||||
                        file1.delete();
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    file.renameTo(file1);
 | 
					 | 
				
			||||||
                } catch (Exception e) {
 | 
					 | 
				
			||||||
                    LogManager.getLogger().warn("Failed to save player data for {}", player.getDisplayName().getString());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player inject(@NotNull Player player) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            EntityPlayer nmsPlayer = getHandle(player);
 | 
					 | 
				
			||||||
            injectPlayer(nmsPlayer);
 | 
					 | 
				
			||||||
            return nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            return player;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
    public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = getHandle(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (nmsPlayer.playerConnection == null) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String title;
 | 
					 | 
				
			||||||
        if (inventory instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner();
 | 
					 | 
				
			||||||
            title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.enderchest", "%player%", owner.getName());
 | 
					 | 
				
			||||||
            if (title == null) {
 | 
					 | 
				
			||||||
                title = owner.getName() + "'s Ender Chest";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        } else if (inventory instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            EntityHuman owner = ((PlayerInventory) inventory).player;
 | 
					 | 
				
			||||||
            title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.player", "%player%", owner.getName());
 | 
					 | 
				
			||||||
            if (title == null) {
 | 
					 | 
				
			||||||
                title = owner.getName() + "'s Inventory";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            return player.openInventory(inventory.getBukkitInventory());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String finalTitle = title;
 | 
					 | 
				
			||||||
        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 finalTitle;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }, 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 41: // PLAYER
 | 
					 | 
				
			||||||
                    case 45:
 | 
					 | 
				
			||||||
                        return Containers.GENERIC_9X5;
 | 
					 | 
				
			||||||
                    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();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void sendSystemMessage(@NotNull Player player, @NotNull String message) {
 | 
					 | 
				
			||||||
        int newline = message.indexOf('\n');
 | 
					 | 
				
			||||||
        if (newline != -1) {
 | 
					 | 
				
			||||||
            // No newlines in action bar chat.
 | 
					 | 
				
			||||||
            message = message.substring(0, newline);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (message.isEmpty()) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = getHandle(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // For action bar chat, color codes are still supported but JSON text color is not allowed. Do not convert text.
 | 
					 | 
				
			||||||
        if (nmsPlayer.playerConnection != null) {
 | 
					 | 
				
			||||||
            nmsPlayer.playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(message), ChatMessageType.GAME_INFO));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2020 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>openinvinternal</artifactId>
 | 
					    <artifactId>openinvinternal</artifactId>
 | 
				
			||||||
    <version>4.1.2-SNAPSHOT</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvadapter1_8_R3</artifactId>
 | 
					  <artifactId>openinvadapter1_8_R3</artifactId>
 | 
				
			||||||
@@ -36,8 +36,8 @@
 | 
				
			|||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					      <groupId>com.lishid</groupId>
 | 
				
			||||||
      <artifactId>openinvplugincore</artifactId>
 | 
					      <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
      <version>4.1.2-SNAPSHOT</version>
 | 
					      <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -46,7 +46,7 @@
 | 
				
			|||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <groupId>org.apache.maven.plugins</groupId>
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
        <artifactId>maven-shade-plugin</artifactId>
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
        <version>3.2.2</version>
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <minimizeJar>true</minimizeJar>
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
        </configuration>
 | 
					        </configuration>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -225,8 +225,6 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
				
			|||||||
        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
					        EnumGamemode gamemode = player.playerInteractManager.getGameMode();
 | 
				
			||||||
        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
					        this.forceGameMode(player, EnumGamemode.SPECTATOR);
 | 
				
			||||||
        player.activeContainer.b(player);
 | 
					        player.activeContainer.b(player);
 | 
				
			||||||
        player.activeContainer.a(player, false);
 | 
					 | 
				
			||||||
        player.activeContainer.transferTo(player.defaultContainer, player.getBukkitEntity());
 | 
					 | 
				
			||||||
        player.activeContainer = player.defaultContainer;
 | 
					        player.activeContainer = player.defaultContainer;
 | 
				
			||||||
        this.forceGameMode(player, gamemode);
 | 
					        this.forceGameMode(player, gamemode);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -19,19 +19,9 @@ package com.lishid.openinv.internal.v1_8_R3;
 | 
				
			|||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					import com.lishid.openinv.internal.IPlayerDataManager;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialInventory;
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					import com.mojang.authlib.GameProfile;
 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.io.FileOutputStream;
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.ChatComponentText;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.Entity;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
 | 
					import net.minecraft.server.v1_8_R3.EntityPlayer;
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
 | 
					import net.minecraft.server.v1_8_R3.MinecraftServer;
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.PlayerInteractManager;
 | 
					import net.minecraft.server.v1_8_R3.PlayerInteractManager;
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.WorldNBTStorage;
 | 
					 | 
				
			||||||
import org.apache.logging.log4j.LogManager;
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.Server;
 | 
					import org.bukkit.Server;
 | 
				
			||||||
@@ -40,23 +30,32 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
 | 
				
			|||||||
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 org.jetbrains.annotations.NotNull;
 | 
				
			||||||
import org.jetbrains.annotations.Nullable;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Field bukkitEntity;
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Player loadPlayer(@NotNull OfflinePlayer offline) {
 | 
				
			||||||
    public PlayerDataManager() {
 | 
					        // Ensure the player has data
 | 
				
			||||||
        try {
 | 
					        if (!offline.hasPlayedBefore()) {
 | 
				
			||||||
            bukkitEntity = Entity.class.getDeclaredField("bukkitEntity");
 | 
					            return null;
 | 
				
			||||||
        } catch (NoSuchFieldException e) {
 | 
					        }
 | 
				
			||||||
            System.out.println("Unable to obtain field to inject custom save process - players' mounts may be deleted when loaded.");
 | 
					
 | 
				
			||||||
            e.printStackTrace();
 | 
					        // Create a profile and entity to load the player data
 | 
				
			||||||
            bukkitEntity = null;
 | 
					        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.getBukkitEntity();
 | 
				
			||||||
 | 
					        if (target != null) {
 | 
				
			||||||
 | 
					            // Load data
 | 
				
			||||||
 | 
					            target.loadData();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // Return the entity
 | 
				
			||||||
 | 
					        return target;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    public static EntityPlayer getHandle(Player player) {
 | 
					    public static EntityPlayer getHandle(Player player) {
 | 
				
			||||||
        if (player instanceof CraftPlayer) {
 | 
					        if (player instanceof CraftPlayer) {
 | 
				
			||||||
            return ((CraftPlayer) player).getHandle();
 | 
					            return ((CraftPlayer) player).getHandle();
 | 
				
			||||||
@@ -77,125 +76,9 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
        return nmsPlayer;
 | 
					        return nmsPlayer;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player loadPlayer(@NotNull OfflinePlayer offline) {
 | 
					 | 
				
			||||||
        // Ensure the 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() != null ? offline.getName() : offline.getUniqueId().toString());
 | 
					 | 
				
			||||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
 | 
					 | 
				
			||||||
                new PlayerInteractManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            injectPlayer(entity);
 | 
					 | 
				
			||||||
        } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Get the bukkit entity
 | 
					 | 
				
			||||||
        Player target = entity.getBukkitEntity();
 | 
					 | 
				
			||||||
        if (target != null) {
 | 
					 | 
				
			||||||
            // Load data
 | 
					 | 
				
			||||||
            target.loadData();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        // Return the entity
 | 
					 | 
				
			||||||
        return target;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    void injectPlayer(EntityPlayer player) throws IllegalAccessException {
 | 
					 | 
				
			||||||
        if (bukkitEntity == null) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        bukkitEntity.setAccessible(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        bukkitEntity.set(player, new CraftPlayer(player.server.server, player) {
 | 
					 | 
				
			||||||
            @Override
 | 
					 | 
				
			||||||
            public void saveData() {
 | 
					 | 
				
			||||||
                super.saveData();
 | 
					 | 
				
			||||||
                // See net.minecraft.server.WorldNBTStorage#save(EntityHuman)
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    WorldNBTStorage worldNBTStorage = (WorldNBTStorage) player.server.getPlayerList().playerFileData;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    NBTTagCompound playerData = new NBTTagCompound();
 | 
					 | 
				
			||||||
                    player.e(playerData);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (!isOnline()) {
 | 
					 | 
				
			||||||
                        // Special case: save old vehicle data
 | 
					 | 
				
			||||||
                        NBTTagCompound oldData = worldNBTStorage.load(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        if (oldData != null && oldData.hasKeyOfType("Riding", 10)) {
 | 
					 | 
				
			||||||
                            // See net.minecraft.server.PlayerList#a(NetworkManager, EntityPlayer) and net.minecraft.server.EntityPlayer#b(NBTTagCompound)
 | 
					 | 
				
			||||||
                            playerData.set("Riding", oldData.getCompound("Riding"));
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    File file = new File(worldNBTStorage.getPlayerDir(), player.getUniqueID().toString() + ".dat.tmp");
 | 
					 | 
				
			||||||
                    File file1 = new File(worldNBTStorage.getPlayerDir(), player.getUniqueID().toString() + ".dat");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    NBTCompressedStreamTools.a(playerData, new FileOutputStream(file));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (file1.exists()) {
 | 
					 | 
				
			||||||
                        file1.delete();
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    file.renameTo(file1);
 | 
					 | 
				
			||||||
                } catch (Exception e) {
 | 
					 | 
				
			||||||
                    LogManager.getLogger().warn("Failed to save player data for {}", player.getName());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Player inject(@NotNull Player player) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            EntityPlayer nmsPlayer = getHandle(player);
 | 
					 | 
				
			||||||
            injectPlayer(nmsPlayer);
 | 
					 | 
				
			||||||
            return nmsPlayer.getBukkitEntity();
 | 
					 | 
				
			||||||
        } catch (IllegalAccessException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            return player;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
 | 
					    public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
 | 
				
			||||||
        return player.openInventory(inventory.getBukkitInventory());
 | 
					        return player.openInventory(inventory.getBukkitInventory());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void sendSystemMessage(@NotNull Player player, @NotNull String message) {
 | 
					 | 
				
			||||||
        int newline = message.indexOf('\n');
 | 
					 | 
				
			||||||
        if (newline != -1) {
 | 
					 | 
				
			||||||
            // No newlines in action bar chat.
 | 
					 | 
				
			||||||
            message = message.substring(0, newline);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (message.isEmpty()) {
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        EntityPlayer nmsPlayer = getHandle(player);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // For action bar chat, color codes are still supported but JSON text color is not allowed. Do not convert text.
 | 
					 | 
				
			||||||
        if (nmsPlayer.playerConnection != null) {
 | 
					 | 
				
			||||||
            nmsPlayer.playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(message), (byte) 2));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @NotNull
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getLocale(Player player) {
 | 
					 | 
				
			||||||
        return getHandle(player).locale;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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-2020 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-2020 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>4.1.2-SNAPSHOT</version>
 | 
					    <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
  </parent>
 | 
					  </parent>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <artifactId>openinvplugincore</artifactId>
 | 
					  <artifactId>openinvplugincore</artifactId>
 | 
				
			||||||
@@ -30,13 +30,13 @@
 | 
				
			|||||||
  <dependencies>
 | 
					  <dependencies>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>com.lishid</groupId>
 | 
					      <groupId>com.lishid</groupId>
 | 
				
			||||||
      <artifactId>openinvapi</artifactId>
 | 
					      <artifactId>openinvcommon</artifactId>
 | 
				
			||||||
      <version>4.1.2-SNAPSHOT</version>
 | 
					      <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>org.spigotmc</groupId>
 | 
					      <groupId>org.spigotmc</groupId>
 | 
				
			||||||
      <artifactId>spigot-api</artifactId>
 | 
					      <artifactId>spigot-api</artifactId>
 | 
				
			||||||
      <version>1.15.2-R0.1-SNAPSHOT</version>
 | 
					      <version>1.8.8-R0.1-SNAPSHOT</version>
 | 
				
			||||||
      <scope>provided</scope>
 | 
					      <scope>provided</scope>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
@@ -52,7 +52,7 @@
 | 
				
			|||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <groupId>org.apache.maven.plugins</groupId>
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
        <artifactId>maven-shade-plugin</artifactId>
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
        <version>3.2.2</version>
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <minimizeJar>true</minimizeJar>
 | 
					          <minimizeJar>true</minimizeJar>
 | 
				
			||||||
        </configuration>
 | 
					        </configuration>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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,11 +18,11 @@ package com.lishid.openinv;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.google.common.collect.HashMultimap;
 | 
					import com.google.common.collect.HashMultimap;
 | 
				
			||||||
import com.google.common.collect.Multimap;
 | 
					import com.google.common.collect.Multimap;
 | 
				
			||||||
import com.lishid.openinv.commands.ContainerSettingCommand;
 | 
					import com.lishid.openinv.commands.AnyChestPluginCommand;
 | 
				
			||||||
import com.lishid.openinv.commands.OpenInvCommand;
 | 
					import com.lishid.openinv.commands.OpenInvPluginCommand;
 | 
				
			||||||
import com.lishid.openinv.commands.SearchContainerCommand;
 | 
					import com.lishid.openinv.commands.SearchEnchantPluginCommand;
 | 
				
			||||||
import com.lishid.openinv.commands.SearchEnchantCommand;
 | 
					import com.lishid.openinv.commands.SearchInvPluginCommand;
 | 
				
			||||||
import com.lishid.openinv.commands.SearchInvCommand;
 | 
					import com.lishid.openinv.commands.SilentChestPluginCommand;
 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
					import com.lishid.openinv.internal.IAnySilentContainer;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialInventory;
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
@@ -34,8 +34,8 @@ import com.lishid.openinv.listeners.PlayerListener;
 | 
				
			|||||||
import com.lishid.openinv.listeners.PluginListener;
 | 
					import com.lishid.openinv.listeners.PluginListener;
 | 
				
			||||||
import com.lishid.openinv.util.Cache;
 | 
					import com.lishid.openinv.util.Cache;
 | 
				
			||||||
import com.lishid.openinv.util.ConfigUpdater;
 | 
					import com.lishid.openinv.util.ConfigUpdater;
 | 
				
			||||||
 | 
					import com.lishid.openinv.util.Function;
 | 
				
			||||||
import com.lishid.openinv.util.InternalAccessor;
 | 
					import com.lishid.openinv.util.InternalAccessor;
 | 
				
			||||||
import com.lishid.openinv.util.LanguageManager;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.Permissions;
 | 
					import com.lishid.openinv.util.Permissions;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
@@ -46,7 +46,6 @@ import java.util.concurrent.Future;
 | 
				
			|||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
import org.bukkit.command.CommandExecutor;
 | 
					 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.command.PluginCommand;
 | 
					import org.bukkit.command.PluginCommand;
 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
@@ -72,16 +71,21 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
    private final Multimap<String, Class<? extends Plugin>> pluginUsage = HashMultimap.create();
 | 
					    private final Multimap<String, Class<? extends Plugin>> pluginUsage = HashMultimap.create();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final Cache<String, Player> playerCache = new Cache<>(300000L,
 | 
					    private final Cache<String, Player> playerCache = new Cache<>(300000L,
 | 
				
			||||||
            value -> {
 | 
					            new Function<Player>() {
 | 
				
			||||||
                String key = OpenInv.this.getPlayerID(value);
 | 
					                @Override
 | 
				
			||||||
 | 
					                public boolean run(final Player value) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    String key = OpenInv.this.getPlayerID(value);
 | 
				
			||||||
                    return OpenInv.this.inventories.containsKey(key)
 | 
					                    return OpenInv.this.inventories.containsKey(key)
 | 
				
			||||||
                            && OpenInv.this.inventories.get(key).isInUse()
 | 
					                            && OpenInv.this.inventories.get(key).isInUse()
 | 
				
			||||||
                            || OpenInv.this.enderChests.containsKey(key)
 | 
					                            || OpenInv.this.enderChests.containsKey(key)
 | 
				
			||||||
                            && OpenInv.this.enderChests.get(key).isInUse()
 | 
					                            && OpenInv.this.enderChests.get(key).isInUse()
 | 
				
			||||||
                            || OpenInv.this.pluginUsage.containsKey(key);
 | 
					                            || OpenInv.this.pluginUsage.containsKey(key);
 | 
				
			||||||
            },
 | 
					                }
 | 
				
			||||||
            value -> {
 | 
					            }, new Function<Player>() {
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public boolean run(final Player value) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            String key = OpenInv.this.getPlayerID(value);
 | 
					            String key = OpenInv.this.getPlayerID(value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Check if inventory is stored, and if it is, remove it and eject all viewers
 | 
					            // Check if inventory is stored, and if it is, remove it and eject all viewers
 | 
				
			||||||
@@ -106,10 +110,10 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
                value.saveData();
 | 
					                value.saveData();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private InternalAccessor accessor;
 | 
					    private InternalAccessor accessor;
 | 
				
			||||||
    private LanguageManager languageManager;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Evicts all viewers lacking cross-world permissions from a Player's inventory.
 | 
					     * Evicts all viewers lacking cross-world permissions from a Player's inventory.
 | 
				
			||||||
@@ -131,7 +135,8 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
                HumanEntity human = iterator.next();
 | 
					                HumanEntity human = iterator.next();
 | 
				
			||||||
                // If player has permission or is in the same world, allow continued access
 | 
					                // If player has permission or is in the same world, allow continued access
 | 
				
			||||||
                // Just in case, also allow null worlds.
 | 
					                // Just in case, also allow null worlds.
 | 
				
			||||||
                if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld().equals(player.getWorld())) {
 | 
					                if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
 | 
				
			||||||
 | 
					                        || human.getWorld().equals(player.getWorld())) {
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                human.closeInventory();
 | 
					                human.closeInventory();
 | 
				
			||||||
@@ -142,7 +147,8 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
            Iterator<HumanEntity> iterator = this.enderChests.get(key).getBukkitInventory().getViewers().iterator();
 | 
					            Iterator<HumanEntity> iterator = this.enderChests.get(key).getBukkitInventory().getViewers().iterator();
 | 
				
			||||||
            while (iterator.hasNext()) {
 | 
					            while (iterator.hasNext()) {
 | 
				
			||||||
                HumanEntity human = iterator.next();
 | 
					                HumanEntity human = iterator.next();
 | 
				
			||||||
                if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld().equals(player.getWorld())) {
 | 
					                if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
 | 
				
			||||||
 | 
					                        || human.getWorld().equals(player.getWorld())) {
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                human.closeInventory();
 | 
					                human.closeInventory();
 | 
				
			||||||
@@ -161,6 +167,50 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
        return this.accessor.getAnySilentContainer();
 | 
					        return this.accessor.getAnySilentContainer();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int getLevenshteinDistance(final String string1, final String string2) {
 | 
				
			||||||
 | 
					        if (string1 == null || string2 == null) {
 | 
				
			||||||
 | 
					            throw new IllegalArgumentException("Strings must not be null");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (string1.isEmpty()) {
 | 
				
			||||||
 | 
					            return string2.length();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (string2.isEmpty()) {
 | 
				
			||||||
 | 
					            return string2.length();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (string1.equals(string2)) {
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int len1 = string1.length();
 | 
				
			||||||
 | 
					        int len2 = string2.length();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int[] prevDistances = new int[len1 + 1];
 | 
				
			||||||
 | 
					        int[] distances = new int[len1 + 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (int i = 0; i <= len1; ++i) {
 | 
				
			||||||
 | 
					            prevDistances[i] = i;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (int i = 1; i <= len2; ++i) {
 | 
				
			||||||
 | 
					            // TODO: include tweaks available in Simmetrics?
 | 
				
			||||||
 | 
					            char string2char = string2.charAt(i - 1);
 | 
				
			||||||
 | 
					            distances[0] = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (int j = 1; j <= len1; ++j) {
 | 
				
			||||||
 | 
					                int cost = string1.charAt(j - 1) == string2char ? 0 : 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                distances[j] = Math.min(Math.min(distances[j - 1] + 1, prevDistances[j] + 1), prevDistances[j - 1] + cost);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            int[] swap = prevDistances;
 | 
				
			||||||
 | 
					            prevDistances = distances;
 | 
				
			||||||
 | 
					            distances = swap;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return prevDistances[len1];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean getPlayerAnyChestStatus(@NotNull final OfflinePlayer player) {
 | 
					    public boolean getPlayerAnyChestStatus(@NotNull final OfflinePlayer player) {
 | 
				
			||||||
        boolean defaultState = false;
 | 
					        boolean defaultState = false;
 | 
				
			||||||
@@ -285,47 +335,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
        return this.accessor.getPlayerDataManager().openInventory(player, inventory);
 | 
					        return this.accessor.getPlayerDataManager().openInventory(player, inventory);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void sendMessage(@NotNull CommandSender sender, @NotNull String key) {
 | 
					 | 
				
			||||||
        String message = this.languageManager.getValue(key, getLocale(sender));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (message != null && !message.isEmpty()) {
 | 
					 | 
				
			||||||
            sender.sendMessage(message);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void sendMessage(@NotNull CommandSender sender, @NotNull String key, String... replacements) {
 | 
					 | 
				
			||||||
        String message = this.languageManager.getValue(key, getLocale(sender), replacements);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (message != null && !message.isEmpty()) {
 | 
					 | 
				
			||||||
            sender.sendMessage(message);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void sendSystemMessage(@NotNull Player player, @NotNull String key) {
 | 
					 | 
				
			||||||
        String message = this.languageManager.getValue(key, getLocale(player));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (message != null) {
 | 
					 | 
				
			||||||
            this.accessor.getPlayerDataManager().sendSystemMessage(player, message);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @Nullable String getLocalizedMessage(@NotNull CommandSender sender, @NotNull String key) {
 | 
					 | 
				
			||||||
        return this.languageManager.getValue(key, getLocale(sender));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public @Nullable String getLocalizedMessage(@NotNull CommandSender sender, @NotNull String key, String... replacements) {
 | 
					 | 
				
			||||||
        return this.languageManager.getValue(key, getLocale(sender), replacements);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    private String getLocale(@NotNull CommandSender sender) {
 | 
					 | 
				
			||||||
        if (sender instanceof Player) {
 | 
					 | 
				
			||||||
            return this.accessor.getPlayerDataManager().getLocale((Player) sender);
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            return this.getConfig().getString("settings.locale", "en_us");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean notifyAnyChest() {
 | 
					    public boolean notifyAnyChest() {
 | 
				
			||||||
        return this.getConfig().getBoolean("notify.any-chest", true);
 | 
					        return this.getConfig().getBoolean("notify.any-chest", true);
 | 
				
			||||||
@@ -359,8 +368,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.accessor = new InternalAccessor(this);
 | 
					        this.accessor = new InternalAccessor(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.languageManager = new LanguageManager(this, "en_us");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Version check
 | 
					        // Version check
 | 
				
			||||||
        if (this.accessor.isSupported()) {
 | 
					        if (this.accessor.isSupported()) {
 | 
				
			||||||
            // Update existing configuration. May require internal access.
 | 
					            // Update existing configuration. May require internal access.
 | 
				
			||||||
@@ -375,18 +382,15 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
            pm.registerEvents(new InventoryDragListener(), this);
 | 
					            pm.registerEvents(new InventoryDragListener(), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Register commands to their executors
 | 
					            // Register commands to their executors
 | 
				
			||||||
            OpenInvCommand openInv = new OpenInvCommand(this);
 | 
					            OpenInvPluginCommand openInv = new OpenInvPluginCommand(this);
 | 
				
			||||||
            this.setCommandExecutor("openinv", openInv);
 | 
					            this.getCommand("openinv").setExecutor(openInv);
 | 
				
			||||||
            this.setCommandExecutor("openender", openInv);
 | 
					            this.getCommand("openender").setExecutor(openInv);
 | 
				
			||||||
            this.setCommandExecutor("searchcontainer", new SearchContainerCommand(this));
 | 
					            SearchInvPluginCommand searchInv = new SearchInvPluginCommand(this);
 | 
				
			||||||
            SearchInvCommand searchInv = new SearchInvCommand(this);
 | 
					            this.getCommand("searchinv").setExecutor(searchInv);
 | 
				
			||||||
            this.setCommandExecutor("searchinv", searchInv);
 | 
					            this.getCommand("searchender").setExecutor(searchInv);
 | 
				
			||||||
            this.setCommandExecutor("searchender", searchInv);
 | 
					            this.getCommand("searchenchant").setExecutor(new SearchEnchantPluginCommand(this));
 | 
				
			||||||
            this.setCommandExecutor("searchenchant", new SearchEnchantCommand(this));
 | 
					            this.getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
 | 
				
			||||||
            ContainerSettingCommand settingCommand = new ContainerSettingCommand(this);
 | 
					            this.getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
 | 
				
			||||||
            this.setCommandExecutor("silentcontainer", settingCommand);
 | 
					 | 
				
			||||||
            this.setCommandExecutor("anycontainer", settingCommand);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.getLogger().info("Your version of CraftBukkit (" + this.accessor.getVersion() + ") is not supported.");
 | 
					            this.getLogger().info("Your version of CraftBukkit (" + this.accessor.getVersion() + ") is not supported.");
 | 
				
			||||||
            this.getLogger().info("If this version is a recent release, check for an update.");
 | 
					            this.getLogger().info("If this version is a recent release, check for an update.");
 | 
				
			||||||
@@ -395,18 +399,12 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void setCommandExecutor(String commandName, CommandExecutor executor) {
 | 
					 | 
				
			||||||
        PluginCommand command = this.getCommand(commandName);
 | 
					 | 
				
			||||||
        if (command != null) {
 | 
					 | 
				
			||||||
            command.setExecutor(executor);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (!this.accessor.isSupported()) {
 | 
					        if (!this.accessor.isSupported()) {
 | 
				
			||||||
            sender.sendMessage("Your version of CraftBukkit (" + this.accessor.getVersion() + ") is not supported.");
 | 
					            sender.sendMessage("Your version of CraftBukkit (" + this.accessor.getVersion() + ") is not supported.");
 | 
				
			||||||
            sender.sendMessage("If this version is a recent release, check for an update.");
 | 
					            sender.sendMessage("If this version is a recent release, check for an update.");
 | 
				
			||||||
 | 
					            sender.sendMessage("If this is an older version, ensure that you've downloaded the legacy support version.");
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
@@ -469,9 +467,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Replace stored player with our own version
 | 
					 | 
				
			||||||
        this.playerCache.put(key, this.accessor.getPlayerDataManager().inject(player));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (this.inventories.containsKey(key)) {
 | 
					        if (this.inventories.containsKey(key)) {
 | 
				
			||||||
            this.inventories.get(key).setPlayerOffline();
 | 
					            this.inventories.get(key).setPlayerOffline();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,54 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class AnyChestPluginCommand implements CommandExecutor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public AnyChestPluginCommand(final OpenInv plugin) {
 | 
				
			||||||
 | 
					        this.plugin = plugin;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
 | 
				
			||||||
 | 
					        if (!(sender instanceof Player)) {
 | 
				
			||||||
 | 
					            sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Player player = (Player) sender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
 | 
				
			||||||
 | 
					            sender.sendMessage("AnyChest is " + (this.plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.plugin.setPlayerAnyChestStatus(player, !this.plugin.getPlayerAnyChestStatus(player));
 | 
				
			||||||
 | 
					        sender.sendMessage("AnyChest is now " + (this.plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,87 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2020 lishid. All rights reserved.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * 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.commands;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.TabCompleter;
 | 
					 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import java.util.function.BiConsumer;
 | 
					 | 
				
			||||||
import java.util.function.Function;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					 | 
				
			||||||
import org.bukkit.command.TabExecutor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class ContainerSettingCommand implements TabExecutor {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final OpenInv plugin;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ContainerSettingCommand(final OpenInv plugin) {
 | 
					 | 
				
			||||||
        this.plugin = plugin;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					 | 
				
			||||||
        if (!(sender instanceof Player)) {
 | 
					 | 
				
			||||||
            plugin.sendMessage(sender, "messages.error.consoleUnsupported");
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Player player = (Player) sender;
 | 
					 | 
				
			||||||
        boolean any = command.getName().startsWith("any");
 | 
					 | 
				
			||||||
        Function<Player, Boolean> getSetting = any ? plugin::getPlayerAnyChestStatus : plugin::getPlayerSilentChestStatus;
 | 
					 | 
				
			||||||
        BiConsumer<OfflinePlayer, Boolean> setSetting = any ? plugin::setPlayerAnyChestStatus : plugin::setPlayerSilentChestStatus;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (args.length > 0) {
 | 
					 | 
				
			||||||
            args[0] = args[0].toLowerCase();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (args[0].equals("on")) {
 | 
					 | 
				
			||||||
                setSetting.accept(player, true);
 | 
					 | 
				
			||||||
            } else if (args[0].equals("off")) {
 | 
					 | 
				
			||||||
                setSetting.accept(player, false);
 | 
					 | 
				
			||||||
            } else if (!args[0].equals("check")) {
 | 
					 | 
				
			||||||
                // Invalid argument, show usage.
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            setSetting.accept(player, !getSetting.apply(player));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String onOff = plugin.getLocalizedMessage(player, getSetting.apply(player) ? "messages.info.on" : "messages.info.off");
 | 
					 | 
				
			||||||
        if (onOff == null) {
 | 
					 | 
				
			||||||
            onOff = String.valueOf(getSetting.apply(player));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        plugin.sendMessage(sender, "messages.info.settingState","%setting%", any ? "AnyContainer" : "SilentContainer", "%state%", onOff);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					 | 
				
			||||||
        if (!command.testPermissionSilent(sender) || args.length != 1) {
 | 
					 | 
				
			||||||
            return Collections.emptyList();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return TabCompleter.completeString(args[0], new String[] {"check", "on", "off"});
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -19,36 +19,33 @@ package com.lishid.openinv.commands;
 | 
				
			|||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialInventory;
 | 
					import com.lishid.openinv.internal.ISpecialInventory;
 | 
				
			||||||
import com.lishid.openinv.util.Permissions;
 | 
					import com.lishid.openinv.util.Permissions;
 | 
				
			||||||
import com.lishid.openinv.util.TabCompleter;
 | 
					 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.List;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.command.TabExecutor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
					import org.bukkit.scheduler.BukkitRunnable;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class OpenInvCommand implements TabExecutor {
 | 
					public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final OpenInv plugin;
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
    private final HashMap<Player, String> openInvHistory = new HashMap<>();
 | 
					    private final HashMap<Player, String> openInvHistory = new HashMap<Player, String>();
 | 
				
			||||||
    private final HashMap<Player, String> openEnderHistory = new HashMap<>();
 | 
					    private final HashMap<Player, String> openEnderHistory = new HashMap<Player, String>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public OpenInvCommand(final OpenInv plugin) {
 | 
					    public OpenInvPluginCommand(final OpenInv plugin) {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command, @NotNull final String label, @NotNull final String[] args) {
 | 
					    public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
 | 
				
			||||||
        if (!(sender instanceof Player)) {
 | 
					        if (!(sender instanceof Player)) {
 | 
				
			||||||
            plugin.sendMessage(sender, "messages.error.consoleUnsupported");
 | 
					            sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (args.length > 0 && (args[0].equalsIgnoreCase("help") || args[0].equals("?"))) {
 | 
					        if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
 | 
				
			||||||
            this.plugin.showHelp((Player) sender);
 | 
					            this.plugin.showHelp((Player) sender);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -76,10 +73,10 @@ public class OpenInvCommand implements TabExecutor {
 | 
				
			|||||||
        new BukkitRunnable() {
 | 
					        new BukkitRunnable() {
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
            public void run() {
 | 
					            public void run() {
 | 
				
			||||||
                final OfflinePlayer offlinePlayer = OpenInvCommand.this.plugin.matchPlayer(name);
 | 
					                final OfflinePlayer offlinePlayer = OpenInvPluginCommand.this.plugin.matchPlayer(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
 | 
					                if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
 | 
				
			||||||
                    plugin.sendMessage(player, "messages.error.invalidPlayer");
 | 
					                    player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -89,9 +86,9 @@ public class OpenInvCommand implements TabExecutor {
 | 
				
			|||||||
                        if (!player.isOnline()) {
 | 
					                        if (!player.isOnline()) {
 | 
				
			||||||
                            return;
 | 
					                            return;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        OpenInvCommand.this.openInventory(player, offlinePlayer, openinv);
 | 
					                        OpenInvPluginCommand.this.openInventory(player, offlinePlayer, openinv);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }.runTask(OpenInvCommand.this.plugin);
 | 
					                }.runTask(OpenInvPluginCommand.this.plugin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }.runTaskAsynchronously(this.plugin);
 | 
					        }.runTaskAsynchronously(this.plugin);
 | 
				
			||||||
@@ -100,58 +97,49 @@ public class OpenInvCommand implements TabExecutor {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void openInventory(final Player player, final OfflinePlayer target, boolean openinv) {
 | 
					    private void openInventory(final Player player, final OfflinePlayer target, boolean openinv) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Player onlineTarget;
 | 
					        Player onlineTarget;
 | 
				
			||||||
        boolean online = target.isOnline();
 | 
					        boolean online = target.isOnline();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!online) {
 | 
					        if (!online) {
 | 
				
			||||||
            if (Permissions.OPENOFFLINE.hasPermission(player)) {
 | 
					 | 
				
			||||||
            // Try loading the player's data
 | 
					            // Try loading the player's data
 | 
				
			||||||
            onlineTarget = this.plugin.loadPlayer(target);
 | 
					            onlineTarget = this.plugin.loadPlayer(target);
 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                plugin.sendMessage(player, "messages.error.permissionPlayerOffline");
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            if (Permissions.OPENONLINE.hasPermission(player)) {
 | 
					 | 
				
			||||||
                onlineTarget = target.getPlayer();
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                plugin.sendMessage(player, "messages.error.permissionPlayerOnline");
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (onlineTarget == null) {
 | 
					            if (onlineTarget == null) {
 | 
				
			||||||
            plugin.sendMessage(player, "messages.error.invalidPlayer");
 | 
					                player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            onlineTarget = target.getPlayer();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Permissions checks
 | 
					        // Permissions checks
 | 
				
			||||||
        if (onlineTarget.equals(player)) {
 | 
					        if (onlineTarget.equals(player)) {
 | 
				
			||||||
            // Inventory: Additional permission required to open own inventory
 | 
					            // Inventory: Additional permission required to open own inventory
 | 
				
			||||||
            if (openinv && !Permissions.OPENSELF.hasPermission(player)) {
 | 
					            if (openinv && !Permissions.OPENSELF.hasPermission(player)) {
 | 
				
			||||||
                plugin.sendMessage(player, "messages.error.permissionOpenSelf");
 | 
					                player.sendMessage(ChatColor.RED + "You're not allowed to open your own inventory!");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            // Enderchest: Additional permission required to open others' ender chests
 | 
					            // Enderchest: Additional permission required to open others' ender chests
 | 
				
			||||||
            if (!openinv && !Permissions.ENDERCHEST_ALL.hasPermission(player)) {
 | 
					            if (!openinv && !Permissions.ENDERCHEST_ALL.hasPermission(player)) {
 | 
				
			||||||
                plugin.sendMessage(player, "messages.error.permissionEnderAll");
 | 
					                player.sendMessage(ChatColor.RED + "You do not have permission to access other players' ender chests.");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Protected check
 | 
					            // Protected check
 | 
				
			||||||
            if (!Permissions.OVERRIDE.hasPermission(player)
 | 
					            if (!Permissions.OVERRIDE.hasPermission(player)
 | 
				
			||||||
                    && Permissions.EXEMPT.hasPermission(onlineTarget)) {
 | 
					                    && Permissions.EXEMPT.hasPermission(onlineTarget)) {
 | 
				
			||||||
                plugin.sendMessage(player, "messages.error.permissionExempt",
 | 
					                player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
 | 
				
			||||||
                        "%target%", onlineTarget.getDisplayName());
 | 
					 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Crossworld check
 | 
					            // Crossworld check
 | 
				
			||||||
            if (!Permissions.CROSSWORLD.hasPermission(player)
 | 
					            if (!Permissions.CROSSWORLD.hasPermission(player)
 | 
				
			||||||
                    && !onlineTarget.getWorld().equals(player.getWorld())) {
 | 
					                    && !onlineTarget.getWorld().equals(player.getWorld())) {
 | 
				
			||||||
                plugin.sendMessage(player, "messages.error.permissionCrossWorld",
 | 
					                player.sendMessage(
 | 
				
			||||||
                        "%target%", onlineTarget.getDisplayName());
 | 
					                        ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -164,7 +152,7 @@ public class OpenInvCommand implements TabExecutor {
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            inv = openinv ? this.plugin.getSpecialInventory(onlineTarget, online) : this.plugin.getSpecialEnderChest(onlineTarget, online);
 | 
					            inv = openinv ? this.plugin.getSpecialInventory(onlineTarget, online) : this.plugin.getSpecialEnderChest(onlineTarget, online);
 | 
				
			||||||
        } catch (Exception e) {
 | 
					        } catch (Exception e) {
 | 
				
			||||||
            plugin.sendMessage(player, "messages.error.commandException");
 | 
					            player.sendMessage(ChatColor.RED + "An error occurred creating " + onlineTarget.getDisplayName() + "'s inventory!");
 | 
				
			||||||
            e.printStackTrace();
 | 
					            e.printStackTrace();
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -173,13 +161,4 @@ public class OpenInvCommand implements TabExecutor {
 | 
				
			|||||||
        plugin.openInventory(player, inv);
 | 
					        plugin.openInventory(player, inv);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					 | 
				
			||||||
        if (!command.testPermissionSilent(sender) || args.length != 1) {
 | 
					 | 
				
			||||||
            return Collections.emptyList();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return TabCompleter.completeOnlinePlayer(sender, args[0]);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,129 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2020 lishid. All rights reserved.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * 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.commands;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.util.TabCompleter;
 | 
					 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import org.bukkit.Chunk;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.World;
 | 
					 | 
				
			||||||
import org.bukkit.block.BlockState;
 | 
					 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					 | 
				
			||||||
import org.bukkit.command.TabExecutor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Command for searching containers in a radius of chunks.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class SearchContainerCommand implements TabExecutor {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private final OpenInv plugin;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SearchContainerCommand(OpenInv plugin) {
 | 
					 | 
				
			||||||
        this.plugin = plugin;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					 | 
				
			||||||
        if (!(sender instanceof Player)) {
 | 
					 | 
				
			||||||
            plugin.sendMessage(sender, "messages.error.consoleUnsupported");
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (args.length < 1) {
 | 
					 | 
				
			||||||
            // Must supply material
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Material material = Material.getMaterial(args[0].toUpperCase());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (material == null) {
 | 
					 | 
				
			||||||
            plugin.sendMessage(sender, "messages.error.invalidMaterial", "%target%", args[0]);
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int radius = 5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (args.length > 1) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                radius = Integer.parseInt(args[1]);
 | 
					 | 
				
			||||||
            } catch (NumberFormatException e) {
 | 
					 | 
				
			||||||
                // Invalid radius supplied
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Player senderPlayer = (Player) sender;
 | 
					 | 
				
			||||||
        World world = senderPlayer.getWorld();
 | 
					 | 
				
			||||||
        Chunk centerChunk = senderPlayer.getLocation().getChunk();
 | 
					 | 
				
			||||||
        StringBuilder locations = new StringBuilder();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (int dX = -radius; dX <= radius; ++dX) {
 | 
					 | 
				
			||||||
            for (int dZ = -radius; dZ <= radius; ++dZ) {
 | 
					 | 
				
			||||||
                if (!world.loadChunk(centerChunk.getX() + dX, centerChunk.getZ() + dZ, false)) {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                Chunk chunk = world.getChunkAt(centerChunk.getX() + dX, centerChunk.getZ() + dZ);
 | 
					 | 
				
			||||||
                for (BlockState tileEntity : chunk.getTileEntities()) {
 | 
					 | 
				
			||||||
                    if (!(tileEntity instanceof InventoryHolder)) {
 | 
					 | 
				
			||||||
                        continue;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    InventoryHolder holder = (InventoryHolder) tileEntity;
 | 
					 | 
				
			||||||
                    if (!holder.getInventory().contains(material)) {
 | 
					 | 
				
			||||||
                        continue;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    locations.append(holder.getInventory().getType().name().toLowerCase()).append(" (")
 | 
					 | 
				
			||||||
                            .append(tileEntity.getX()).append(',').append(tileEntity.getY()).append(',')
 | 
					 | 
				
			||||||
                            .append(tileEntity.getZ()).append("), ");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Matches found, delete trailing comma and space
 | 
					 | 
				
			||||||
        if (locations.length() > 0) {
 | 
					 | 
				
			||||||
            locations.delete(locations.length() - 2, locations.length());
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            plugin.sendMessage(sender, "messages.info.container.noMatches",
 | 
					 | 
				
			||||||
                    "%target%", material.name());
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        plugin.sendMessage(sender, "messages.info.container.matches",
 | 
					 | 
				
			||||||
                "%target%", material.name(), "%detail%", locations.toString());
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
 | 
					 | 
				
			||||||
        if (args.length < 1 || args.length > 2 || !command.testPermissionSilent(sender)) {
 | 
					 | 
				
			||||||
            return Collections.emptyList();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String argument = args[args.length - 1];
 | 
					 | 
				
			||||||
        if (args.length == 1) {
 | 
					 | 
				
			||||||
            return TabCompleter.completeEnum(argument, Material.class);
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            return TabCompleter.completeInteger(argument);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -17,20 +17,15 @@
 | 
				
			|||||||
package com.lishid.openinv.commands;
 | 
					package com.lishid.openinv.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.util.TabCompleter;
 | 
					 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.NamespacedKey;
 | 
					 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.command.TabExecutor;
 | 
					 | 
				
			||||||
import org.bukkit.enchantments.Enchantment;
 | 
					import org.bukkit.enchantments.Enchantment;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
import org.bukkit.inventory.ItemStack;
 | 
					import org.bukkit.inventory.ItemStack;
 | 
				
			||||||
import org.bukkit.inventory.meta.ItemMeta;
 | 
					import org.bukkit.inventory.meta.ItemMeta;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Command adding the ability to search online players' inventories for enchantments of a specific
 | 
					 * Command adding the ability to search online players' inventories for enchantments of a specific
 | 
				
			||||||
@@ -38,16 +33,16 @@ import org.jetbrains.annotations.NotNull;
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author Jikoo
 | 
					 * @author Jikoo
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class SearchEnchantCommand implements TabExecutor {
 | 
					public class SearchEnchantPluginCommand implements CommandExecutor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final OpenInv plugin;
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public SearchEnchantCommand(OpenInv plugin) {
 | 
					    public SearchEnchantPluginCommand(OpenInv plugin) {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (args.length == 0) {
 | 
					        if (args.length == 0) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -56,28 +51,14 @@ public class SearchEnchantCommand implements TabExecutor {
 | 
				
			|||||||
        int level = 0;
 | 
					        int level = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (String argument : args) {
 | 
					        for (String argument : args) {
 | 
				
			||||||
            try {
 | 
					            Enchantment localEnchant = Enchantment.getByName(argument.toUpperCase());
 | 
				
			||||||
                level = Integer.parseInt(argument);
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            } catch (NumberFormatException ignored) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            argument = argument.toLowerCase();
 | 
					 | 
				
			||||||
            int colon = argument.indexOf(':');
 | 
					 | 
				
			||||||
            NamespacedKey key;
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                if (colon > -1 && colon < argument.length() - 1) {
 | 
					 | 
				
			||||||
                    key = new NamespacedKey(argument.substring(0, colon), argument.substring(colon + 1));
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    key = NamespacedKey.minecraft(argument);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            } catch (IllegalArgumentException ignored) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            Enchantment localEnchant = Enchantment.getByKey(key);
 | 
					 | 
				
			||||||
            if (localEnchant != null) {
 | 
					            if (localEnchant != null) {
 | 
				
			||||||
                enchant = localEnchant;
 | 
					                enchant = localEnchant;
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                level = Integer.parseInt(argument);
 | 
				
			||||||
 | 
					            } catch (NumberFormatException ignored) {}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Arguments not set correctly
 | 
					        // Arguments not set correctly
 | 
				
			||||||
@@ -113,14 +94,12 @@ public class SearchEnchantCommand implements TabExecutor {
 | 
				
			|||||||
            // Matches found, delete trailing comma and space
 | 
					            // Matches found, delete trailing comma and space
 | 
				
			||||||
            players.delete(players.length() - 2, players.length());
 | 
					            players.delete(players.length() - 2, players.length());
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            plugin.sendMessage(sender, "messages.info.player.noMatches",
 | 
					            sender.sendMessage("No players found with " + (enchant == null ? "any enchant" : enchant.getName())
 | 
				
			||||||
                    "%target%", (enchant != null ? enchant.getKey().toString() : "") + " >= " + level);
 | 
					                    + " of level " + level + " or higher.");
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        plugin.sendMessage(sender, "messages.info.player.matches",
 | 
					        sender.sendMessage("Players: " + players.toString());
 | 
				
			||||||
                "%target%", (enchant != null ? enchant.getKey().toString() : "") + " >= " + level,
 | 
					 | 
				
			||||||
                "%detail%", players.toString());
 | 
					 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -138,7 +117,7 @@ public class SearchEnchantCommand implements TabExecutor {
 | 
				
			|||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                ItemMeta meta = item.getItemMeta();
 | 
					                ItemMeta meta = item.getItemMeta();
 | 
				
			||||||
                if (meta == null || !meta.hasEnchants()) {
 | 
					                if (!meta.hasEnchants()) {
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                for (int enchLevel : meta.getEnchants().values()) {
 | 
					                for (int enchLevel : meta.getEnchants().values()) {
 | 
				
			||||||
@@ -151,17 +130,4 @@ public class SearchEnchantCommand implements TabExecutor {
 | 
				
			|||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					 | 
				
			||||||
        if (!command.testPermissionSilent(sender) || args.length < 1 || args.length > 2) {
 | 
					 | 
				
			||||||
            return Collections.emptyList();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (args.length == 1) {
 | 
					 | 
				
			||||||
            return TabCompleter.completeObject(args[0], enchantment -> enchantment.getKey().toString(), Enchantment.values());
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            return TabCompleter.completeInteger(args[1]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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
 | 
				
			||||||
@@ -17,54 +17,50 @@
 | 
				
			|||||||
package com.lishid.openinv.commands;
 | 
					package com.lishid.openinv.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.util.TabCompleter;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.command.TabExecutor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SearchInvCommand implements TabExecutor {
 | 
					public class SearchInvPluginCommand implements CommandExecutor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final OpenInv plugin;
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public SearchInvCommand(OpenInv plugin) {
 | 
					    public SearchInvPluginCommand(OpenInv plugin) {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Material material = null;
 | 
					        Material material = null;
 | 
				
			||||||
 | 
					        int count = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (args.length >= 1) {
 | 
					        if (args.length >= 1) {
 | 
				
			||||||
            material = Material.getMaterial(args[0].toUpperCase());
 | 
					            String[] gData = args[0].split(":");
 | 
				
			||||||
 | 
					            material = Material.matchMaterial(gData[0]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (material == null) {
 | 
					 | 
				
			||||||
            plugin.sendMessage(sender, "messages.error.invalidMaterial", "%target%", args.length > 0 ? args[0] : "null");
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int count = 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (args.length >= 2) {
 | 
					        if (args.length >= 2) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                count = Integer.parseInt(args[1]);
 | 
					                count = Integer.parseInt(args[1]);
 | 
				
			||||||
            } catch (NumberFormatException ex) {
 | 
					            } catch (NumberFormatException ex) {
 | 
				
			||||||
                plugin.sendMessage(sender, "messages.error.invalidNumber", "%target%", args[1]);
 | 
					                sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (material == null) {
 | 
				
			||||||
 | 
					            sender.sendMessage(ChatColor.RED + "Unknown item");
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        StringBuilder players = new StringBuilder();
 | 
					        StringBuilder players = new StringBuilder();
 | 
				
			||||||
        boolean searchInv = command.getName().equals("searchinv");
 | 
					 | 
				
			||||||
        for (Player player : plugin.getServer().getOnlinePlayers()) {
 | 
					        for (Player player : plugin.getServer().getOnlinePlayers()) {
 | 
				
			||||||
            Inventory inventory = searchInv ? player.getInventory() : player.getEnderChest();
 | 
					            Inventory inventory = command.getName().equals("searchinv") ? player.getInventory() : player.getEnderChest();
 | 
				
			||||||
            if (inventory.contains(material, count)) {
 | 
					            if (inventory.contains(material, count)) {
 | 
				
			||||||
                players.append(player.getName()).append(", ");
 | 
					                players.append(player.getName()).append(", ");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -74,28 +70,11 @@ public class SearchInvCommand implements TabExecutor {
 | 
				
			|||||||
        if (players.length() > 0) {
 | 
					        if (players.length() > 0) {
 | 
				
			||||||
            players.delete(players.length() - 2, players.length());
 | 
					            players.delete(players.length() - 2, players.length());
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            plugin.sendMessage(sender, "messages.info.player.noMatches",
 | 
					            sender.sendMessage("No players found with " + material.toString());
 | 
				
			||||||
                    "%target%", material.name());
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sender.sendMessage("Players with the item " + material.toString() + ": " + players.toString());
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        plugin.sendMessage(sender, "messages.info.player.matches",
 | 
					 | 
				
			||||||
                "%target%", material.name(), "%detail%", players.toString());
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | 
					 | 
				
			||||||
        if (args.length < 1 || args.length > 2 || !command.testPermissionSilent(sender)) {
 | 
					 | 
				
			||||||
            return Collections.emptyList();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String argument = args[args.length - 1];
 | 
					 | 
				
			||||||
        if (args.length == 1) {
 | 
					 | 
				
			||||||
            return TabCompleter.completeEnum(argument, Material.class);
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            return TabCompleter.completeInteger(argument);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SilentChestPluginCommand implements CommandExecutor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SilentChestPluginCommand(OpenInv plugin) {
 | 
				
			||||||
 | 
					        this.plugin = plugin;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (!(sender instanceof Player)) {
 | 
				
			||||||
 | 
					            sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Player player = (Player) sender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
 | 
				
			||||||
 | 
					            sender.sendMessage("SilentChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        plugin.setPlayerSilentChestStatus(player, !plugin.getPlayerSilentChestStatus(player));
 | 
				
			||||||
 | 
					        sender.sendMessage("SilentChest is now " + (plugin.getPlayerSilentChestStatus(player) ? "ON" : "OFF") + ".");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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-2020 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-2020 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-2020 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
 | 
				
			||||||
@@ -37,7 +37,7 @@ public class PlayerListener implements Listener {
 | 
				
			|||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler(priority = EventPriority.LOWEST)
 | 
					    @EventHandler(priority = EventPriority.MONITOR)
 | 
				
			||||||
    public void onPlayerJoin(final PlayerJoinEvent event) {
 | 
					    public void onPlayerJoin(final PlayerJoinEvent event) {
 | 
				
			||||||
        plugin.setPlayerOnline(event.getPlayer());
 | 
					        plugin.setPlayerOnline(event.getPlayer());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -55,7 +55,7 @@ public class PlayerListener implements Listener {
 | 
				
			|||||||
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
					    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
				
			||||||
    public void onPlayerInteract(PlayerInteractEvent event) {
 | 
					    public void onPlayerInteract(PlayerInteractEvent event) {
 | 
				
			||||||
        if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking()
 | 
					        if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking()
 | 
				
			||||||
                || event.useInteractedBlock() == Result.DENY || event.getClickedBlock() == null
 | 
					                || event.useInteractedBlock() == Result.DENY
 | 
				
			||||||
                || !plugin.getAnySilentContainer().isAnySilentContainer(event.getClickedBlock())) {
 | 
					                || !plugin.getAnySilentContainer().isAnySilentContainer(event.getClickedBlock())) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -71,15 +71,13 @@ public class PlayerListener implements Listener {
 | 
				
			|||||||
        boolean silent = Permissions.SILENT.hasPermission(player) && plugin.getPlayerSilentChestStatus(player);
 | 
					        boolean silent = Permissions.SILENT.hasPermission(player) && plugin.getPlayerSilentChestStatus(player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // If anycontainer or silentcontainer is active
 | 
					        // If anycontainer or silentcontainer is active
 | 
				
			||||||
        if (any || silent) {
 | 
					        if ((any || silent) && plugin.getAnySilentContainer().activateContainer(player, silent, event.getClickedBlock())) {
 | 
				
			||||||
            if (plugin.getAnySilentContainer().activateContainer(player, silent, event.getClickedBlock())) {
 | 
					 | 
				
			||||||
            if (silent && plugin.notifySilentChest() && needsAny && plugin.notifyAnyChest()) {
 | 
					            if (silent && plugin.notifySilentChest() && needsAny && plugin.notifyAnyChest()) {
 | 
				
			||||||
                    plugin.sendSystemMessage(player, "messages.info.containerBlockedSilent");
 | 
					                player.sendMessage("You are opening a blocked container silently.");
 | 
				
			||||||
                } else if (needsAny && plugin.notifyAnyChest()) {
 | 
					 | 
				
			||||||
                    plugin.sendSystemMessage(player, "messages.info.containerBlocked");
 | 
					 | 
				
			||||||
            } else if (silent && plugin.notifySilentChest()) {
 | 
					            } else if (silent && plugin.notifySilentChest()) {
 | 
				
			||||||
                    plugin.sendSystemMessage(player, "messages.info.containerSilent");
 | 
					                player.sendMessage("You are opening a container silently.");
 | 
				
			||||||
                }
 | 
					            } else if (needsAny && plugin.notifyAnyChest()) {
 | 
				
			||||||
 | 
					                player.sendMessage("You are opening a blocked container.");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            event.setCancelled(true);
 | 
					            event.setCancelled(true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2011-2020 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-2020 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
 | 
				
			||||||
@@ -59,9 +59,6 @@ public class ConfigUpdater {
 | 
				
			|||||||
                if (version < 3) {
 | 
					                if (version < 3) {
 | 
				
			||||||
                    updateConfig2To3();
 | 
					                    updateConfig2To3();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (version < 4) {
 | 
					 | 
				
			||||||
                    updateConfig3To4();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                new BukkitRunnable() {
 | 
					                new BukkitRunnable() {
 | 
				
			||||||
                    @Override
 | 
					                    @Override
 | 
				
			||||||
@@ -74,17 +71,6 @@ public class ConfigUpdater {
 | 
				
			|||||||
        }.runTaskAsynchronously(plugin);
 | 
					        }.runTaskAsynchronously(plugin);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void updateConfig3To4() {
 | 
					 | 
				
			||||||
        new BukkitRunnable() {
 | 
					 | 
				
			||||||
            @Override
 | 
					 | 
				
			||||||
            public void run() {
 | 
					 | 
				
			||||||
                plugin.getConfig().set("notify", null);
 | 
					 | 
				
			||||||
                plugin.getConfig().set("settings.locale", "en_US");
 | 
					 | 
				
			||||||
                plugin.getConfig().set("config-version", 4);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }.runTask(plugin);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void updateConfig2To3() {
 | 
					    private void updateConfig2To3() {
 | 
				
			||||||
        new BukkitRunnable() {
 | 
					        new BukkitRunnable() {
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,170 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2020 Jikoo. 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.OpenInv;
 | 
					 | 
				
			||||||
import java.io.BufferedReader;
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.io.IOException;
 | 
					 | 
				
			||||||
import java.io.InputStream;
 | 
					 | 
				
			||||||
import java.io.InputStreamReader;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.HashMap;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import java.util.Map;
 | 
					 | 
				
			||||||
import java.util.logging.Level;
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.configuration.file.YamlConfiguration;
 | 
					 | 
				
			||||||
import org.jetbrains.annotations.NotNull;
 | 
					 | 
				
			||||||
import org.jetbrains.annotations.Nullable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * A simple language manager supporting both custom and bundled languages.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @author Jikoo
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class LanguageManager {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private final OpenInv plugin;
 | 
					 | 
				
			||||||
	private final String defaultLocale;
 | 
					 | 
				
			||||||
	private Map<String, YamlConfiguration> locales;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public LanguageManager(@NotNull OpenInv plugin, @NotNull String defaultLocale) {
 | 
					 | 
				
			||||||
		this.plugin = plugin;
 | 
					 | 
				
			||||||
		this.defaultLocale = defaultLocale;
 | 
					 | 
				
			||||||
		this.locales = new HashMap<>();
 | 
					 | 
				
			||||||
		getOrLoadLocale(defaultLocale);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private YamlConfiguration getOrLoadLocale(@NotNull String locale) {
 | 
					 | 
				
			||||||
		YamlConfiguration loaded = locales.get(locale);
 | 
					 | 
				
			||||||
		if (loaded != null) {
 | 
					 | 
				
			||||||
			return loaded;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		InputStream resourceStream = plugin.getResource(locale + ".yml");
 | 
					 | 
				
			||||||
		YamlConfiguration localeConfigDefaults;
 | 
					 | 
				
			||||||
		if (resourceStream == null) {
 | 
					 | 
				
			||||||
			localeConfigDefaults = new YamlConfiguration();
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceStream))) {
 | 
					 | 
				
			||||||
				localeConfigDefaults = YamlConfiguration.loadConfiguration(reader);
 | 
					 | 
				
			||||||
			} catch (IOException e) {
 | 
					 | 
				
			||||||
				plugin.getLogger().log(Level.WARNING, "[LanguageManager] Unable to load resource " + locale + ".yml", e);
 | 
					 | 
				
			||||||
				localeConfigDefaults = new YamlConfiguration();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		File file = new File(plugin.getDataFolder(), locale + ".yml");
 | 
					 | 
				
			||||||
		YamlConfiguration localeConfig;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (!file.exists()) {
 | 
					 | 
				
			||||||
			localeConfig = localeConfigDefaults;
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				localeConfigDefaults.save(file);
 | 
					 | 
				
			||||||
			} catch (IOException e) {
 | 
					 | 
				
			||||||
				plugin.getLogger().log(Level.WARNING, "[LanguageManager] Unable to save resource " + locale + ".yml", e);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			localeConfig = YamlConfiguration.loadConfiguration(file);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Add new language keys
 | 
					 | 
				
			||||||
			List<String> newKeys = new ArrayList<>();
 | 
					 | 
				
			||||||
			for (String key : localeConfigDefaults.getKeys(true)) {
 | 
					 | 
				
			||||||
				if (localeConfigDefaults.isConfigurationSection(key)) {
 | 
					 | 
				
			||||||
					continue;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (localeConfig.isSet(key)) {
 | 
					 | 
				
			||||||
					continue;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				localeConfig.set(key, localeConfigDefaults.get(key));
 | 
					 | 
				
			||||||
				newKeys.add(key);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (!newKeys.isEmpty()) {
 | 
					 | 
				
			||||||
				plugin.getLogger().info("[LanguageManager] Added new language keys: " + String.join(", ", newKeys));
 | 
					 | 
				
			||||||
				try {
 | 
					 | 
				
			||||||
					localeConfig.save(file);
 | 
					 | 
				
			||||||
				} catch (IOException e) {
 | 
					 | 
				
			||||||
					plugin.getLogger().log(Level.WARNING, "[LanguageManager] Unable to save resource " + locale + ".yml", e);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (!locale.equals(defaultLocale)) {
 | 
					 | 
				
			||||||
			localeConfigDefaults = locales.get(defaultLocale);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Check for missing keys
 | 
					 | 
				
			||||||
			List<String> newKeys = new ArrayList<>();
 | 
					 | 
				
			||||||
			for (String key : localeConfigDefaults.getKeys(true)) {
 | 
					 | 
				
			||||||
				if (localeConfigDefaults.isConfigurationSection(key)) {
 | 
					 | 
				
			||||||
					continue;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (localeConfig.isSet(key)) {
 | 
					 | 
				
			||||||
					continue;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				newKeys.add(key);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (!newKeys.isEmpty()) {
 | 
					 | 
				
			||||||
				plugin.getLogger().info("[LanguageManager] Missing translations from " + locale + ".yml: " + String.join(", ", newKeys));
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Fall through to default locale
 | 
					 | 
				
			||||||
			localeConfig.setDefaults(localeConfigDefaults);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		locales.put(locale, localeConfig);
 | 
					 | 
				
			||||||
		return localeConfig;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Nullable
 | 
					 | 
				
			||||||
	public String getValue(@NotNull String key, @Nullable String locale) {
 | 
					 | 
				
			||||||
		String value = getOrLoadLocale(locale == null ? defaultLocale : locale.toLowerCase()).getString(key);
 | 
					 | 
				
			||||||
		if (value == null || value.isEmpty()) {
 | 
					 | 
				
			||||||
			return null;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		value = ChatColor.translateAlternateColorCodes('&', value);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return value;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Nullable
 | 
					 | 
				
			||||||
	public String getValue(@NotNull String key, @Nullable String locale, @NotNull String... replacements) {
 | 
					 | 
				
			||||||
		if (replacements.length % 2 != 0) {
 | 
					 | 
				
			||||||
			plugin.getLogger().log(Level.WARNING, "[LanguageManager] Replacement data is uneven", new Exception());
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		String value = getValue(key, locale);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (value == null) {
 | 
					 | 
				
			||||||
			return null;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		for (int i = 0; i < replacements.length; i += 2) {
 | 
					 | 
				
			||||||
			value = value.replace(replacements[i], replacements[i + 1]);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return value;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,147 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2020 lishid. All rights reserved.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * 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.ArrayList;
 | 
					 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import java.util.Locale;
 | 
					 | 
				
			||||||
import java.util.function.Function;
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.util.StringUtil;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Utility class for common tab completions.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class TabCompleter {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Offer tab completions for whole numbers.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param argument the argument to complete
 | 
					 | 
				
			||||||
     * @return integer options
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public static List<String> completeInteger(String argument) {
 | 
					 | 
				
			||||||
        // Ensure existing argument is actually a number
 | 
					 | 
				
			||||||
        if (!argument.isEmpty()) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                Integer.parseInt(argument);
 | 
					 | 
				
			||||||
            } catch (NumberFormatException e) {
 | 
					 | 
				
			||||||
                return Collections.emptyList();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        List<String> completions = new ArrayList<>(10);
 | 
					 | 
				
			||||||
        for (int i = 0; i < 10; ++i) {
 | 
					 | 
				
			||||||
            completions.add(argument + i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return completions;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Offer tab completions for a given Enum.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param argument the argument to complete
 | 
					 | 
				
			||||||
     * @param enumClazz the Enum to complete for
 | 
					 | 
				
			||||||
     * @return the matching Enum values
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public static List<String> completeEnum(String argument, Class<? extends Enum<?>> enumClazz) {
 | 
					 | 
				
			||||||
        argument = argument.toLowerCase(Locale.ENGLISH);
 | 
					 | 
				
			||||||
        List<String> completions = new ArrayList<>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (Enum<?> enumConstant : enumClazz.getEnumConstants()) {
 | 
					 | 
				
			||||||
            String name = enumConstant.name().toLowerCase();
 | 
					 | 
				
			||||||
            if (name.startsWith(argument)) {
 | 
					 | 
				
			||||||
                completions.add(name);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return completions;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Offer tab completions for a given array of Strings.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param argument the argument to complete
 | 
					 | 
				
			||||||
     * @param options the Strings which may be completed
 | 
					 | 
				
			||||||
     * @return the matching Strings
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public static List<String> completeString(String argument, String[] options) {
 | 
					 | 
				
			||||||
        argument = argument.toLowerCase(Locale.ENGLISH);
 | 
					 | 
				
			||||||
        List<String> completions = new ArrayList<>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (String option : options) {
 | 
					 | 
				
			||||||
            if (option.startsWith(argument)) {
 | 
					 | 
				
			||||||
                completions.add(option);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return completions;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Offer tab completions for visible online Players' names.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param sender the command's sender
 | 
					 | 
				
			||||||
     * @param argument the argument to complete
 | 
					 | 
				
			||||||
     * @return the matching Players' names
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public static List<String> completeOnlinePlayer(CommandSender sender, String argument) {
 | 
					 | 
				
			||||||
        List<String> completions = new ArrayList<>();
 | 
					 | 
				
			||||||
        Player senderPlayer = sender instanceof Player ? (Player) sender : null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (Player player : Bukkit.getOnlinePlayers()) {
 | 
					 | 
				
			||||||
            if (senderPlayer != null && !senderPlayer.canSee(player)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (StringUtil.startsWithIgnoreCase(player.getName(), argument)) {
 | 
					 | 
				
			||||||
                completions.add(player.getName());
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return completions;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Offer tab completions for a given array of Objects.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param argument the argument to complete
 | 
					 | 
				
			||||||
     * @param converter the Function for converting the Object into a comparable String
 | 
					 | 
				
			||||||
     * @param options the Objects which may be completed
 | 
					 | 
				
			||||||
     * @return the matching Strings
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public static <T> List<String> completeObject(String argument, Function<T, String> converter, T[] options) {
 | 
					 | 
				
			||||||
        argument = argument.toLowerCase(Locale.ENGLISH);
 | 
					 | 
				
			||||||
        List<String> completions = new ArrayList<>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (T option : options) {
 | 
					 | 
				
			||||||
            String optionString = converter.apply(option).toLowerCase();
 | 
					 | 
				
			||||||
            if (optionString.startsWith(argument)) {
 | 
					 | 
				
			||||||
                completions.add(optionString);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return completions;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private TabCompleter() {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
config-version: 4
 | 
					config-version: 3
 | 
				
			||||||
 | 
					notify:
 | 
				
			||||||
 | 
					  any-chest: true
 | 
				
			||||||
 | 
					  silent-chest: true
 | 
				
			||||||
settings:
 | 
					settings:
 | 
				
			||||||
  disable-saving: false
 | 
					  disable-saving: false
 | 
				
			||||||
  locale: 'en_us'
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,30 +0,0 @@
 | 
				
			|||||||
messages:
 | 
					 | 
				
			||||||
  error:
 | 
					 | 
				
			||||||
    consoleUnsupported: 'You cannot use this command from console.'
 | 
					 | 
				
			||||||
    lootNotGenerated: '&cLoot not generated! Please disable &b/silentcontainer&c.'
 | 
					 | 
				
			||||||
    invalidMaterial: '&cInvalid material: "%target%"'
 | 
					 | 
				
			||||||
    invalidNumber: '&cInvalid number: "%target%"'
 | 
					 | 
				
			||||||
    invalidPlayer: '&cPlayer not found!'
 | 
					 | 
				
			||||||
    permissionOpenSelf: '&cYou''re not allowed to open your own inventory.'
 | 
					 | 
				
			||||||
    permissionEnderAll: '&cYou''re not allowed to access other players'' ender chests.'
 | 
					 | 
				
			||||||
    permissionExempt: '&c%target%''s inventory is protected.'
 | 
					 | 
				
			||||||
    permissionCrossWorld: '&c%target% is not in your world.'
 | 
					 | 
				
			||||||
    permissionPlayerOnline: '&cYou''re not allowed to open the inventory of online players.'
 | 
					 | 
				
			||||||
    permissionPlayerOffline: '&cYou''re not allowed to open the inventory of offline players.'
 | 
					 | 
				
			||||||
    commandException: '&cAn error occurred. Please check console for details.'
 | 
					 | 
				
			||||||
  info:
 | 
					 | 
				
			||||||
    containerBlocked: 'You are opening a blocked container.'
 | 
					 | 
				
			||||||
    containerBlockedSilent: 'You are opening a blocked container silently.'
 | 
					 | 
				
			||||||
    containerSilent: 'You are opening a container silently.'
 | 
					 | 
				
			||||||
    settingState: '%setting%: %state%'
 | 
					 | 
				
			||||||
    player:
 | 
					 | 
				
			||||||
      noMatches: 'No players found with %target%.'
 | 
					 | 
				
			||||||
      matches: 'Players holding %target%: %detail%'
 | 
					 | 
				
			||||||
    container:
 | 
					 | 
				
			||||||
      noMatches: 'No containers found with %target%.'
 | 
					 | 
				
			||||||
      matches: 'Containers holding %target%: %detail%'
 | 
					 | 
				
			||||||
    on: 'on'
 | 
					 | 
				
			||||||
    off: 'off'
 | 
					 | 
				
			||||||
container:
 | 
					 | 
				
			||||||
  player: '%player%''s Inventory'
 | 
					 | 
				
			||||||
  enderchest: '%player%''s Ender Chest'
 | 
					 | 
				
			||||||
@@ -5,7 +5,7 @@ author: lishid
 | 
				
			|||||||
authors: [Jikoo, ShadowRanger]
 | 
					authors: [Jikoo, ShadowRanger]
 | 
				
			||||||
description: >
 | 
					description: >
 | 
				
			||||||
             This plugin allows you to open a player's inventory as a chest and interact with it in real time.
 | 
					             This plugin allows you to open a player's inventory as a chest and interact with it in real time.
 | 
				
			||||||
api-version: "1.14"
 | 
					api-version: "1.13"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
permissions:
 | 
					permissions:
 | 
				
			||||||
  OpenInv.any.default:
 | 
					  OpenInv.any.default:
 | 
				
			||||||
@@ -24,19 +24,6 @@ permissions:
 | 
				
			|||||||
      OpenInv.silent: true
 | 
					      OpenInv.silent: true
 | 
				
			||||||
      OpenInv.anychest: true
 | 
					      OpenInv.anychest: true
 | 
				
			||||||
      OpenInv.searchenchant: true
 | 
					      OpenInv.searchenchant: true
 | 
				
			||||||
      OpenInv.searchcontainer: true
 | 
					 | 
				
			||||||
      OpenInv.openonline: true
 | 
					 | 
				
			||||||
      OpenInv.openoffline: true
 | 
					 | 
				
			||||||
  OpenInv.openinv:
 | 
					 | 
				
			||||||
    default: op
 | 
					 | 
				
			||||||
    children:
 | 
					 | 
				
			||||||
      OpenInv.openonline: true
 | 
					 | 
				
			||||||
      OpenInv.openoffline: true
 | 
					 | 
				
			||||||
  OpenInv.openender:
 | 
					 | 
				
			||||||
    default: op
 | 
					 | 
				
			||||||
    children:
 | 
					 | 
				
			||||||
      OpenInv.openonline: true
 | 
					 | 
				
			||||||
      OpenInv.openoffline: true
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
commands:
 | 
					commands:
 | 
				
			||||||
  openinv:
 | 
					  openinv:
 | 
				
			||||||
@@ -56,33 +43,28 @@ commands:
 | 
				
			|||||||
    description: Search and list players having a specific item
 | 
					    description: Search and list players having a specific item
 | 
				
			||||||
    permission: OpenInv.search
 | 
					    permission: OpenInv.search
 | 
				
			||||||
    usage: |-
 | 
					    usage: |-
 | 
				
			||||||
           /<command> <Material> [MinAmount] - MinAmount is optional, the minimum amount required
 | 
					           /<command> <Item> [MinAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required
 | 
				
			||||||
  searchender:
 | 
					  searchender:
 | 
				
			||||||
    aliases: [se]
 | 
					    aliases: [se]
 | 
				
			||||||
    permission: OpenInv.search
 | 
					    permission: OpenInv.search
 | 
				
			||||||
    description: Searches and lists players having a specific item in their ender chest
 | 
					    description: Searches and lists players having a specific item in their ender chest
 | 
				
			||||||
    usage: |-
 | 
					    usage: |-
 | 
				
			||||||
           /<command> <Material> [MinAmount] - MinAmount is optional, the minimum amount required
 | 
					           /<command> <item> [MinAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required
 | 
				
			||||||
  silentcontainer:
 | 
					  silentcontainer:
 | 
				
			||||||
    aliases: [sc, silent, silentchest]
 | 
					    aliases: [sc, silent, silentchest]
 | 
				
			||||||
    description: SilentContainer stops sounds and animations when using containers.
 | 
					    description: Toggle SilentContainer function, which stops sounds and animations when using containers.
 | 
				
			||||||
    permission: OpenInv.silent
 | 
					    permission: OpenInv.silent
 | 
				
			||||||
    usage: |-
 | 
					    usage: |-
 | 
				
			||||||
           /<command> [check|on|off] - Check, toggle, or set SilentContainer
 | 
					           /<command> [Check] - Check or toggle silent chest
 | 
				
			||||||
  anycontainer:
 | 
					  anycontainer:
 | 
				
			||||||
    aliases: [ac, anychest]
 | 
					    aliases: [ac, anychest]
 | 
				
			||||||
    description: AnyContainer allows using blocked containers.
 | 
					    description: Toggle AnyContainer function, which allows opening of blocked containers.
 | 
				
			||||||
    permission: OpenInv.anychest
 | 
					    permission: OpenInv.anychest
 | 
				
			||||||
    usage: |-
 | 
					    usage: |-
 | 
				
			||||||
           /<command> [check|on|off] - Check, toggle, or set AnyContainer
 | 
					           /<command> [Check] - Checks or toggle anychest
 | 
				
			||||||
  searchenchant:
 | 
					  searchenchant:
 | 
				
			||||||
    aliases: [searchenchants]
 | 
					    aliases: [searchenchants]
 | 
				
			||||||
    description: Search and list players with a specific enchantment.
 | 
					    description: Search and list players with a specific enchantment.
 | 
				
			||||||
    permission: OpenInv.searchenchant
 | 
					    permission: OpenInv.searchenchant
 | 
				
			||||||
    usage: |-
 | 
					    usage: |-
 | 
				
			||||||
           /<command> <[Enchantment] [MinLevel]> - Enchantment is the enchantment type, MinLevel is the minimum level. One is optional
 | 
					           /<command> <[enchantment] [MinLevel]> - Enchantment is the enchantment type, MinLevel is the minimum level. One is optional
 | 
				
			||||||
  searchcontainer:
 | 
					 | 
				
			||||||
    aliases: [searchchest]
 | 
					 | 
				
			||||||
    description: Search and list containers with a specific material.
 | 
					 | 
				
			||||||
    permission: OpenInv.searchcontainer
 | 
					 | 
				
			||||||
    usage: /<command> <Material> [ChunkRadius] - ChunkRadius is optional, the length that will be searched for matching items. Default 5
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,30 +0,0 @@
 | 
				
			|||||||
messages:
 | 
					 | 
				
			||||||
  error:
 | 
					 | 
				
			||||||
    consoleUnsupported: 'Voce nao consegue usar esse comando pelo console.'
 | 
					 | 
				
			||||||
    lootNotGenerated: '&cPilhagem nao gerada! Por favor desabilite &b/silentcontainer&c.'
 | 
					 | 
				
			||||||
    invalidMaterial: '&cMaterial invalido: "%target%"'
 | 
					 | 
				
			||||||
    invalidNumber: '&cNumero invalido: "%target%"'
 | 
					 | 
				
			||||||
    invalidPlayer: '&cJogador nao encontrado!'
 | 
					 | 
				
			||||||
    permissionOpenSelf: '&cVoce nao pode abrir seu proprio inventario.'
 | 
					 | 
				
			||||||
    permissionEnderAll: '&cVoce nao tem permissao para abrir baus de ender de outros jogadores.'
 | 
					 | 
				
			||||||
    permissionExempt: '&cO inventario de %target% e protegido.'
 | 
					 | 
				
			||||||
    permissionCrossWorld: '&c%target% nao esta no seu mundo.'
 | 
					 | 
				
			||||||
    permissionPlayerOnline: '&cVoce nao tem permissao para abrir o inventario de jogadores online.'
 | 
					 | 
				
			||||||
    permissionPlayerOffline: '&cVoce nao tem permissao para abrir o inventario de jogadores offline.'
 | 
					 | 
				
			||||||
    commandException: '&cUm erro ocorreu. Por favor cheque o console para detalhes.'
 | 
					 | 
				
			||||||
  info:
 | 
					 | 
				
			||||||
    containerBlocked: 'Voce esta abrindo um recipiente bloqueado.'
 | 
					 | 
				
			||||||
    containerBlockedSilent: 'Voce esta abrindo um recipiente bloqueado silenciosamente.'
 | 
					 | 
				
			||||||
    containerSilent: 'Voce esta abrindo um recipiente silenciosamente.'
 | 
					 | 
				
			||||||
    settingState: '%setting%: %state%'
 | 
					 | 
				
			||||||
    player:
 | 
					 | 
				
			||||||
      noMatches: 'Nenhum jogador encontrado com %target%.'
 | 
					 | 
				
			||||||
      matches: 'Jogadores segurando %target%: %detail%'
 | 
					 | 
				
			||||||
    container:
 | 
					 | 
				
			||||||
      noMatches: 'Nenhum recipiente encontrado com %target%.'
 | 
					 | 
				
			||||||
      matches: 'Recipientes contendo %target%: %detail%'
 | 
					 | 
				
			||||||
    on: 'ligado'
 | 
					 | 
				
			||||||
    off: 'desligado'
 | 
					 | 
				
			||||||
container:
 | 
					 | 
				
			||||||
  player: 'Inventario de %player%'
 | 
					 | 
				
			||||||
  enderchest: 'Bau de Ender de %player%'
 | 
					 | 
				
			||||||
							
								
								
									
										7
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								pom.xml
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
  ~ Copyright (C) 2011-2020 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 @@
 | 
				
			|||||||
  <artifactId>openinvparent</artifactId>
 | 
					  <artifactId>openinvparent</artifactId>
 | 
				
			||||||
  <name>OpenInvParent</name>
 | 
					  <name>OpenInvParent</name>
 | 
				
			||||||
  <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
					  <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
				
			||||||
  <version>4.1.2-SNAPSHOT</version>
 | 
					  <version>4.0.8-SNAPSHOT</version>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <packaging>pom</packaging>
 | 
					  <packaging>pom</packaging>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,6 +31,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  <modules>
 | 
					  <modules>
 | 
				
			||||||
    <module>api</module>
 | 
					    <module>api</module>
 | 
				
			||||||
 | 
					    <module>common</module>
 | 
				
			||||||
    <module>plugin</module>
 | 
					    <module>plugin</module>
 | 
				
			||||||
    <module>internal</module>
 | 
					    <module>internal</module>
 | 
				
			||||||
    <module>assembly</module>
 | 
					    <module>assembly</module>
 | 
				
			||||||
@@ -88,7 +89,7 @@
 | 
				
			|||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
        <groupId>org.apache.maven.plugins</groupId>
 | 
					        <groupId>org.apache.maven.plugins</groupId>
 | 
				
			||||||
        <artifactId>maven-shade-plugin</artifactId>
 | 
					        <artifactId>maven-shade-plugin</artifactId>
 | 
				
			||||||
        <version>3.2.2</version>
 | 
					        <version>3.0.0</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <filters>
 | 
					          <filters>
 | 
				
			||||||
            <filter>
 | 
					            <filter>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user