Compare commits
245 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0c3ce2dfb3 | ||
|
a1f4649a09 | ||
|
100d0e12cd | ||
|
3e629798e5 | ||
|
7c1f15974c | ||
|
d992237766 | ||
|
c93464e643 | ||
|
56afefc82b | ||
|
f0a66570d2 | ||
|
201a3578bf | ||
|
1228fc2de2 | ||
|
2561e75ae5 | ||
|
80661b9465 | ||
|
53701da34f | ||
|
9cf4712813 | ||
|
abe8fccdb5 | ||
|
4499bb5453 | ||
|
5405b7d7b9 | ||
|
34199d12a4 | ||
|
67131ab9f9 | ||
|
723381cb2b | ||
|
34e7252d77 | ||
|
a1b2df74cc | ||
|
7210f9153e | ||
|
dcdfac0d3b | ||
|
c7b4554a6c | ||
|
c51acb4e72 | ||
|
23d41cd6c8 | ||
|
8bc389496b | ||
|
1cc36d08bd | ||
|
c8938f451d | ||
|
4f2665fedc | ||
|
7d93bb06ad | ||
|
19c491411f | ||
|
65c6eb2693 | ||
|
ab1f4ace8a | ||
|
e7dc52bee4 | ||
|
a9c5799677 | ||
|
6d6257720a | ||
|
3e235fa688 | ||
|
dd02355ac2 | ||
|
4d3f5d67a8 | ||
|
7ad5faa2ce | ||
|
c28383ef36 | ||
|
5fbab1ab8f | ||
|
d97b092978 | ||
|
154bf56c2a | ||
|
d65a9caeb2 | ||
|
b3c4253606 | ||
|
b64000e89b | ||
|
3faf41ef18 | ||
|
db27d25a93 | ||
|
0f02e6fe66 | ||
|
ec07637e9f | ||
|
b269f3509c | ||
|
f2e4c8a3ad | ||
|
35839f1548 | ||
|
a4a462a1fa | ||
|
b9f901af66 | ||
|
1333056613 | ||
|
fb23df313a | ||
|
96dc400c83 | ||
|
b801d36f12 | ||
|
4c27599dd9 | ||
|
64ad0a5267 | ||
|
cba7f44192 | ||
|
e8ace6bd06 | ||
|
fd70f260ba | ||
|
be9874ba1d | ||
|
096faef161 | ||
|
df96d5106a | ||
|
fe77a1d2e7 | ||
|
3096e43540 | ||
|
2939551d65 | ||
|
fb74fd3ced | ||
|
393fe1d837 | ||
|
f80df9d83b | ||
|
5c006f8ebd | ||
|
57097e626e | ||
|
0f266c8a64 | ||
|
185f037254 | ||
|
e4d0020296 | ||
|
9e37cbbca8 | ||
|
adc35e9ad5 | ||
|
a469c732cc | ||
|
c5c1f47167 | ||
|
dc59356f76 | ||
|
d497772ad7 | ||
|
4f4d46974a | ||
|
96c38895e2 | ||
|
5753648d77 | ||
|
3725711b94 | ||
|
c22e18c096 | ||
|
6bff759d72 | ||
|
582c7201dd | ||
|
59a8ed70bb | ||
|
27812c133d | ||
|
165f3fb00e | ||
|
60dcb64558 | ||
|
077b34d304 | ||
|
8ce6e2f8d3 | ||
|
f5dce23f18 | ||
|
669cfd72aa | ||
|
9e66885690 | ||
|
a802769265 | ||
|
50c45b6616 | ||
|
eaf01fa32c | ||
|
4abaa6ea51 | ||
|
7c621bf899 | ||
|
f5c682ff2b | ||
|
e652b43670 | ||
|
f07cef5621 | ||
|
ded6421e33 | ||
|
cbb2b4d232 | ||
|
48c61eeb82 | ||
|
e3d1af010b | ||
|
2195677651 | ||
|
c72af5dbac | ||
|
931cdb6fb1 | ||
|
9db18613a1 | ||
|
784935a975 | ||
|
d9abe76531 | ||
|
ca85a392aa | ||
|
307f47e4d3 | ||
|
96c59f163d | ||
|
01f147b13c | ||
|
1c104b775f | ||
|
9a53e46dd3 | ||
|
6744e71127 | ||
|
12c3ebb798 | ||
|
32ec8d8147 | ||
|
443e0c489e | ||
|
7ab0003b62 | ||
|
12c0cac311 | ||
|
f54481e872 | ||
|
f27dd8a233 | ||
|
d6df1a0871 | ||
|
e34e51d127 | ||
|
5ca2ae461a | ||
|
4095e8039d | ||
|
73f390ab20 | ||
|
2f7d3bc235 | ||
|
ef486032f1 | ||
|
72ef873772 | ||
|
9b6e32a775 | ||
|
f05110c9b8 | ||
|
a41f89b011 | ||
|
d24827ffcb | ||
|
802ce28103 | ||
|
f31356b227 | ||
|
7942466863 | ||
|
db2cade4e2 | ||
|
718b4bb5dd | ||
|
6aa25dd2dc | ||
|
0bbcf6cdb2 | ||
|
f11d60f78c | ||
|
8a6b98614f | ||
|
d7eec528e4 | ||
|
a10c61168a | ||
|
5c4886c66b | ||
|
4335b8dc2c | ||
|
3bf7225712 | ||
|
b76440ab9a | ||
|
3152605bca | ||
|
eaabd30dc2 | ||
|
de0d28b12d | ||
|
c3a8bc9486 | ||
|
5b77404597 | ||
|
d9c1b00b50 | ||
|
2fc439b306 | ||
|
2cb1b01fbf | ||
|
d16cca9847 | ||
|
e39f009661 | ||
|
1d622b653d | ||
|
582a958195 | ||
|
9245b4cc27 | ||
|
ba9396ad5c | ||
|
27de16cba9 | ||
|
90ea073089 | ||
|
4811e53d12 | ||
|
c7f38adb3f | ||
|
99a7359be3 | ||
|
d42cc3e275 | ||
|
b8f4589b87 | ||
|
f9ac6804b2 | ||
|
62f5d54676 | ||
|
8feca3fb21 | ||
|
7b16140ee1 | ||
|
14ec280d26 | ||
|
71ac05ae85 | ||
|
c4a9cb0a4a | ||
|
7ae87d1dbe | ||
|
346036b7e7 | ||
|
69c355c8cd | ||
|
8dbbe80dbf | ||
|
77e6ce8c7c | ||
|
cd405a9b9e | ||
|
b5d6cf047c | ||
|
aaa9c4e190 | ||
|
6ea09dc964 | ||
|
eace5ca8fb | ||
|
03308be7f5 | ||
|
4f40459b96 | ||
|
791368b100 | ||
|
5dd3f5bbd7 | ||
|
d1d60e55d5 | ||
|
471b631838 | ||
|
2f1fd87435 | ||
|
a03c73f8d6 | ||
|
f7029e5ee2 | ||
|
802e405c4e | ||
|
55deabe56b | ||
|
f8e4e69e53 | ||
|
3c7d1696ff | ||
|
902def1dd7 | ||
|
f260ed1175 | ||
|
bc40e91215 | ||
|
120b35d394 | ||
|
ded568ec3f | ||
|
e958059572 | ||
|
d988becf1f | ||
|
e8476d5b05 | ||
|
1ea0307156 | ||
|
4ae47b09dc | ||
|
3e9bb63894 | ||
|
dce86d9c69 | ||
|
4013098201 | ||
|
56f633d58b | ||
|
6c1fb14cda | ||
|
ad0e55cf4c | ||
|
c4fb5489fa | ||
|
3d3006c681 | ||
|
a9d983ddc6 | ||
|
f6554a2a51 | ||
|
ec3426b827 | ||
|
d0494aa2e7 | ||
|
6adcd491db | ||
|
bc709336e1 | ||
|
7d56a04283 | ||
|
7851404d69 | ||
|
30b5acc3b4 | ||
|
29b0bc980f | ||
|
b05279ed4b | ||
|
88f3cb0a3f | ||
|
f48fdac085 |
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
**/.settings
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.classpath
|
||||
**/.idea
|
||||
**.iml
|
||||
**/target
|
||||
**/bin
|
||||
**/out
|
||||
**dependency-reduced-pom.xml
|
||||
**pom.xml.versionsBackup
|
@@ -1,57 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinv</artifactId>
|
||||
<name>OpenInv</name>
|
||||
<version>2.5.2</version>
|
||||
|
||||
<build>
|
||||
<directory>../target</directory>
|
||||
<finalName>${project.name}</finalName>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<!--
|
||||
This keeps the final file clean, but may cause issues for people not familiar with the setup.
|
||||
If you're having trouble with the final product missing files, remove or tweak this configuration.
|
||||
-->
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>com.lishid:*</artifact>
|
||||
<includes>
|
||||
<include>com/lishid/openinv/**/*</include>
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
</project>
|
@@ -1,39 +0,0 @@
|
||||
name: OpenInv
|
||||
main: com.lishid.openinv.OpenInv
|
||||
version: ${project.version}
|
||||
author: lishid
|
||||
authors: [Jikoo]
|
||||
description: >
|
||||
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
|
||||
commands:
|
||||
openinv:
|
||||
aliases: [oi, inv, open]
|
||||
description: Open a player's inventory
|
||||
permission: OpenInv.*;OpenInv.openinv
|
||||
usage: |
|
||||
/<command> - Open last person's inventory
|
||||
/<command> <Player> - Open a player's inventory
|
||||
openender:
|
||||
aliases: [oe]
|
||||
description: Opens the enderchest of a player
|
||||
permission: OpenInv.*;OpenInv.openender
|
||||
usage: |
|
||||
/<command> <Player> - Opens a player's enderchest
|
||||
searchinv:
|
||||
aliases: [si]
|
||||
description: Search and list players having a specific item
|
||||
permission: OpenInv.*;OpenInv.search
|
||||
usage: |
|
||||
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
|
||||
silentchest:
|
||||
aliases: [sc, silent]
|
||||
description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound.
|
||||
permission: OpenInv.*;OpenInv.silent
|
||||
usage: |
|
||||
/<command> [Check] - Checks whether silent chest is enabled
|
||||
anychest:
|
||||
aliases: [ac]
|
||||
description: Toggle anychest function, which allows opening of blocked chests.
|
||||
permission: OpenInv.*;OpenInv.anychest
|
||||
usage: |
|
||||
/<command> [Check] - Checks whether anychest is enabled
|
@@ -1,22 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<name>OpenInvCore</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.5-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IPlayerDataManager {
|
||||
|
||||
/**
|
||||
* Loads a Player for an OfflinePlayer.
|
||||
* </p>
|
||||
* This method is potentially blocking, and should not be called on the main thread.
|
||||
*
|
||||
* @param offline
|
||||
* @return
|
||||
*/
|
||||
public Player loadPlayer(OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Gets a unique identifying string for an OfflinePlayer.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public String getPlayerDataID(OfflinePlayer player);
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface ISpecialEnderChest {
|
||||
|
||||
public Inventory getBukkitInventory();
|
||||
|
||||
/**
|
||||
* Sets the Player associated with this ISpecialEnderChest online.
|
||||
*
|
||||
* @param player the Player coming online
|
||||
*/
|
||||
public void setPlayerOnline(Player player);
|
||||
|
||||
/**
|
||||
* Sets the Player associated with this ISpecialEnderChest offline.
|
||||
*/
|
||||
public void setPlayerOffline();
|
||||
|
||||
/**
|
||||
* Gets whether or not this ISpecialEnderChest is in use.
|
||||
*
|
||||
* @return true if the ISpecialEnderChest is in use
|
||||
*/
|
||||
public boolean isInUse();
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface ISpecialPlayerInventory {
|
||||
|
||||
public Inventory getBukkitInventory();
|
||||
|
||||
/**
|
||||
* Sets the Player associated with this ISpecialPlayerInventory online.
|
||||
*
|
||||
* @param player the Player coming online
|
||||
*/
|
||||
public void setPlayerOnline(Player player);
|
||||
|
||||
/**
|
||||
* Sets the Player associated with this ISpecialPlayerInventory offline.
|
||||
*/
|
||||
public void setPlayerOffline();
|
||||
|
||||
/**
|
||||
* Gets whether or not this ISpecialPlayerInventory is in use.
|
||||
*
|
||||
* @return true if the ISpecialPlayerInventory is in use
|
||||
*/
|
||||
public boolean isInUse();
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_10_R1</artifactId>
|
||||
<name>OpenInvCraftbukkit1_10_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.10-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_10_R1;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_10_R1.Block;
|
||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
import net.minecraft.server.v1_10_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_10_R1.IInventory;
|
||||
import net.minecraft.server.v1_10_R1.ITileInventory;
|
||||
import net.minecraft.server.v1_10_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_10_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_10_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block or ocelot on top
|
||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
||||
return true;
|
||||
|
||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||
|
||||
// If block next to chest is chest and has a block or ocelot on top
|
||||
if (isBlockedChest(world, id, x - 1, y, z))
|
||||
return true;
|
||||
if (isBlockedChest(world, id, x + 1, y, z))
|
||||
return true;
|
||||
if (isBlockedChest(world, id, x, y, z - 1))
|
||||
return true;
|
||||
if (isBlockedChest(world, id, x, y, z + 1))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
||||
BlockPosition position = new BlockPosition(x, y, z);
|
||||
if (Block.getId(world.getType(position).getBlock()) != id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.getType(position).l()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Entity localEntity : world.a(EntityOcelot.class,
|
||||
new AxisAlignedBB(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||
|
||||
if (!anychest) {
|
||||
if (world.getType(new BlockPosition(x, y + 1, z)).l())
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
||||
player.activeContainer = silentContainerChest;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_10_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_10_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = grabInventory(inventory);
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private IInventory grabInventory(Inventory inventory) {
|
||||
if(inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory();
|
||||
}
|
||||
|
||||
//Use reflection to find the iinventory
|
||||
Class<? extends Inventory> clazz = inventory.getClass();
|
||||
IInventory result = null;
|
||||
for(Field f : clazz.getDeclaredFields()) {
|
||||
f.setAccessible(true);
|
||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
||||
try {
|
||||
result = (IInventory) f.get(inventory);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_10_R1;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_10_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_10_R1;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_10_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_10_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_10_R1.IInventory;
|
||||
import net.minecraft.server.v1_10_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) {
|
||||
super(i1, i2, e1);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.closeContainer(e1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried(), false);
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_10_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_10_R1.IInventory;
|
||||
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_10_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_10_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public boolean playerOnline = false;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
this.enderChest = craftPlayer.getHandle().getEnderChest();
|
||||
this.bukkitOwner = craftPlayer;
|
||||
setItemArrays(this, enderChest.getContents());
|
||||
}
|
||||
|
||||
private void setItemArrays(InventorySubcontainer subcontainer, ItemStack[] items) {
|
||||
try {
|
||||
// Prepare to remove final modifier
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
// Access and replace main inventory array
|
||||
Field field = InventorySubcontainer.class.getField("items");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(subcontainer, items);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
this.bukkitOwner = player;
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,303 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_10_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_10_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_10_R1.ItemStack;
|
||||
import net.minecraft.server.v1_10_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[4];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
|
||||
}
|
||||
|
||||
private void setItemArrays(PlayerInventory inventory, ItemStack[] items, ItemStack[] armor,
|
||||
ItemStack[] extraSlots) {
|
||||
try {
|
||||
// Prepare to remove final modifier
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
|
||||
// Access and replace main inventory array
|
||||
Field field = PlayerInventory.class.getField("items");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, items);
|
||||
|
||||
// Access and replace armor inventory array
|
||||
field = PlayerInventory.class.getField("armor");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, armor);
|
||||
|
||||
// Access and replace offhand inventory array
|
||||
field = PlayerInventory.class.getField("extraSlots");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, extraSlots);
|
||||
|
||||
// Access and replace array containing all inventory arrays
|
||||
field = PlayerInventory.class.getDeclaredField("g");
|
||||
field.setAccessible(true);
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, new ItemStack[][] { items, armor, extraSlots });
|
||||
} catch (NoSuchFieldException e) {
|
||||
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
setItemArrays(this.player.inventory, items, armor, extraSlots);
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
System.arraycopy(extraSlots, 0, contents, items.length + armor.length, extraSlots.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
// extraSlots is, for now, just an array with length 1. No need for special handling.
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].cloneAndSubtract(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack, true);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_11_R1</artifactId>
|
||||
<name>OpenInvCraftbukkit1_11_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.11-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_11_R1;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_11_R1.Block;
|
||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_11_R1.IInventory;
|
||||
import net.minecraft.server.v1_11_R1.ITileInventory;
|
||||
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_11_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_11_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block or ocelot on top
|
||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
||||
return true;
|
||||
|
||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||
|
||||
// If block next to chest is chest and has a block or ocelot on top
|
||||
if (isBlockedChest(world, id, x - 1, y, z))
|
||||
return true;
|
||||
if (isBlockedChest(world, id, x + 1, y, z))
|
||||
return true;
|
||||
if (isBlockedChest(world, id, x, y, z - 1))
|
||||
return true;
|
||||
if (isBlockedChest(world, id, x, y, z + 1))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
||||
BlockPosition position = new BlockPosition(x, y, z);
|
||||
if (Block.getId(world.getType(position).getBlock()) != id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.getType(position).l()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Entity localEntity : world.a(EntityOcelot.class,
|
||||
new AxisAlignedBB(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||
|
||||
if (!anychest) {
|
||||
if (world.getType(new BlockPosition(x, y + 1, z)).l())
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
|
||||
return true;
|
||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
||||
player.activeContainer = silentContainerChest;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_11_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_11_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = grabInventory(inventory);
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private IInventory grabInventory(Inventory inventory) {
|
||||
if(inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory();
|
||||
}
|
||||
|
||||
//Use reflection to find the iinventory
|
||||
Class<? extends Inventory> clazz = inventory.getClass();
|
||||
IInventory result = null;
|
||||
for(Field f : clazz.getDeclaredFields()) {
|
||||
f.setAccessible(true);
|
||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
||||
try {
|
||||
result = (IInventory) f.get(inventory);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_11_R1;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_11_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_11_R1;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_11_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_11_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_11_R1.IInventory;
|
||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) {
|
||||
super(i1, i2, e1);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.closeContainer(e1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (!playerinventory.getCarried().isEmpty()) {
|
||||
entityHuman.drop(playerinventory.getCarried(), false);
|
||||
playerinventory.setCarried(ItemStack.a);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_11_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_11_R1.IInventory;
|
||||
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_11_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public boolean playerOnline = false;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
this.enderChest = craftPlayer.getHandle().getEnderChest();
|
||||
this.bukkitOwner = craftPlayer;
|
||||
setItemLists(this, enderChest.getContents());
|
||||
}
|
||||
|
||||
private void setItemLists(InventorySubcontainer subcontainer, List<ItemStack> list) {
|
||||
try {
|
||||
// Prepare to remove final modifier
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
// Access and replace main inventory array
|
||||
Field field = InventorySubcontainer.class.getField("items");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(subcontainer, list);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
this.bukkitOwner = player;
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
setItemLists(craftPlayer.getHandle().getEnderChest(), this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,257 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_11_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_11_R1.ContainerUtil;
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_11_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
||||
import net.minecraft.server.v1_11_R1.NonNullList;
|
||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
|
||||
}
|
||||
|
||||
private void setItemArrays(PlayerInventory inventory, NonNullList<ItemStack> items,
|
||||
NonNullList<ItemStack> armor, NonNullList<ItemStack> extraSlots) {
|
||||
try {
|
||||
// Prepare to remove final modifier
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
|
||||
// Access and replace main inventory array
|
||||
Field field = PlayerInventory.class.getField("items");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, items);
|
||||
|
||||
// Access and replace armor inventory array
|
||||
field = PlayerInventory.class.getField("armor");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, armor);
|
||||
|
||||
// Access and replace offhand inventory array
|
||||
field = PlayerInventory.class.getField("extraSlots");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, extraSlots);
|
||||
|
||||
// Access and replace array containing all inventory arrays
|
||||
field = PlayerInventory.class.getDeclaredField("g");
|
||||
field.setAccessible(true);
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots }));
|
||||
} catch (NoSuchFieldException e) {
|
||||
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
setItemArrays(this.player.inventory, items, armor, extraSlots);
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
NonNullList<ItemStack> list = this.items;
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
return list.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
NonNullList<ItemStack> list = this.items;
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
return list == null || list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
NonNullList<ItemStack> list = this.items;
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
if (list != null && !list.get(i).isEmpty()) {
|
||||
ItemStack itemstack = list.get(i);
|
||||
|
||||
list.set(i, ItemStack.a);
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
NonNullList<ItemStack> list = this.items;
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
player.drop(itemstack, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (list != null) {
|
||||
list.set(i, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_4_5</artifactId>
|
||||
<name>OpenInvCraftbukkit1_4_5</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.5-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.Block;
|
||||
import net.minecraft.server.v1_4_5.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_5.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_5.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.s(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
if (!anychest) {
|
||||
if (world.s(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int id = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
id = windowID.getInt(player);
|
||||
id = id % 100 + 1;
|
||||
windowID.setInt(player, id);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = id;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_5.ItemInWorldManager;
|
||||
import net.minecraft.server.v1_4_5.MinecraftServer;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new ItemInWorldManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.ContainerChest;
|
||||
import net.minecraft.server.v1_4_5.EntityHuman;
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.f();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_5.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_5.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_5;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_5.ItemStack;
|
||||
import net.minecraft.server.v1_4_5.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_4_6</artifactId>
|
||||
<name>OpenInvCraftbukkit1_4_6</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.6-R0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
import net.minecraft.server.v1_4_6.Block;
|
||||
import net.minecraft.server.v1_4_6.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_6.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_6.World;
|
||||
|
||||
// Volatile
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.s(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
if (!anychest) {
|
||||
if (world.s(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int id = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
id = windowID.getInt(player);
|
||||
id = id % 100 + 1;
|
||||
windowID.setInt(player, id);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = id;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
|
||||
// Volatile
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_6.MinecraftServer;
|
||||
import net.minecraft.server.v1_4_6.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.ContainerChest;
|
||||
import net.minecraft.server.v1_4_6.EntityHuman;
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.f();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_6.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_6.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_6;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_6.ItemStack;
|
||||
import net.minecraft.server.v1_4_6.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_4_R1</artifactId>
|
||||
<name>OpenInvCraftbukkit1_4_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.7-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
import net.minecraft.server.v1_4_R1.Block;
|
||||
import net.minecraft.server.v1_4_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_R1.IInventory;
|
||||
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_R1.World;
|
||||
|
||||
// Volatile
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.s(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
if (!anychest) {
|
||||
if (world.s(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int id = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
id = windowID.getInt(player);
|
||||
id = id % 100 + 1;
|
||||
windowID.setInt(player, id);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = id;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_R1;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
import net.minecraft.server.v1_4_R1.IInventory;
|
||||
|
||||
// Volatile
|
||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_R1;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.minecraft.server.v1_4_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_4_R1.PlayerInteractManager;
|
||||
|
||||
// Volatile
|
||||
import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
|
||||
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_R1;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_4_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_4_R1.IInventory;
|
||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.f();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_R1.IInventory;
|
||||
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_4_R1;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_4_R1.ItemStack;
|
||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_5_R2</artifactId>
|
||||
<name>OpenInvCraftbukkit1_5_R2</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.5.1-R0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_5_R2.IInventory;
|
||||
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_5_R2.TileEntityChest;
|
||||
import net.minecraft.server.v1_5_R2.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
if (!anychest) {
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R2;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R2.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R2;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_5_R2.MinecraftServer;
|
||||
import net.minecraft.server.v1_5_R2.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R2;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R2.ContainerChest;
|
||||
import net.minecraft.server.v1_5_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_5_R2.IInventory;
|
||||
import net.minecraft.server.v1_5_R2.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R2.IInventory;
|
||||
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_5_R2.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_5_R2.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R2;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R2.ItemStack;
|
||||
import net.minecraft.server.v1_5_R2.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_5_R3</artifactId>
|
||||
<name>OpenInvCraftbukkit1_5_R3</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.5.2-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
//Volatile
|
||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_5_R3.IInventory;
|
||||
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_5_R3.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_5_R3.TileEntityChest;
|
||||
import net.minecraft.server.v1_5_R3.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
if (!anychest) {
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R3;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R3.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R3;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_5_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_5_R3.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R3;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R3.ContainerChest;
|
||||
import net.minecraft.server.v1_5_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_5_R3.IInventory;
|
||||
import net.minecraft.server.v1_5_R3.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R3.IInventory;
|
||||
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_5_R3.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_5_R3.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_5_R3;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_5_R3.ItemStack;
|
||||
import net.minecraft.server.v1_5_R3.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_6_R1</artifactId>
|
||||
<name>OpenInvCraftbukkit1_6_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.6.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R1.IInventory;
|
||||
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_6_R1.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_6_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_6_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
if (!anychest) {
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R1;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R1;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_6_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R1;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_6_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_6_R1.IInventory;
|
||||
import net.minecraft.server.v1_6_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R1.IInventory;
|
||||
import net.minecraft.server.v1_6_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_6_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R1;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R1.ItemStack;
|
||||
import net.minecraft.server.v1_6_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_6_R2</artifactId>
|
||||
<name>OpenInvCraftbukkit1_6_R2</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.6.2-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_6_R2.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_6_R2.TileEntityChest;
|
||||
import net.minecraft.server.v1_6_R2.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
if (!anychest) {
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R2;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R2;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R2.MinecraftServer;
|
||||
import net.minecraft.server.v1_6_R2.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R2;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R2.ContainerChest;
|
||||
import net.minecraft.server.v1_6_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
import net.minecraft.server.v1_6_R2.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
import net.minecraft.server.v1_6_R2.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R2.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R2;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||
import net.minecraft.server.v1_6_R2.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_6_R3</artifactId>
|
||||
<name>OpenInvCraftbukkit1_6_R3</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.6.4-R2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
import net.minecraft.server.v1_6_R3.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_6_R3.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_6_R3.TileEntityChest;
|
||||
import net.minecraft.server.v1_6_R3.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = world.getTypeId(x, y, z);
|
||||
|
||||
if (!anychest) {
|
||||
if (world.t(x, y + 1, z))
|
||||
return true;
|
||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
||||
return true;
|
||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getTypeId(x - 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (world.getTypeId(x + 1, y, z) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (world.getTypeId(x, y, z - 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (world.getTypeId(x, y, z + 1) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R3;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R3;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_6_R3.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R3;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R3.ContainerChest;
|
||||
import net.minecraft.server.v1_6_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
import net.minecraft.server.v1_6_R3.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried());
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
import net.minecraft.server.v1_6_R3.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R3.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_6_R3;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
||||
import net.minecraft.server.v1_6_R3.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_7_R1</artifactId>
|
||||
<name>OpenInvCraftbukkit1_7_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.2-R0.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
//Volatile
|
||||
import net.minecraft.server.v1_7_R1.Block;
|
||||
import net.minecraft.server.v1_7_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R1.IInventory;
|
||||
import net.minecraft.server.v1_7_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_7_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_7_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_7_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.getType(x, y + 1, z).c())
|
||||
return true;
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
if (!anychest) {
|
||||
if (world.getType(x, y + 1, z).c())
|
||||
return true;
|
||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (Block.b(world.getType(x, y, z - 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R1;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R1;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_7_R1.PlayerInteractManager;
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
GameProfile profile = new GameProfile(null, offline.getName());
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R1;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_7_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_7_R1.IInventory;
|
||||
import net.minecraft.server.v1_7_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.l_();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried(), false);
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R1.IInventory;
|
||||
import net.minecraft.server.v1_7_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_7_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_7_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R1;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R1.ItemStack;
|
||||
import net.minecraft.server.v1_7_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack, true);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_7_R2</artifactId>
|
||||
<name>OpenInvCraftbukkit1_7_R2</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.5-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
import net.minecraft.server.v1_7_R2.Block;
|
||||
//Volatile
|
||||
import net.minecraft.server.v1_7_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R2.IInventory;
|
||||
import net.minecraft.server.v1_7_R2.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_7_R2.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_7_R2.TileEntityChest;
|
||||
import net.minecraft.server.v1_7_R2.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.getType(x, y + 1, z).c())
|
||||
return true;
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
if (!anychest) {
|
||||
if (world.getType(x, y + 1, z).c())
|
||||
return true;
|
||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (Block.b(world.getType(x, y, z - 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R2;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R2.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R2;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
//Volatile
|
||||
import net.minecraft.server.v1_7_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R2.MinecraftServer;
|
||||
import net.minecraft.server.v1_7_R2.PlayerInteractManager;
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
GameProfile profile = new GameProfile(null, offline.getName());
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R2;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R2.ContainerChest;
|
||||
import net.minecraft.server.v1_7_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_7_R2.IInventory;
|
||||
import net.minecraft.server.v1_7_R2.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.l_();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried(), false);
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R2.IInventory;
|
||||
import net.minecraft.server.v1_7_R2.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_7_R2.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_7_R2.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R2;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R2.ItemStack;
|
||||
import net.minecraft.server.v1_7_R2.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack, true);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_7_R3</artifactId>
|
||||
<name>OpenInvCraftbukkit1_7_R3</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.9-R0.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentChest;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R3.Block;
|
||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R3.IInventory;
|
||||
import net.minecraft.server.v1_7_R3.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_7_R3.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_7_R3.TileEntityChest;
|
||||
import net.minecraft.server.v1_7_R3.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
@Override
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
// If block on top
|
||||
if (world.getType(x, y + 1, z).c())
|
||||
return true;
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
// If block next to chest is chest and has a block on top
|
||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
if (!anychest) {
|
||||
if (world.getType(x, y + 1, z).c())
|
||||
return true;
|
||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (Block.b(world.getType(x, y, z - 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R3;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R3.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R3;
|
||||
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_7_R3.PlayerInteractManager;
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R3;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R3.ContainerChest;
|
||||
import net.minecraft.server.v1_7_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_7_R3.IInventory;
|
||||
import net.minecraft.server.v1_7_R3.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.l_();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman entityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried(), false);
|
||||
playerinventory.setCarried(null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R3.IInventory;
|
||||
import net.minecraft.server.v1_7_R3.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_7_R3.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_7_R3.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
this.owner = player;
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
owner = (CraftPlayer) player;
|
||||
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_7_R3;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_7_R3.ItemStack;
|
||||
import net.minecraft.server.v1_7_R3.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(((CraftPlayer) bukkitPlayer).getHandle());
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = ((CraftPlayer) player).getHandle();
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack, true);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>OpenInvCraftbukkit1_7_R4</artifactId>
|
||||
<name>OpenInvCraftbukkit1_7_R4</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.10-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user