Migrate to UUID usage

This commit is contained in:
ShadowRanger 2015-06-22 12:03:03 +10:00
parent 1ea0307156
commit e8476d5b05
122 changed files with 727 additions and 11495 deletions

62
pom.xml Normal file
View file

@ -0,0 +1,62 @@
<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>
<groupId>com.lishid</groupId>
<artifactId>openinv</artifactId>
<packaging>jar</packaging>
<version>2.2.9</version>
<name>OpenInv</name>
<url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.7-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8.7-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install</defaultGoal>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -18,6 +18,7 @@ package com.lishid.openinv;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
@ -28,12 +29,14 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.openinv.commands.*;
import com.lishid.openinv.internal.IAnySilentChest;
import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.internal.InternalAccessor;
import com.lishid.openinv.internal.AnySilentChest;
import com.lishid.openinv.internal.InventoryAccess;
import com.lishid.openinv.internal.PlayerDataManager;
import com.lishid.openinv.internal.SpecialEnderChest;
import com.lishid.openinv.internal.SpecialPlayerInventory;
import com.lishid.openinv.listeners.OpenInvEntityListener;
import com.lishid.openinv.listeners.OpenInvInventoryListener;
import com.lishid.openinv.listeners.OpenInvPlayerListener;
/**
* Open other player's inventory
@ -43,32 +46,23 @@ import com.lishid.openinv.internal.InternalAccessor;
public class OpenInv extends JavaPlugin {
public static final Logger logger = Logger.getLogger("Minecraft.OpenInv");
public static Map<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
public static Map<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
public static final Map<UUID, SpecialPlayerInventory> inventories = new HashMap<UUID, SpecialPlayerInventory>();
public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
public static OpenInv mainPlugin;
public static IPlayerDataManager playerLoader;
public static IInventoryAccess inventoryAccess;
public static IAnySilentChest anySilentChest;
public static PlayerDataManager playerLoader;
public static InventoryAccess inventoryAccess;
public static AnySilentChest anySilentChest;
@Override
public void onEnable() {
// Get plugin manager
PluginManager pm = getServer().getPluginManager();
// Version check
boolean success = InternalAccessor.Initialize(this.getServer());
if (!success) {
OpenInv.log("Your version of CraftBukkit is not supported.");
OpenInv.log("Please look for an updated version of OpenInv.");
pm.disablePlugin(this);
return;
}
playerLoader = InternalAccessor.Instance.newPlayerDataManager();
inventoryAccess = InternalAccessor.Instance.newInventoryAccess();
anySilentChest = InternalAccessor.Instance.newAnySilentChest();
playerLoader = new PlayerDataManager();
inventoryAccess = new InventoryAccess();
anySilentChest = new AnySilentChest();
mainPlugin = this;
FileConfiguration config = getConfig();
@ -90,8 +84,8 @@ public class OpenInv extends JavaPlugin {
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
getCommand("silentchest").setExecutor(new SilentChestPluginCommand());
getCommand("anychest").setExecutor(new AnyChestPluginCommand());
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
}
@ -195,4 +189,4 @@ public class OpenInv extends JavaPlugin {
}
return player.hasPermission(permission);
}
}
}

View file

@ -26,32 +26,33 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class AnyChestPluginCommand implements CommandExecutor {
public AnyChestPluginCommand(OpenInv plugin) {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_ANYCHEST)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use anychest.");
return true;
}
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerAnyChestStatus(sender.getName()))
sender.sendMessage("AnyChest is ON.");
else
sender.sendMessage("AnyChest is OFF.");
if (command.getName().equalsIgnoreCase("anychest")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_ANYCHEST)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use anychest.");
return true;
}
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerAnyChestStatus(sender.getName()))
sender.sendMessage("AnyChest is ON.");
else
sender.sendMessage("AnyChest is OFF.");
}
}
OpenInv.SetPlayerAnyChestStatus(sender.getName(), !OpenInv.GetPlayerAnyChestStatus(sender.getName()));
sender.sendMessage("AnyChest is now " + (OpenInv.GetPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + ".");
return true;
}
OpenInv.SetPlayerAnyChestStatus(sender.getName(), !OpenInv.GetPlayerAnyChestStatus(sender.getName()));
sender.sendMessage("AnyChest is now " + (OpenInv.GetPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + ".");
return true;
return false;
}
}

View file

@ -17,6 +17,7 @@
package com.lishid.openinv.commands;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
@ -28,88 +29,93 @@ import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.InternalAccessor;
import com.lishid.openinv.internal.SpecialEnderChest;
import com.lishid.openinv.utils.UUIDUtil;
public class OpenEnderPluginCommand implements CommandExecutor {
private final OpenInv plugin;
public static Map<Player, String> openEnderHistory = new ConcurrentHashMap<Player, String>();
public static final Map<UUID, UUID> openEnderHistory = new ConcurrentHashMap<UUID, UUID>();
public OpenEnderPluginCommand(OpenInv plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player enderchest");
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender);
return true;
}
Player player = (Player) sender;
// History management
String history = openEnderHistory.get(player);
if (history == null || history == "") {
history = player.getName();
openEnderHistory.put(player, history);
}
final String name;
// Read from history if target is not named
if (args.length < 1) {
if (history != null && history != "") {
name = history;
}
else {
sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
if (command.getName().equalsIgnoreCase("openender")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
}
else {
name = args[0];
}
final String playername = player.getName();
Player target = plugin.getServer().getPlayer(name);
// Targeted player was not found online, start asynchron lookup in files
if (target == null) {
sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// Try loading the player's data asynchronly
final Player target = OpenInv.playerLoader.loadPlayer(name);
// Back to synchron to send messages and display inventory
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(playername);
// If sender is no longer online after loading the target. Abort!
if (player == null) {
return;
}
openInventory(player, target);
}
});
if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player enderchest");
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender);
return true;
}
Player player = (Player) sender;
// History management
UUID history = openEnderHistory.get(player.getUniqueId());
if (history == null) {
history = player.getUniqueId();
openEnderHistory.put(player.getUniqueId(), history);
}
final UUID uuid;
// Read from history if target is not named
if (args.length < 1) {
if (history != null) {
uuid = history;
}
});
} else {
openInventory(player, target);
else {
sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
return true;
}
}
else {
uuid = UUIDUtil.getUUIDOf(args[0]);
}
final UUID playerUUID = player.getUniqueId();
Player target = Bukkit.getPlayer(uuid);
// Targeted player was not found online, start asynchron lookup in files
if (target == null) {
sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// Try loading the player's data asynchronly
final Player target = OpenInv.playerLoader.loadPlayer(uuid);
// Back to synchron to send messages and display inventory
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(playerUUID);
// If sender is no longer online after loading the target. Abort!
if (player == null) {
return;
}
openInventory(player, target);
}
});
}
});
} else {
openInventory(player, target);
}
return true;
}
return true;
return false;
}
private void openInventory(Player player, Player target) {
@ -136,17 +142,15 @@ public class OpenEnderPluginCommand implements CommandExecutor {
}
// Record the target
openEnderHistory.put(player, target.getName());
openEnderHistory.put(player.getUniqueId(), target.getUniqueId());
// Create the inventory
ISpecialEnderChest chest = OpenInv.enderChests.get(target.getName().toLowerCase());
SpecialEnderChest chest = OpenInv.enderChests.get(target.getUniqueId());
if (chest == null) {
chest = InternalAccessor.Instance.newSpecialEnderChest(target, target.isOnline());
chest = new SpecialEnderChest(target, target.isOnline());
}
// Open the inventory
player.openInventory(chest.getBukkitInventory());
return;
}
}

View file

@ -17,6 +17,7 @@
package com.lishid.openinv.commands;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
@ -28,79 +29,86 @@ import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.internal.InternalAccessor;
import com.lishid.openinv.internal.SpecialPlayerInventory;
import com.lishid.openinv.utils.UUIDUtil;
public class OpenInvPluginCommand implements CommandExecutor {
private final OpenInv plugin;
public static Map<Player, String> openInvHistory = new ConcurrentHashMap<Player, String>();
public static final Map<UUID, UUID> openInvHistory = new ConcurrentHashMap<UUID, UUID>();
public OpenInvPluginCommand(OpenInv plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
if (command.getName().equalsIgnoreCase("openinv")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender);
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender);
return true;
}
Player player = (Player) sender;
Player player = (Player) sender;
// History management
String history = openInvHistory.get(player);
// History management
UUID history = openInvHistory.get(player.getUniqueId());
if (history == null || history == "") {
history = player.getName();
openInvHistory.put(player, history);
}
if (history == null) {
history = player.getUniqueId();
openInvHistory.put(player.getUniqueId(), history);
}
final String name;
final UUID uuid;
// Read from history if target is not named
if (args.length < 1) {
name = history;
} else {
name = args[0];
}
// Read from history if target is not named
if (args.length < 1) {
uuid = history;
}
else {
uuid = UUIDUtil.getUUIDOf(args[0]);
}
final String playername = player.getName();
Player target = plugin.getServer().getPlayer(name);
// Targeted player was not found online, start asynchron lookup in files
if (target == null) {
sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// Try loading the player's data asynchronly
final Player target = OpenInv.playerLoader.loadPlayer(name);
// Back to synchron to send messages and display inventory
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(playername);
// If sender is no longer online after loading the target. Abort!
if (player == null) {
return;
final UUID playerUUID = player.getUniqueId();
Player target = Bukkit.getPlayer(uuid);
// Targeted player was not found online, start asynchron lookup in files
if (target == null) {
sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// Try loading the player's data asynchronly
final Player target = OpenInv.playerLoader.loadPlayer(uuid);
// Back to synchron to send messages and display inventory
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(playerUUID);
// If sender is no longer online after loading the target. Abort!
if (player == null) {
return;
}
openInventory(player, target);
}
openInventory(player, target);
}
});
}
});
} else {
openInventory(player, target);
});
}
});
} else {
openInventory(player, target);
}
return true;
}
return true;
return false;
}
private void openInventory(Player player, Player target) {
@ -128,17 +136,15 @@ public class OpenInvPluginCommand implements CommandExecutor {
}
// Record the target
openInvHistory.put(player, target.getName());
openInvHistory.put(player.getUniqueId(), target.getUniqueId());
// Create the inventory
ISpecialPlayerInventory inv = OpenInv.inventories.get(target.getName().toLowerCase());
SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId());
if (inv == null) {
inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, target.isOnline());
inv = new SpecialPlayerInventory(target, target.isOnline());
}
// Open the inventory
player.openInventory(inv.getBukkitInventory());
return;
}
}

View file

@ -28,50 +28,52 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class SearchInvPluginCommand implements CommandExecutor {
public SearchInvPluginCommand() {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
if (command.getName().equalsIgnoreCase("searchinv")) {
if (sender instanceof Player) {
if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
}
}
String PlayerList = "";
String playerList = "";
Material material = null;
int count = 1;
Material material = null;
int count = 1;
if (args.length >= 1) {
String[] gData = null;
gData = args[0].split(":");
material = Material.matchMaterial(gData[0]);
}
if (args.length >= 2) {
try {
count = Integer.parseInt(args[1]);
if (args.length >= 1) {
String[] gData = null;
gData = args[0].split(":");
material = Material.matchMaterial(gData[0]);
}
catch (NumberFormatException ex) {
sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
if (args.length >= 2) {
try {
count = Integer.parseInt(args[1]);
}
catch (NumberFormatException ex) {
sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
return false;
}
}
if (material == null) {
sender.sendMessage(ChatColor.RED + "Unknown item");
return false;
}
}
if (material == null) {
sender.sendMessage(ChatColor.RED + "Unknown item");
return false;
}
for (Player templayer : Bukkit.getServer().getOnlinePlayers()) {
if (templayer.getInventory().contains(material, count)) {
PlayerList += templayer.getName() + " ";
for (Player templayer : Bukkit.getServer().getOnlinePlayers()) {
if (templayer.getInventory().contains(material, count)) {
playerList += templayer.getName() + " ";
}
}
sender.sendMessage("Players with the item " + material.toString() + ": " + playerList);
return true;
}
sender.sendMessage("Players with the item " + material.toString() + ": " + PlayerList);
return true;
return false;
}
}

View file

@ -26,32 +26,33 @@ import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
public class SilentChestPluginCommand implements CommandExecutor {
public SilentChestPluginCommand(OpenInv plugin) {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_SILENT)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest.");
return true;
}
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerSilentChestStatus(sender.getName()))
sender.sendMessage("SilentChest is ON.");
else
sender.sendMessage("SilentChest is OFF.");
if (command.getName().equalsIgnoreCase("silentchest")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_SILENT)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest.");
return true;
}
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerSilentChestStatus(sender.getName()))
sender.sendMessage("SilentChest is ON.");
else
sender.sendMessage("SilentChest is OFF.");
}
}
OpenInv.SetPlayerSilentChestStatus(sender.getName(), !OpenInv.GetPlayerSilentChestStatus(sender.getName()));
sender.sendMessage("SilentChest is now " + (OpenInv.GetPlayerSilentChestStatus(sender.getName()) ? "On" : "Off") + ".");
return true;
}
OpenInv.SetPlayerSilentChestStatus(sender.getName(), !OpenInv.GetPlayerSilentChestStatus(sender.getName()));
sender.sendMessage("SilentChest is now " + (OpenInv.GetPlayerSilentChestStatus(sender.getName()) ? "On" : "Off") + ".");
return true;
return false;
}
}

View file

@ -26,35 +26,40 @@ import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
@SuppressWarnings("deprecation")
public class ToggleOpenInvPluginCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
if (command.getName().equalsIgnoreCase("toggleopeninv")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
return true;
}
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
Player player = (Player) sender;
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
else
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
}
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName())) {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), false);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
else {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), true);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
}
return true;
}
Player player = (Player) sender;
if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
else
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
}
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName())) {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), false);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
else {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), true);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
}
return true;
return false;
}
}

View file

@ -14,22 +14,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal;
import java.util.Iterator;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
public class AnySilentChest implements IAnySilentChest {
public class AnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
BlockPosition position = new BlockPosition(x, y, z);

View file

@ -1,11 +1,12 @@
package com.lishid.openinv.internal.v1_8_R3;
import com.google.common.collect.Iterators;
import net.minecraft.server.v1_8_R3.EnumDirection;
import net.minecraft.server.v1_8_R3.EnumDirection.EnumDirectionLimit;
package com.lishid.openinv.internal;
import java.util.Iterator;
import com.google.common.collect.Iterators;
import net.minecraft.server.v1_8_R3.EnumDirection;
import net.minecraft.server.v1_8_R3.EnumDirection.EnumDirectionLimit;
public enum EnumDirectionList implements Iterable<EnumDirection> {
HORIZONTAL(EnumDirectionLimit.HORIZONTAL),
VERTICAL(EnumDirectionLimit.VERTICAL);
@ -20,5 +21,4 @@ public enum EnumDirectionList implements Iterable<EnumDirection> {
public Iterator<EnumDirection> iterator() {
return Iterators.forArray(list.a());
}
}
}

View file

@ -1,25 +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;
public interface IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z);
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z);
}

View file

@ -1,24 +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.HumanEntity;
import org.bukkit.inventory.Inventory;
public interface IInventoryAccess {
public boolean check(Inventory inventory, HumanEntity player);
}

View file

@ -1,23 +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;
public interface IPlayerDataManager {
public Player loadPlayer(String name);
}

View file

@ -1,29 +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();
public void playerOnline(Player p);
public void playerOffline();
}

View file

@ -1,28 +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();
public void playerOnline(Player p);
public void playerOffline();
}

View file

@ -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;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
public class InternalAccessor {
public static InternalAccessor Instance;
private String version;
/*
* Returns false if version not supported
*/
public static boolean Initialize(Server server) {
Instance = new InternalAccessor();
String packageName = server.getClass().getPackage().getName();
Instance.version = packageName.substring(packageName.lastIndexOf('.') + 1);
try {
Class.forName("com.lishid.openinv.internal." + Instance.version + ".AnySilentChest");
return true;
}
catch (Exception e) {
return false;
}
}
public void PrintError() {
OpenInv.log("OpenInv encountered an error with the CraftBukkit version \"" + Instance.version + "\". Please look for an updated version of OpenInv.");
}
public IPlayerDataManager newPlayerDataManager() {
return (IPlayerDataManager) createObject(IPlayerDataManager.class, "PlayerDataManager");
}
public IInventoryAccess newInventoryAccess() {
return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess");
}
public IAnySilentChest newAnySilentChest() {
return (IAnySilentChest) createObject(IAnySilentChest.class, "AnySilentChest");
}
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) {
try {
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialPlayerInventory");
if (ISpecialPlayerInventory.class.isAssignableFrom(internalClass)) {
return (ISpecialPlayerInventory) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline);
}
}
catch (Exception e) {
PrintError();
OpenInv.log(e);
}
return null;
}
public ISpecialEnderChest newSpecialEnderChest(Player player, boolean offline) {
try {
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialEnderChest");
if (ISpecialEnderChest.class.isAssignableFrom(internalClass)) {
return (ISpecialEnderChest) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline);
}
}
catch (Exception e) {
PrintError();
OpenInv.log(e);
}
return null;
}
private Object createObject(Class<? extends Object> assignableClass, String className) {
try {
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
if (assignableClass.isAssignableFrom(internalClass)) {
return internalClass.getConstructor().newInstance();
}
}
catch (Exception e) {
PrintError();
OpenInv.log(e);
}
return null;
}
}

