public static String getPlayerLanguage(Player player) { if (!(player instanceof CraftPlayer)) { return "en_US"; } EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); try { Field field = entityPlayer.getClass().getDeclaredField("locale"); field.setAccessible(true); return (String) field.get(entityPlayer); } catch (Exception e) { return "en_US"; } }
/** * チェストインベントリを開く * * @param p * @param x * @param y * @param z * @return */ public static boolean openChestInventory( Player bukkitPlayer, int x, int y, int z, boolean doAnimate) { EntityPlayer player = ((CraftPlayer) bukkitPlayer).getHandle(); World world = player.world; Object chest = (TileEntityChest) world.getTileEntity(x, y, z); if (chest == null) return false; final String label = "ラージチェスト"; if (world.getType(x - 1, y, z) == Blocks.CHEST) chest = new InventoryLargeChest( label, (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); if (world.getType(x + 1, y, z) == Blocks.CHEST) chest = new InventoryLargeChest( label, (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); if (world.getType(x, y, z - 1) == Blocks.CHEST) chest = new InventoryLargeChest( label, (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); if (world.getType(x, y, z + 1) == Blocks.CHEST) chest = new InventoryLargeChest( label, (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); if (doAnimate) { 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 ignore) { } // TODO temp fix, may broken on 1.5 player.playerConnection.sendPacket( new PacketPlayOutOpenWindow( id, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); // player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) // chest).getName(), ((IInventory) chest).getSize())); player.activeContainer = new CBContainerChest(player.inventory, ((IInventory) chest)); player.activeContainer.windowId = id; player.activeContainer.addSlotListener(player); return false; } catch (Exception ex) { ex.printStackTrace(); Util.message(bukkitPlayer, "&cError while sending chest inventory without animation"); } } return true; }