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

View file

@ -1,9 +1,12 @@
package lishid.openinv;
import lishid.openinv.commands.OpenInvPluginCommand;
import lishid.openinv.utils.PlayerInventoryChest;
import net.minecraft.server.Block;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.IInventory;
import net.minecraft.server.InventoryLargeChest;
import net.minecraft.server.Packet101CloseWindow;
import net.minecraft.server.TileEntityChest;
import net.minecraft.server.World;
@ -16,9 +19,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerLoginEvent;
public class OpenInvPlayerListener extends PlayerListener{
OpenInv plugin;
@ -27,17 +29,29 @@ public class OpenInvPlayerListener extends PlayerListener{
}
@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
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)
{
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
{

View file

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

View file

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

View file

@ -1,25 +1,33 @@
package lishid.openinv.utils;
import net.minecraft.server.ContainerPlayer;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.InventoryPlayer;
import org.bukkit.entity.Player;
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) {
super(inventory.d);
public boolean Offline = false;
public Player Opener;
public Player Target;
public PlayerInventoryChest(PlayerInventory inventory, EntityPlayer entityplayer) {
super(entityplayer);
this.armor = inventory.armor;
this.items = inventory.items;
this.itemInHandIndex = inventory.itemInHandIndex;
this.e = inventory.e;
this.b(inventory.l());
inventory.d.defaultContainer = new ContainerPlayer(this, !inventory.d.world.isStatic);
inventory.d.activeContainer = inventory.d.defaultContainer;
}
@Override
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
@ -27,4 +35,16 @@ public class PlayerInventoryChest extends InventoryPlayer
{
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
main: lishid.openinv.OpenInv
version: 1.4.6
author: lishid
description: >
This plugin allows you to open another player's inventory as a chest
commands:
openinv:
description: Open a player's inventory
usage: |
/<command> <Player>
searchinv:
description: Search and list players having a specific item
usage: |
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
toggleopeninv:
description: Toggle the stick openinv
usage: |
name: OpenInv
main: lishid.openinv.OpenInv
version: 1.6.1
author: lishid
description: >
This plugin allows you to open another player's inventory as a chest
commands:
openinv:
description: Open a player's inventory
usage: |
/<command> <Player>
searchinv:
description: Search and list players having a specific item
usage: |
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
toggleopeninv:
description: Toggle the stick openinv
usage: |
/<command> [check] - Checks whether stick openinv is enabled