View file

@ -14,23 +14,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal;
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_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
public class InventoryAccess implements IInventoryAccess {
public class InventoryAccess {
public boolean check(Inventory inventory, HumanEntity player) {
IInventory inv = grabInventory(inventory);

View file

@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal;
import java.util.UUID;
@ -23,7 +23,6 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile;
//Volatile
@ -31,14 +30,9 @@ import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
public class PlayerDataManager {
public Player loadPlayer(UUID uuid) {
try {
UUID uuid = matchUser(name);
if (uuid == null) {
return null;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null) {
return null;
@ -63,39 +57,4 @@ public class PlayerDataManager implements IPlayerDataManager {
return null;
}
private static UUID matchUser(String search) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(search);
if (offlinePlayer != null && offlinePlayer.hasPlayedBefore()) {
return offlinePlayer.getUniqueId();
}
UUID found = null;
String lowerSearch = search.toLowerCase();
int delta = 2147483647;
OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
for (OfflinePlayer player : offlinePlayers) {
String name = player.getName();
if (name == null){
continue;
}
if (name.equalsIgnoreCase(search)){
return player.getUniqueId();
}
if (name.toLowerCase().startsWith(lowerSearch)) {
int curDelta = name.length() - lowerSearch.length();
if (curDelta < delta) {
found = player.getUniqueId();
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
}
return found;
}
}

View file

@ -14,12 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal;
//Volatile
import net.minecraft.server.v1_8_R3.*;
public class SilentContainerChest extends ContainerChest {
public IInventory inv;
@ -34,4 +33,4 @@ public class SilentContainerChest extends ContainerChest {
public void b(EntityHuman paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}
}

View file

@ -1,11 +1,13 @@
package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal;
import java.util.List;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.InventoryHolder;
import java.util.List;
//Volatile
import net.minecraft.server.v1_8_R3.*;
public class SilentInventory implements ITileInventory {
public ITileInventory inv;
@ -109,12 +111,10 @@ public class SilentInventory implements ITileInventory {
return inv.getContents();
}
@Override
public void onOpen(CraftHumanEntity craftHumanEntity) {
inv.onOpen(craftHumanEntity);
}
@Override
public void onClose(CraftHumanEntity craftHumanEntity) {
inv.onClose(craftHumanEntity);
}
@ -159,4 +159,4 @@ public class SilentInventory implements ITileInventory {
public String getContainerName() {
return inv.getContainerName();
}
}
}

View file

@ -14,21 +14,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R3;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
package com.lishid.openinv.internal;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import com.lishid.openinv.OpenInv;
//Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements ISpecialEnderChest {
public class SpecialEnderChest extends InventorySubcontainer {
private CraftInventory inventory = new CraftInventory(this);
private InventoryEnderChest enderChest;
private CraftPlayer owner;
@ -44,13 +43,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements ISpecial
this.enderChest = enderchest;
this.items = enderChest.getContents();
this.playerOnline = online;
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
OpenInv.enderChests.put(owner.getUniqueId(), this);
}
private void saveOnExit() {
if (transaction.isEmpty() && !playerOnline) {
owner.saveData();
OpenInv.enderChests.remove(owner.getName().toLowerCase());
OpenInv.enderChests.remove(owner.getUniqueId());
}
}

View file

@ -14,21 +14,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_8_R3;
package com.lishid.openinv.internal;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
public class SpecialPlayerInventory extends PlayerInventory {
private CraftInventory inventory = new CraftInventory(this);
private ItemStack[] extra = new ItemStack[5];
private CraftPlayer owner;
@ -40,7 +38,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
this.items = player.inventory.items;
this.armor = player.inventory.armor;
this.playerOnline = online;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
OpenInv.inventories.put(owner.getUniqueId(), this);
}
public Inventory getBukkitInventory() {
@ -50,7 +48,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private void saveOnExit() {
if (transaction.isEmpty() && !playerOnline) {
owner.saveData();
OpenInv.inventories.remove(owner.getName().toLowerCase());
OpenInv.inventories.remove(owner.getUniqueId());
}
}
@ -250,4 +248,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
super.update();
player.inventory.update();
}
}
}

View file

@ -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.craftbukkit;
import java.lang.reflect.Field;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.*;
import org.bukkit.craftbukkit.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.s(x, y + 1, z))
return true;
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.craftbukkit;
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.*;
import org.bukkit.craftbukkit.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.craftbukkit;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.*;
import org.bukkit.craftbukkit.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.craftbukkit;
//Volatile
import net.minecraft.server.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.craftbukkit;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.OpenInv;
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.*;
import org.bukkit.craftbukkit.entity.*;
import org.bukkit.craftbukkit.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.craftbukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.*;
import org.bukkit.craftbukkit.entity.*;
import org.bukkit.craftbukkit.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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.name.length() > 16) {
return player.name.substring(0, 16);
}
return player.name;
}
@Override
public boolean a_(EntityHuman entityhuman) {
return true;
}
}

View file

@ -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.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_4_5.*;
import org.bukkit.craftbukkit.v1_4_5.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.s(x, y + 1, z))
return true;
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_4_5.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_4_5.*;
import org.bukkit.craftbukkit.v1_4_5.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_4_5.entity.*;
import org.bukkit.craftbukkit.v1_4_5.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_4_5.*;
import org.bukkit.craftbukkit.v1_4_5.entity.*;
import org.bukkit.craftbukkit.v1_4_5.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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.name.length() > 16) {
return player.name.substring(0, 16);
}
return player.name;
}
@Override
public boolean a_(EntityHuman entityhuman) {
return true;
}
}

