Updated to MC 1.0.0

Fixed inventory not updating problem.
This commit is contained in:
lishd 2011-12-02 17:28:57 -05:00
parent 493f9b7e2e
commit ea95c5bfd0
6 changed files with 131 additions and 72 deletions

View file

@ -6,7 +6,6 @@ import lishid.openinv.utils.PlayerInventoryChest;
import net.minecraft.server.ContainerPlayer; import net.minecraft.server.ContainerPlayer;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.ICrafting;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -16,7 +15,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.nijiko.permissions.PermissionHandler; import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions; import com.nijikokun.bukkit.Permissions.Permissions;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.util.config.Configuration;
/** /**
* Open other player's inventory * Open other player's inventory
@ -28,7 +26,7 @@ public class OpenInv extends JavaPlugin {
private final OpenInvEntityListener entityListener = new OpenInvEntityListener(this); private final OpenInvEntityListener entityListener = new OpenInvEntityListener(this);
//private final OpenInvInventoryListener inventoryListener = new OpenInvInventoryListener(this); //private final OpenInvInventoryListener inventoryListener = new OpenInvInventoryListener(this);
public static PermissionHandler permissionHandler; public static PermissionHandler permissionHandler;
public static Configuration config; public static OpenInv mainPlugin;
public void onDisable() { public void onDisable() {
} }
@ -45,14 +43,17 @@ public class OpenInv extends JavaPlugin {
} }
public void onEnable() { public void onEnable() {
config = this.getConfiguration(); mainPlugin = this;
mainPlugin.getConfig().addDefault("ItemOpenInvItemID", 280);
mainPlugin.getConfig().options().copyDefaults(true);
mainPlugin.saveConfig();
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
//pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Highest, this); pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Event.Priority.Lowest, this);
//pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Monitor, this); pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Monitor, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Lowest, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Lowest, this);
//pm.registerEvent(Event.Type.INVENTORY_CLOSE, inventoryListener, Event.Priority.Normal, this); //pm.registerEvent(Event.Type.CUSTOM_EVENT, inventoryListener, Event.Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Monitor, this);
setupPermissions(); setupPermissions();
PluginDescriptionFile pdfFile = this.getDescription(); PluginDescriptionFile pdfFile = this.getDescription();
@ -67,12 +68,16 @@ public class OpenInv extends JavaPlugin {
{ {
try{ try{
EntityPlayer entityplayer = player.getHandle(); EntityPlayer entityplayer = player.getHandle();
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory); entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory, entityplayer);
entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic); entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic);
entityplayer.activeContainer = entityplayer.defaultContainer;
//sync //sync
((ICrafting)entityplayer).a(entityplayer.activeContainer, entityplayer.activeContainer.b()); try
{
entityplayer.syncInventory();
}catch(Exception e){}
entityplayer.a(entityplayer.activeContainer, entityplayer.activeContainer.b());
entityplayer.activeContainer.a(); entityplayer.activeContainer.a();
entityplayer.defaultContainer.a();
player.setHandle(entityplayer); player.setHandle(entityplayer);
} }
@ -84,26 +89,26 @@ public class OpenInv extends JavaPlugin {
public static boolean GetPlayerItemOpenInvStatus(String name) public static boolean GetPlayerItemOpenInvStatus(String name)
{ {
return config.getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false); return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false);
} }
public static void SetPlayerItemOpenInvStatus(String name, boolean status) public static void SetPlayerItemOpenInvStatus(String name, boolean status)
{ {
config.setProperty("ItemOpenInv." + name.toLowerCase() + ".toggle", status); mainPlugin.getConfig().set("ItemOpenInv." + name.toLowerCase() + ".toggle", status);
config.save(); mainPlugin.saveConfig();
} }
public static int GetItemOpenInvItem() public static int GetItemOpenInvItem()
{ {
return config.getInt("ItemOpenInvItemID", 280); return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280);
} }
public static Object GetFromConfig(String data, Object defaultValue) public static Object GetFromConfig(String data, Object defaultValue)
{ {
Object val = config.getProperty(data); Object val = mainPlugin.getConfig().get(data);
if (val == null) if (val == null)
{ {
config.setProperty(data, defaultValue); mainPlugin.getConfig().set(data, defaultValue);
return defaultValue; return defaultValue;
} }
else else
@ -114,7 +119,7 @@ public class OpenInv extends JavaPlugin {
public static void SaveToConfig(String data, Object value) public static void SaveToConfig(String data, Object value)
{ {
config.setProperty(data, value); mainPlugin.getConfig().set(data, value);
config.save(); mainPlugin.saveConfig();
} }
} }

View file

@ -1,9 +1,12 @@
package lishid.openinv; package lishid.openinv;
import lishid.openinv.commands.OpenInvPluginCommand;
import lishid.openinv.utils.PlayerInventoryChest;
import net.minecraft.server.Block; import net.minecraft.server.Block;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.IInventory; import net.minecraft.server.IInventory;
import net.minecraft.server.InventoryLargeChest; import net.minecraft.server.InventoryLargeChest;
import net.minecraft.server.Packet101CloseWindow;
import net.minecraft.server.TileEntityChest; import net.minecraft.server.TileEntityChest;
import net.minecraft.server.World; import net.minecraft.server.World;
@ -16,9 +19,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result; import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerLoginEvent;
public class OpenInvPlayerListener extends PlayerListener{ public class OpenInvPlayerListener extends PlayerListener{
OpenInv plugin; OpenInv plugin;
@ -27,17 +29,29 @@ public class OpenInvPlayerListener extends PlayerListener{
} }
@Override @Override
public void onPlayerJoin(PlayerJoinEvent event) public void onPlayerLogin(PlayerLoginEvent event)
{ {
OpenInv.ReplaceInv((CraftPlayer) event.getPlayer()); try{
for(Player target : OpenInvPluginCommand.offlineInv.values())
{
if(target.getName().equalsIgnoreCase(event.getPlayer().getName()))
{
System.out.print("[OpenInv] PlayerLogin event triggered closing openinv.");
EntityPlayer player = ((CraftPlayer)target).getHandle();
if(player.inventory instanceof PlayerInventoryChest)
{
((CraftPlayer)((PlayerInventoryChest)player.inventory).Opener).getHandle().netServerHandler.sendPacket(new Packet101CloseWindow());
}
target.saveData();
OpenInvPluginCommand.offlineInv.remove(player.inventory);
event.getPlayer().loadData();
break;
}
}
}
catch(Exception e){}
} }
@Override
public void onPlayerRespawn(PlayerRespawnEvent event)
{
OpenInv.ReplaceInv((CraftPlayer) event.getPlayer());
}
@Override @Override
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
@ -132,7 +146,9 @@ public class OpenInvPlayerListener extends PlayerListener{
{ {
if(plugin.getServer().getPlayer(((Sign)event.getClickedBlock().getState()).getLine(2)) != null) if(plugin.getServer().getPlayer(((Sign)event.getClickedBlock().getState()).getLine(2)) != null)
{ {
player.performCommand("openinv " + ((Sign)event.getClickedBlock().getState()).getLine(2)); Sign sign = ((Sign)event.getClickedBlock().getState());
String text = sign.getLine(2).trim() + sign.getLine(3).trim() + sign.getLine(4).trim();
player.performCommand("openinv " + text);
} }
else else
{ {

View file

@ -7,7 +7,7 @@ public class PermissionRelay {
public static boolean hasPermission(Player player, String permission) public static boolean hasPermission(Player player, String permission)
{ {
if (OpenInv.permissionHandler == null) { if (OpenInv.permissionHandler == null) {
return player.isOp(); return player.isOp() ? true : player.hasPermission(permission);
}else{ }else{
return OpenInv.permissionHandler.has(player, permission); return OpenInv.permissionHandler.has(player, permission);
} }

View file

@ -8,18 +8,21 @@ import lishid.openinv.utils.PlayerInventoryChest;
import lishid.openinv.utils.OpenInvHistory; import lishid.openinv.utils.OpenInvHistory;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.ItemInWorldManager;
import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class OpenInvPluginCommand implements CommandExecutor { public class OpenInvPluginCommand implements CommandExecutor {
private final OpenInv plugin; private final OpenInv plugin;
//public static HashMap<Player, PlayerInventoryChest> offlineInv = new HashMap<Player, PlayerInventoryChest>(); public static HashMap<PlayerInventoryChest, Player> offlineInv = new HashMap<PlayerInventoryChest, Player>();
public static HashMap<Player, OpenInvHistory> theOpenInvHistory = new HashMap<Player, OpenInvHistory>(); public static HashMap<Player, OpenInvHistory> theOpenInvHistory = new HashMap<Player, OpenInvHistory>();
public OpenInvPluginCommand(OpenInv plugin) { public OpenInvPluginCommand(OpenInv plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -31,7 +34,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
return true; return true;
} }
//boolean Offline = false; boolean Offline = false;
Player player = (Player)sender; Player player = (Player)sender;
//History management //History management
@ -72,10 +75,12 @@ public class OpenInvPluginCommand implements CommandExecutor {
//Target selecting //Target selecting
Player target; Player target;
String name = "";
if (args.length < 1) { if (args.length < 1) {
if(history.lastPlayer != null) if(history.lastPlayer != null)
{ {
target = this.plugin.getServer().getPlayer(history.lastPlayer); name = history.lastPlayer;
} }
else else
{ {
@ -85,33 +90,39 @@ public class OpenInvPluginCommand implements CommandExecutor {
} }
else else
{ {
target = this.plugin.getServer().getPlayer(args[0]); name = args[0];
} }
target = this.plugin.getServer().getPlayer(name);
if(target == null) if(target == null)
{ {
//Offline inv here... //Offline inv here...
/*try{ try{
MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer(); MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), args[0], new ItemInWorldManager(server.getWorldServer(0))); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), name, new ItemInWorldManager(server.getWorldServer(0)));
target = (entity == null) ? null : (Player) entity.getBukkitEntity(); target = (entity == null) ? null : (Player) entity.getBukkitEntity();
if(target != null) if(target != null)
{ {
Offline = true; Offline = true;
target.loadData(); target.loadData();
EntityPlayer entityplayer = ((CraftPlayer)target).getHandle();
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory, entityplayer);
} }
else else
{ {
sender.sendMessage(ChatColor.RED + "Player not found!"); sender.sendMessage(ChatColor.RED + "Player not found!");
return false; return false;
} }
} catch(Exception e) }
{*/ catch(Exception e)
//sender.sendMessage("Error while retrieving offline player data!"); {
sender.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found!"); sender.sendMessage("Error while retrieving offline player data!");
e.printStackTrace();
//sender.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found!");
return true; return true;
/*}*/ }
} }
//Check if target is the player him/her self //Check if target is the player him/her self
@ -146,12 +157,19 @@ public class OpenInvPluginCommand implements CommandExecutor {
{ {
OpenInv.ReplaceInv((CraftPlayer) target); OpenInv.ReplaceInv((CraftPlayer) target);
} }
/*
if(Offline && entitytarget.inventory instanceof PlayerInventoryChest) if(entitytarget.inventory instanceof PlayerInventoryChest)
{ {
offlineInv.put(target, (PlayerInventoryChest) entitytarget.inventory); ((PlayerInventoryChest)entitytarget.inventory).Opener = player;
((PlayerInventoryChest)entitytarget.inventory).Target = target;
if(Offline)
{
((PlayerInventoryChest)entitytarget.inventory).Offline = true;
offlineInv.put((PlayerInventoryChest) entitytarget.inventory, target);
}
} }
*/
entityplayer.a(entitytarget.inventory); entityplayer.a(entitytarget.inventory);
return true; return true;

View file

@ -1,25 +1,33 @@
package lishid.openinv.utils; package lishid.openinv.utils;
import net.minecraft.server.ContainerPlayer; import org.bukkit.entity.Player;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.InventoryPlayer;
public class PlayerInventoryChest extends InventoryPlayer import lishid.openinv.commands.OpenInvPluginCommand;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.PlayerInventory;
public class PlayerInventoryChest extends PlayerInventory
{ {
public PlayerInventoryChest(InventoryPlayer inventory) { public boolean Offline = false;
super(inventory.d); public Player Opener;
public Player Target;
public PlayerInventoryChest(PlayerInventory inventory, EntityPlayer entityplayer) {
super(entityplayer);
this.armor = inventory.armor; this.armor = inventory.armor;
this.items = inventory.items; this.items = inventory.items;
this.itemInHandIndex = inventory.itemInHandIndex; this.itemInHandIndex = inventory.itemInHandIndex;
this.e = inventory.e; this.e = inventory.e;
this.b(inventory.l()); this.b(inventory.l());
inventory.d.defaultContainer = new ContainerPlayer(this, !inventory.d.world.isStatic);
inventory.d.activeContainer = inventory.d.defaultContainer;
} }
@Override @Override
public String getName() { public String getName() {
return "Player Inventory"; if(this.d.name.length() > 16)
return this.d.name.substring(0, 16);
else
return this.d.name;
} }
@Override @Override
@ -27,4 +35,16 @@ public class PlayerInventoryChest extends InventoryPlayer
{ {
return true; return true;
} }
@Override
public void g() {
try{
Player player = OpenInvPluginCommand.offlineInv.get(this);
if(player != null)
{
player.saveData();
OpenInvPluginCommand.offlineInv.remove(this);
}
}catch(Exception e){}
}
} }

View file

@ -1,19 +1,19 @@
name: OpenInv name: OpenInv
main: lishid.openinv.OpenInv main: lishid.openinv.OpenInv
version: 1.4.6 version: 1.6.1
author: lishid author: lishid
description: > description: >
This plugin allows you to open another player's inventory as a chest This plugin allows you to open another player's inventory as a chest
commands: commands:
openinv: openinv:
description: Open a player's inventory description: Open a player's inventory
usage: | usage: |
/<command> <Player> /<command> <Player>
searchinv: searchinv:
description: Search and list players having a specific item description: Search and list players having a specific item
usage: | usage: |
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered. /<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
toggleopeninv: toggleopeninv:
description: Toggle the stick openinv description: Toggle the stick openinv
usage: | usage: |
/<command> [check] - Checks whether stick openinv is enabled /<command> [check] - Checks whether stick openinv is enabled