mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
Latest version update 1.6.2
This commit is contained in:
parent
ea95c5bfd0
commit
7d4d830c77
5 changed files with 112 additions and 45 deletions
|
@ -52,8 +52,7 @@ public class OpenInv extends JavaPlugin {
|
||||||
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Event.Priority.Lowest, 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.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.CUSTOM_EVENT, inventoryListener, Event.Priority.Monitor, this);
|
//pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, 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();
|
||||||
|
@ -62,6 +61,7 @@ public class OpenInv extends JavaPlugin {
|
||||||
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
||||||
getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this));
|
getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this));
|
||||||
getCommand("toggleopeninv").setExecutor(new OpenInvPluginCommand(this));
|
getCommand("toggleopeninv").setExecutor(new OpenInvPluginCommand(this));
|
||||||
|
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReplaceInv(CraftPlayer player)
|
public static void ReplaceInv(CraftPlayer player)
|
||||||
|
@ -98,8 +98,23 @@ public class OpenInv extends JavaPlugin {
|
||||||
mainPlugin.saveConfig();
|
mainPlugin.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean GetPlayerSilentChestStatus(String name)
|
||||||
|
{
|
||||||
|
return mainPlugin.getConfig().getBoolean("SilentChest." + name.toLowerCase() + ".toggle", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetPlayerSilentChestStatus(String name, boolean status)
|
||||||
|
{
|
||||||
|
mainPlugin.getConfig().set("SilentChest." + name.toLowerCase() + ".toggle", status);
|
||||||
|
mainPlugin.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
public static int GetItemOpenInvItem()
|
public static int GetItemOpenInvItem()
|
||||||
{
|
{
|
||||||
|
if(mainPlugin.getConfig().get("ItemOpenInvItemID") == null)
|
||||||
|
{
|
||||||
|
SaveToConfig("ItemOpenInvItemID", 280);
|
||||||
|
}
|
||||||
return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280);
|
return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package lishid.openinv;
|
package lishid.openinv;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import lishid.openinv.commands.OpenInvPluginCommand;
|
import lishid.openinv.commands.OpenInvPluginCommand;
|
||||||
import lishid.openinv.utils.PlayerInventoryChest;
|
import lishid.openinv.utils.PlayerInventoryChest;
|
||||||
|
import lishid.openinv.utils.SilentContainerChest;
|
||||||
import net.minecraft.server.Block;
|
import net.minecraft.server.Block;
|
||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
|
import net.minecraft.server.ICrafting;
|
||||||
import net.minecraft.server.IInventory;
|
import net.minecraft.server.IInventory;
|
||||||
import net.minecraft.server.InventoryLargeChest;
|
import net.minecraft.server.InventoryLargeChest;
|
||||||
|
import net.minecraft.server.Packet100OpenWindow;
|
||||||
import net.minecraft.server.Packet101CloseWindow;
|
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;
|
||||||
|
@ -55,58 +60,44 @@ public class OpenInvPlayerListener extends PlayerListener{
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerInteract(PlayerInteractEvent event)
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
if(event.useInteractedBlock() == Result.DENY)
|
if(event.useInteractedBlock() == Result.DENY || event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
boolean silentchest = false;
|
||||||
|
boolean anychest = false;
|
||||||
|
int x = event.getClickedBlock().getX();
|
||||||
|
int y = event.getClickedBlock().getY();
|
||||||
|
int z = event.getClickedBlock().getZ();
|
||||||
|
|
||||||
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||||
|
event.getClickedBlock().getState() instanceof Chest &&
|
||||||
|
PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.silent") &&
|
||||||
|
OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName()))
|
||||||
|
{
|
||||||
|
silentchest = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||||
event.getClickedBlock().getState() instanceof Chest &&
|
event.getClickedBlock().getState() instanceof Chest &&
|
||||||
PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.anychest"))
|
PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.anychest"))
|
||||||
{
|
{
|
||||||
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
int x = event.getClickedBlock().getX();
|
|
||||||
int y = event.getClickedBlock().getY();
|
|
||||||
int z = event.getClickedBlock().getZ();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boolean override = false;
|
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
|
||||||
|
World world = player.world;
|
||||||
//If block on top
|
//If block on top
|
||||||
if(world.e(x, y + 1, z))
|
if(world.e(x, y + 1, z))
|
||||||
override = true;
|
anychest = true;
|
||||||
|
|
||||||
//If block next to chest is chest and has a block on top
|
//If block next to chest is chest and has a block on top
|
||||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z)))
|
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z)))
|
||||||
override = true;
|
anychest = true;
|
||||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z)))
|
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z)))
|
||||||
override = true;
|
anychest = true;
|
||||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1)))
|
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1)))
|
||||||
override = true;
|
anychest = true;
|
||||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1)))
|
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1)))
|
||||||
override = true;
|
anychest = true;
|
||||||
|
|
||||||
//If the chest is blocked
|
|
||||||
if(override)
|
|
||||||
{
|
|
||||||
//Create chest
|
|
||||||
Object inventory = (TileEntityChest)player.world.getTileEntity(x, y, z);
|
|
||||||
|
|
||||||
//Link chest
|
|
||||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id) inventory = new InventoryLargeChest("Large chest", (TileEntityChest)world.getTileEntity(x - 1, y, z), (IInventory)inventory);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == Block.CHEST.id) inventory = new InventoryLargeChest("Large chest", (IInventory)inventory, (TileEntityChest)world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == Block.CHEST.id) inventory = new InventoryLargeChest("Large chest", (TileEntityChest)world.getTileEntity(x, y, z - 1), (IInventory)inventory);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) inventory = new InventoryLargeChest("Large chest", (IInventory)inventory, (TileEntityChest)world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
//Open chest
|
|
||||||
player.a((IInventory)inventory);
|
|
||||||
|
|
||||||
//Send a notification
|
|
||||||
event.getPlayer().sendMessage("You are opening a blocked chest.");
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Chest chest = (Chest)event.getClickedBlock().getState();
|
|
||||||
player.a(((CraftInventory)chest.getInventory()).getInventory());*/
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
catch(Exception e) //Incompatible CraftBukkit?
|
catch(Exception e) //Incompatible CraftBukkit?
|
||||||
{
|
{
|
||||||
|
@ -115,6 +106,59 @@ public class OpenInvPlayerListener extends PlayerListener{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//If the chest is blocked
|
||||||
|
if(anychest || silentchest)
|
||||||
|
{
|
||||||
|
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
|
||||||
|
World world = player.world;
|
||||||
|
Object chest = (TileEntityChest)world.getTileEntity(x, y, z);
|
||||||
|
if (chest == null) return;
|
||||||
|
|
||||||
|
if(!anychest)
|
||||||
|
{
|
||||||
|
if (world.e(x, y + 1, z)) return;
|
||||||
|
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z))) return;
|
||||||
|
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z))) return;
|
||||||
|
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1))) return;
|
||||||
|
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1))) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
if(!silentchest)
|
||||||
|
{
|
||||||
|
player.a((IInventory)chest);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
Field ciField = player.getClass().getDeclaredField("ci");
|
||||||
|
ciField.setAccessible(true);
|
||||||
|
int ci = ciField.getInt(player);
|
||||||
|
ci = ci % 100 + 1;
|
||||||
|
ciField.setInt(player, ci);
|
||||||
|
player.netServerHandler.sendPacket(new Packet100OpenWindow(ci, 0, ((IInventory)chest).getName(), ((IInventory)chest).getSize()));
|
||||||
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory)chest));
|
||||||
|
System.out.println(player.activeContainer.toString());
|
||||||
|
player.activeContainer.windowId = ci;
|
||||||
|
player.activeContainer.a((ICrafting)player);
|
||||||
|
event.getPlayer().sendMessage("You are opening a silent chest.");
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(anychest)
|
||||||
|
event.getPlayer().sendMessage("You are opening a blocked chest.");
|
||||||
|
}
|
||||||
|
|
||||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||||
(event.getClickedBlock() == Block.CHEST ||
|
(event.getClickedBlock() == Block.CHEST ||
|
||||||
event.getClickedBlock() == Block.FURNACE ||
|
event.getClickedBlock() == Block.FURNACE ||
|
||||||
|
@ -142,12 +186,12 @@ public class OpenInvPlayerListener extends PlayerListener{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
try{
|
try{
|
||||||
if (PermissionRelay.hasPermission(player, "openinv") &&
|
if (PermissionRelay.hasPermission(player, "openinv") &&
|
||||||
((Sign)event.getClickedBlock().getState()).getLine(1).equalsIgnoreCase("[openinv]"))
|
((Sign)event.getClickedBlock().getState()).getLine(0).equalsIgnoreCase("[openinv]"))
|
||||||
{
|
{
|
||||||
if(plugin.getServer().getPlayer(((Sign)event.getClickedBlock().getState()).getLine(2)) != null)
|
if(plugin.getServer().getPlayer(((Sign)event.getClickedBlock().getState()).getLine(1)) != null)
|
||||||
{
|
{
|
||||||
Sign sign = ((Sign)event.getClickedBlock().getState());
|
Sign sign = ((Sign)event.getClickedBlock().getState());
|
||||||
String text = sign.getLine(2).trim() + sign.getLine(3).trim() + sign.getLine(4).trim();
|
String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(2).trim();
|
||||||
player.performCommand("openinv " + text);
|
player.performCommand("openinv " + text);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -159,6 +203,7 @@ public class OpenInvPlayerListener extends PlayerListener{
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
player.sendMessage("Internal Error.");
|
player.sendMessage("Internal Error.");
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,11 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
||||||
{
|
{
|
||||||
//Offline inv here...
|
//Offline inv here...
|
||||||
try{
|
try{
|
||||||
|
if(!this.plugin.getServer().getOfflinePlayer(name).hasPlayedBefore())
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer();
|
MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer();
|
||||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), name, 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();
|
||||||
|
|
|
@ -22,8 +22,6 @@ public class SearchInvPluginCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
String PlayerList = "";
|
String PlayerList = "";
|
||||||
|
|
||||||
Material material = null;
|
Material material = null;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: OpenInv
|
name: OpenInv
|
||||||
main: lishid.openinv.OpenInv
|
main: lishid.openinv.OpenInv
|
||||||
version: 1.6.1
|
version: 1.6.2
|
||||||
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
|
||||||
|
@ -17,3 +17,7 @@ commands:
|
||||||
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
|
||||||
|
silentchest:
|
||||||
|
description: Toggle silent chest, which does not animate a chest when opened or closed, and suppresses the sound.
|
||||||
|
usage: |
|
||||||
|
/<command> [check] - Checks whether silent chest is enabled
|
Loading…
Reference in a new issue