View file

@ -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.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_4_6.*;
import org.bukkit.craftbukkit.v1_4_6.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.s(x, y + 1, z))
return true;
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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;
//Volatile
import net.minecraft.server.v1_4_6.*;
import org.bukkit.craftbukkit.v1_4_6.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_4_6.*;
import org.bukkit.craftbukkit.v1_4_6.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_4_6.entity.*;
import org.bukkit.craftbukkit.v1_4_6.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_4_6.*;
import org.bukkit.craftbukkit.v1_4_6.entity.*;
import org.bukkit.craftbukkit.v1_4_6.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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.name.length() > 16) {
return player.name.substring(0, 16);
}
return player.name;
}
@Override
public boolean a_(EntityHuman entityhuman) {
return true;
}
}

View file

@ -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.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.s(x, y + 1, z))
return true;
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
import org.bukkit.craftbukkit.v1_4_R1.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
import org.bukkit.craftbukkit.v1_4_R1.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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.name.length() > 16) {
return player.name.substring(0, 16);
}
return player.name;
}
@Override
public boolean a_(EntityHuman entityhuman) {
return true;
}
}

View file

@ -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_5_R2;
import java.lang.reflect.Field;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_5_R2.*;
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_5_R2.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_5_R2.*;
import org.bukkit.craftbukkit.v1_5_R2.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
import org.bukkit.craftbukkit.v1_5_R2.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_5_R2.*;
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
import org.bukkit.craftbukkit.v1_5_R2.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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.name.length() > 16) {
return player.name.substring(0, 16);
}
return player.name;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View file

@ -1,126 +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.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
import com.lishid.openinv.internal.v1_5_R3.SilentContainerChest;
//Volatile
import net.minecraft.server.v1_5_R3.*;
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_5_R3.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_5_R3.*;
import org.bukkit.craftbukkit.v1_5_R3.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
import org.bukkit.craftbukkit.v1_5_R3.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_5_R3.*;
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
import org.bukkit.craftbukkit.v1_5_R3.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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.name.length() > 16) {
return player.name.substring(0, 16);
}
return player.name;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View file

@ -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_6_R1;
import java.lang.reflect.Field;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_6_R1.*;
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_6_R1.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_6_R1.*;
import org.bukkit.craftbukkit.v1_6_R1.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
import org.bukkit.craftbukkit.v1_6_R1.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_6_R1.*;
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
import org.bukkit.craftbukkit.v1_6_R1.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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;
}
}

View file

@ -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_6_R2;
import java.lang.reflect.Field;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_6_R2.*;
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_6_R2.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_6_R2.*;
import org.bukkit.craftbukkit.v1_6_R2.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
import org.bukkit.craftbukkit.v1_6_R2.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_6_R2.*;
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
import org.bukkit.craftbukkit.v1_6_R2.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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;
}
}

View file

@ -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_6_R3;
import java.lang.reflect.Field;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_6_R3.*;
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.t(x, y + 1, z))
return true;
int id = world.getTypeId(x, y, z);
// If block next to chest is chest and has a block on top
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
return true;
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
return true;
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
return true;
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_6_R3.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,97 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
//Volatile
import net.minecraft.server.v1_6_R3.*;
import org.bukkit.craftbukkit.v1_6_R3.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
import org.bukkit.craftbukkit.v1_6_R3.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_6_R3.*;
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
import org.bukkit.craftbukkit.v1_6_R3.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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;
}
}

View file

@ -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.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_7_R1.*;
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.getType(x, y + 1, z).c())
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block on top
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_7_R1.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,99 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
//Volatile
import net.minecraft.server.v1_7_R1.*;
import org.bukkit.craftbukkit.v1_7_R1.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
GameProfile profile = new GameProfile(null, playername);
// 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
import org.bukkit.craftbukkit.v1_7_R1.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_7_R1.*;
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
import org.bukkit.craftbukkit.v1_7_R1.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View file

@ -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.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_7_R2.*;
import org.bukkit.craftbukkit.v1_7_R2.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.getType(x, y + 1, z).c())
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block on top
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_7_R2.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -1,99 +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.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
//Volatile
import net.minecraft.server.v1_7_R2.*;
import org.bukkit.craftbukkit.v1_7_R2.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
if (!playerfolder.exists()) {
return null;
}
String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
if (playername == null) {
return null;
}
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
GameProfile profile = new GameProfile(null, playername);
// 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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
/**
* @author Balor (aka Antoine Aflalo)
*/
private static String matchUser(final Collection<File> container, final String search) {
String found = null;
if (search == null) {
return found;
}
final String lowerSearch = search.toLowerCase();
int delta = Integer.MAX_VALUE;
for (final File file : container) {
final String filename = file.getName();
final String str = filename.substring(0, filename.length() - 4);
if (!str.toLowerCase().startsWith(lowerSearch)) {
continue;
}
final int curDelta = str.length() - lowerSearch.length();
if (curDelta < delta) {
found = str;
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_7_R2.entity.*;
import org.bukkit.craftbukkit.v1_7_R2.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_7_R2.*;
import org.bukkit.craftbukkit.v1_7_R2.entity.*;
import org.bukkit.craftbukkit.v1_7_R2.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View file

@ -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.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_7_R3.*;
import org.bukkit.craftbukkit.v1_7_R3.entity.*;
public class AnySilentChest implements IAnySilentChest {
public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
// If block on top
if (world.getType(x, y + 1, z).c())
return true;
int id = Block.b(world.getType(x, y, z));
// If block next to chest is chest and has a block on top
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
return false;
}
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
Object chest = (TileEntityChest) 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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,48 +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.*;
import org.bukkit.craftbukkit.v1_7_R3.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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;
}
}

View file

@ -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_7_R3;
import java.io.File;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
//Volatile
import net.minecraft.server.v1_7_R3.*;
import org.bukkit.craftbukkit.v1_7_R3.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
UUID uuid = matchUser(name);
if (uuid == null) {
return null;
}
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata");
if (!playerfolder.exists()) {
return null;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null) {
return null;
}
GameProfile profile = new GameProfile(uuid, player.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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
private static UUID matchUser(String search) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(search);
if (offlinePlayer != null && offlinePlayer.hasPlayedBefore()) {
return offlinePlayer.getUniqueId();
}
UUID found = null;
String lowerSearch = search.toLowerCase();
int delta = 2147483647;
OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
for (OfflinePlayer player : offlinePlayers) {
String name = player.getName();
if (name.equalsIgnoreCase(search))
return player.getUniqueId();
if (name.toLowerCase().startsWith(lowerSearch)) {
int curDelta = name.length() - lowerSearch.length();
if (curDelta < delta) {
found = player.getUniqueId();
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
}
return found;
}
}

View file

@ -1,36 +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.*;
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 paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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.OpenInv;
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.*;
import org.bukkit.craftbukkit.v1_7_R3.entity.*;
import org.bukkit.craftbukkit.v1_7_R3.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_7_R3.*;
import org.bukkit.craftbukkit.v1_7_R3.entity.*;
import org.bukkit.craftbukkit.v1_7_R3.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

View file

@ -1,125 +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_R4;
import java.lang.reflect.Field;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
//Volatile
import net.minecraft.server.v1_7_R4.*;
import org.bukkit.craftbukkit.v1_7_R4.entity.*;
public class AnySilentChest implements IAnySilentChest {
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.getId(world.getType(x, y, z));
// If block next to chest is chest and has a block on top
if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
return false;
}
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 = (TileEntityChest) world.getTileEntity(x, y, z);
if (chest == null)
return true;
int id = Block.getId(world.getType(x, y, z));
if (!anychest) {
if (world.getType(x, y + 1, z).c())
return true;
if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
return true;
if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
return true;
if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
return true;
if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
return true;
}
if (Block.getId(world.getType(x - 1, y, z)) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
if (Block.getId(world.getType(x + 1, y, z)) == id)
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
if (Block.getId(world.getType(x, y, z - 1)) == id)
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
if (Block.getId(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);
if (OpenInv.NotifySilentChest()) {
p.sendMessage("You are opening a chest silently.");
}
returnValue = false;
}
catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
}
}
if (anychest && OpenInv.NotifyAnyChest()) {
p.sendMessage("You are opening a blocked chest.");
}
return returnValue;
}
}

View file

@ -1,73 +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_R4;
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_7_R4.*;
import org.bukkit.craftbukkit.v1_7_R4.inventory.*;
public class InventoryAccess implements IInventoryAccess {
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 iiventory
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) {
OpenInv.log(e);
}
}
}
return result;
}
}

View file

@ -1,108 +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_R4;
import java.io.File;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IPlayerDataManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
//Volatile
import net.minecraft.server.v1_7_R4.*;
import org.bukkit.craftbukkit.v1_7_R4.*;
public class PlayerDataManager implements IPlayerDataManager {
public Player loadPlayer(String name) {
try {
UUID uuid = matchUser(name);
if (uuid == null) {
return null;
}
// Default player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata");
if (!playerfolder.exists()) {
return null;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null) {
return null;
}
GameProfile profile = new GameProfile(uuid, player.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;
}
}
catch (Exception e) {
OpenInv.log(e);
}
return null;
}
private static UUID matchUser(String search) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(search);
if (offlinePlayer != null && offlinePlayer.hasPlayedBefore()) {
return offlinePlayer.getUniqueId();
}
UUID found = null;
String lowerSearch = search.toLowerCase();
int delta = 2147483647;
OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
for (OfflinePlayer player : offlinePlayers) {
String name = player.getName();
if (name == null){
continue;
}
if (name.equalsIgnoreCase(search)){
return player.getUniqueId();
}
if (name.toLowerCase().startsWith(lowerSearch)) {
int curDelta = name.length() - lowerSearch.length();
if (curDelta < delta) {
found = player.getUniqueId();
delta = curDelta;
}
if (curDelta == 0) {
break;
}
}
}
return found;
}
}

View file

@ -1,36 +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_R4;
//Volatile
import net.minecraft.server.v1_7_R4.*;
public class SilentContainerChest extends ContainerChest {
public IInventory inv;
public SilentContainerChest(IInventory i1, IInventory i2) {
super(i1, i2);
inv = i2;
// close signal
inv.closeContainer();
}
@Override
public void b(EntityHuman paramEntityHuman) {
// Don't send close signal twice, might screw up
}
}

View file

@ -1,126 +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_R4;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import com.lishid.openinv.OpenInv;
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_R4.*;
import org.bukkit.craftbukkit.v1_7_R4.entity.*;
import org.bukkit.craftbukkit.v1_7_R4.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public boolean playerOnline = false;
private CraftPlayer owner;
private InventoryEnderChest enderChest;
private int maxStack = MAX_STACK;
private CraftInventory inventory = new CraftInventory(this);
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();
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.enderChests.remove(owner.getName().toLowerCase());
}
}
public void playerOnline(Player p) {
if (!playerOnline) {
try {
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);
}
catch (Exception e) {}
p.saveData();
playerOnline = true;
}
}
public void playerOffline() {
playerOnline = false;
}
public ItemStack[] getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
this.InventoryRemovalCheck();
}
public List<HumanEntity> getViewers() {
return transaction;
}
public InventoryHolder getOwner() {
return this.owner;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public int getMaxStackSize() {
return maxStack;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen() {
}
public void f() {
}
public void update() {
enderChest.update();
}
}

View file

@ -1,252 +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_R4;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
//Volatile
import net.minecraft.server.v1_7_R4.*;
import org.bukkit.craftbukkit.v1_7_R4.entity.*;
import org.bukkit.craftbukkit.v1_7_R4.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
CraftPlayer owner;
public boolean playerOnline = false;
private ItemStack[] extra = new ItemStack[5];
private CraftInventory inventory = new CraftInventory(this);
public SpecialPlayerInventory(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = ((CraftPlayer) p);
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
}
@Override
public Inventory getBukkitInventory() {
return inventory;
}
public void InventoryRemovalCheck() {
owner.saveData();
if (transaction.isEmpty() && !playerOnline) {
OpenInv.inventories.remove(owner.getName().toLowerCase());
}
}
@Override
public void playerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
playerOnline = true;
}
}
@Override
public void playerOffline() {
playerOnline = false;
this.InventoryRemovalCheck();
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.InventoryRemovalCheck();
}
@Override
public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(armor, 0, C, items.length, armor.length);
return C;
}
@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) {
owner.getHandle().drop(itemstack, true);
itemstack = null;
}
is[i] = itemstack;
owner.getHandle().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();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
}

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