public void displayVillagerTradeGui(IMerchant villager) { this.getNextWindowId(); this.openContainer = new ContainerMerchant(this.inventory, villager, this.worldObj); this.openContainer.windowId = this.currentWindowId; this.openContainer.onCraftGuiOpened(this); IInventory iinventory = ((ContainerMerchant)this.openContainer).getMerchantInventory(); IChatComponent ichatcomponent = villager.getDisplayName(); this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "minecraft:villager", ichatcomponent, iinventory.getSizeInventory())); MerchantRecipeList merchantrecipelist = villager.getRecipes(this); if (merchantrecipelist != null) { PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); packetbuffer.writeInt(this.currentWindowId); merchantrecipelist.writeToBuf(packetbuffer); this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer)); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, Packet msg) throws Exception { boolean handled = false; if (msg instanceof C17PacketCustomPayload) { handled = handleServerSideCustomPacket((C17PacketCustomPayload) msg, ctx); } else if (msg instanceof S3FPacketCustomPayload) { handled = handleClientSideCustomPacket((S3FPacketCustomPayload)msg, ctx); } else if (state != ConnectionState.CONNECTED && state != ConnectionState.HANDSHAKECOMPLETE) { handled = handleVanilla(msg); } if (!handled) { ctx.fireChannelRead(msg); } }
public void displayGUIMerchant(IMerchant par1IMerchant, String par2Str) { this.getNextWindowId(); this.openContainer = new ContainerMerchant(this.inventory, par1IMerchant, this.worldObj); this.openContainer.windowId = this.currentWindowId; this.openContainer.addCraftingToCrafters(this); InventoryMerchant var3 = ((ContainerMerchant)this.openContainer).getMerchantInventory(); this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 6, par2Str == null ? "" : par2Str, var3.getSizeInventory(), par2Str != null)); MerchantRecipeList var4 = par1IMerchant.getRecipes(this); if (var4 != null) { try { PacketBuffer var5 = new PacketBuffer(Unpooled.buffer()); var5.writeInt(this.currentWindowId); var4.func_151391_a(var5); this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", var5)); } catch (IOException var6) { logger.error("Couldn\'t send trade list", var6); } } }
public void sendNameUpdate() { String name = this.dataWatcher.getWatchableObjectString(19); if (owner != null && name != null) { EntityPlayer o = (EntityPlayer) this.worldObj.getPlayerEntityByName(owner); if (o != null) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt(1); pb.writeInt(name.getBytes().length); pb.writeBytes(name.getBytes()); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarFam", pb); ((EntityPlayerMP) o).playerNetServerHandler.sendPacket(packet); } } }
public void sendDeathUpdate() { if (owner != null) { EntityPlayer o = (EntityPlayer) this.worldObj.getPlayerEntityByName(owner); if (o != null) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt(4); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarFam", pb); ((EntityPlayerMP) o).playerNetServerHandler.sendPacket(packet); } } }
public void sendHealthUpdate() { if (owner != null) { EntityPlayer o = (EntityPlayer) this.worldObj.getPlayerEntityByName(owner); if (o != null) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt(2); pb.writeInt((int) this.getHealth()); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarFam", pb); ((EntityPlayerMP) o).playerNetServerHandler.sendPacket(packet); this.healthlastsent = (int) this.getHealth(); } } }
public void sendMoodUpdate() { if (owner != null) { EntityPlayer o = (EntityPlayer) this.worldObj.getPlayerEntityByName(owner); if (o != null) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt(3); pb.writeInt(this.mood); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarFam", pb); ((EntityPlayerMP) o).playerNetServerHandler.sendPacket(packet); this.moodlastsent = this.mood; } } }
public void syncGlidingSERVER(int type, String name){ /*0 - add, 1 - remove*/ PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("gliderdata".getBytes().length); pb.writeBytes("gliderdata".getBytes()); pb.writeInt(type); pb.writeInt(name.getBytes().length); pb.writeBytes(name.getBytes()); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarMisc", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
public static void spawnParticle(String particle, World w, double x, double y, double z, int total, double size) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt(particle.getBytes().length); pb.writeBytes(particle.getBytes()); pb.writeDouble(x); pb.writeDouble(y); pb.writeDouble(z); pb.writeInt(total); pb.writeDouble(size); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarPar", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
/** * * @param location - where the shield will spawn around * @param height - of the shield * @param radius - of the shield * @param yquality - Y axis quality, don't mess with please. Higher is better quality. * @param xzquality - XZ axis quality, feel free to experiment. It is the number of degrees between particle spawns in the circle. Lower is better quality. 6 is a good value. * @param chance - The chance of particles spawning, feel free to experiment. eg 10 is one tenth. Lower is better quality. 10 is a good value. * @param element - Element of the shield (water, air or fire) */ public static void sendShield(Location location, int height, int radius, int yquality, int xzquality, int chance, int element){ PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("Avatar_shield".getBytes().length); pb.writeBytes("Avatar_shield".getBytes()); pb.writeDouble(location.getX()); pb.writeDouble(location.getY()); pb.writeDouble(location.getZ()); pb.writeInt(0); pb.writeDouble(0); pb.writeInt(height); pb.writeInt(radius); pb.writeInt(yquality); pb.writeInt(xzquality); pb.writeInt(chance); pb.writeInt(element); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarPar", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
public static void sendCircle(Location location, double radius, int xzquality, int chance, int element){ PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("Avatar_circle".getBytes().length); pb.writeBytes("Avatar_circle".getBytes()); pb.writeDouble(location.getX()); pb.writeDouble(location.getY()); pb.writeDouble(location.getZ()); pb.writeInt(0); pb.writeDouble(0); pb.writeDouble(radius); pb.writeInt(xzquality); //XZ axis quality, feel free to experiment. It is the number of degrees between particle spawns in the circle. Lower is better quality. 6 is a good value. pb.writeInt(chance); //The chance of particles spawning, feel free to experiment. eg 10 is one tenth. Lower is better quality. 10 is a good value. pb.writeInt(element); //Element } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarPar", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
public static void sendDisc(Location location, int radius, int xzquality, int chance, int element){ PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("Avatar_disc".getBytes().length); pb.writeBytes("Avatar_disc".getBytes()); pb.writeDouble(location.getX()); pb.writeDouble(location.getY()); pb.writeDouble(location.getZ()); pb.writeInt(0); pb.writeDouble(0); pb.writeInt(radius); pb.writeInt(xzquality); //XZ axis quality, feel free to experiment. It is the number of degrees between particle spawns in the circle. Lower is better quality. 6 is a good value. pb.writeInt(chance); //The chance of particles spawning, feel free to experiment. eg 10 is one tenth. Lower is better quality. 10 is a good value. pb.writeInt(element); //Element } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarPar", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
public static void sendVelocity(Entity entity, double x, double y, double z) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("velocity".getBytes().length); pb.writeBytes("velocity".getBytes()); pb.writeInt(entity.getEntityId()); pb.writeDouble(x); pb.writeDouble(y); pb.writeDouble(z); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarMisc", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); entity.motionX = x; entity.motionY = y; entity.motionZ = z; }
public static void sendIsBending(Entity entity, boolean isBending, int element) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("isBending".getBytes().length); pb.writeBytes("isBending".getBytes()); pb.writeBoolean(isBending); pb.writeInt(entity.getEntityId()); pb.writeInt(element); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarMisc", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
public void sendSupportedChannels(){ if(netHandler == null){ return; } Set<String> listening = NailedPlatform.instance().getMessenger().getIncomingChannels(); if(!listening.isEmpty()){ ByteArrayOutputStream stream = new ByteArrayOutputStream(); for (String channel : listening) { try{ stream.write(channel.getBytes(CharsetUtil.UTF_8)); stream.write((byte) 0); }catch(IOException e){ logger.error("Could not send Plugin Channel REGISTER to " + getName(), e); } } sendPacket(new S3FPacketCustomPayload("REGISTER", Unpooled.copiedBuffer(stream.toByteArray()))); } }
/** * Displays the GUI for interacting with a book. */ public void displayGUIBook(ItemStack bookStack) { Item item = bookStack.getItem(); if (item == Items.written_book) { this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|BOpen", new PacketBuffer(Unpooled.buffer()))); } }
/** * Handles packets that have room for a channel specification. Vanilla * implemented channels are "MC|TrList" to acquire a MerchantRecipeList trades * for a villager merchant, "MC|Brand" which sets the server brand? on the * player instance and finally "MC|RPack" which the server uses to communicate * the identifier of the default server resourcepack for the client to load. */ public void handleCustomPayload(S3FPacketCustomPayload packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); if ("MC|TrList".equals(packetIn.getChannelName())) { PacketBuffer packetbuffer = packetIn.getBufferData(); try { int i = packetbuffer.readInt(); GuiScreen guiscreen = this.gameController.currentScreen; if (guiscreen != null && guiscreen instanceof GuiMerchant && i == this.gameController.thePlayer.openContainer.windowId) { IMerchant imerchant = ((GuiMerchant) guiscreen).getMerchant(); MerchantRecipeList merchantrecipelist = MerchantRecipeList.readFromBuf(packetbuffer); imerchant.setRecipes(merchantrecipelist); } } catch (IOException ioexception) { logger.error((String) "Couldn\'t load trade info", (Throwable) ioexception); } finally { packetbuffer.release(); } } else if ("MC|Brand".equals(packetIn.getChannelName())) { this.gameController.thePlayer.setClientBrand(packetIn.getBufferData().readStringFromBuffer(32767)); } else if ("MC|BOpen".equals(packetIn.getChannelName())) { ItemStack itemstack = this.gameController.thePlayer.getCurrentEquippedItem(); if (itemstack != null && itemstack.getItem() == Items.written_book) { this.gameController .displayGuiScreen(new GuiScreenBook(this.gameController.thePlayer, itemstack, false)); } } }
private static Packet make(Side side, String channel) { if (FMLCommonHandler.instance().getSide() == Side.SERVER && side == Side.CLIENT) { return null; } if (side == Side.CLIENT) { return new C17PacketCustomPayload(channel, new PacketBuffer(Unpooled.buffer(0))); } else { return new S3FPacketCustomPayload(channel, new PacketBuffer(Unpooled.buffer(0))); } }
@Override public String getChannel(Packet packet) { if (packet instanceof S3FPacketCustomPayload) { S3FPacketCustomPayload p = (S3FPacketCustomPayload) packet; return p.getChannelName(); } return super.getChannel(packet); }
@Override public void dispatchCUIEvent(CUIEvent event) { String[] params = event.getParameters(); String send = event.getTypeId(); if (params.length > 0) { send = send + "|" + StringUtil.joinString(params, "|"); } PacketBuffer buffer = new PacketBuffer(Unpooled.copiedBuffer(send.getBytes(WECUIPacketHandler.UTF_8_CHARSET))); S3FPacketCustomPayload packet = new S3FPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, buffer); this.player.playerNetServerHandler.sendPacket(packet); }
@Override public void dispatchCUIEvent(CUIEvent event) { String[] params = event.getParameters(); String send = event.getTypeId(); if (params.length > 0) { send = send + "|" + StringUtil.joinString(params, "|"); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, send.getBytes(WECUIPacketHandler.UTF_8_CHARSET)); this.player.playerNetServerHandler.sendPacket(packet); }
@Override public boolean sendCustomPayloadToAllPlayers(String channel, byte[] bytes) { boolean toRet = false; try { if (bytes == null) { throw new CustomPayloadChannelException("Invalid Custom Payload: Byte Array is null."); } if (channel == null || channel.trim().equals("") || isReservedChannel(channel)) { throw new CustomPayloadChannelException(String.format("Invalid Custom Payload: Invalid channel name of '%s'", channel)); } if (channel.length() > 20) { throw new CustomPayloadChannelException(String.format("Invalid Custom Payload: Channel Name too long '%s'", channel)); } if (this.clients.containsKey(channel)) { for (final NetServerHandler handler : this.clients.get(channel)) { final PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); packetbuffer.writeByteArray(bytes); handler.sendPacket((Packet) new S3FPacketCustomPayload(channel, packetbuffer)); toRet = true; } } } catch (final CustomPayloadChannelException ex) { Canary.log.error(ex.getMessage(), ex); } return toRet; }
@Override public boolean sendCustomPayloadToPlayer(String channel, byte[] bytes, Player player) { try { if (bytes == null) { throw new CustomPayloadChannelException("Invalid Custom Payload: Byte Array is null."); } if (channel == null || channel.trim().equals("") || isReservedChannel(channel)) { throw new CustomPayloadChannelException(String.format("Invalid Custom Payload: Invalid channel name of '%s'", channel)); } if (channel.length() > 20) { throw new CustomPayloadChannelException(String.format("Invalid Custom Payload: Channel Name too long '%s'", channel)); } if (player == null) { throw new CustomPayloadChannelException("Invalid Custom Payload: Player is null."); } if (this.clients.containsKey(channel)) { for (final NetServerHandler handler : this.clients.get(channel)) { if (handler.getUser().equals(player)) { final PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); packetbuffer.writeByteArray(bytes); handler.sendPacket((Packet) new S3FPacketCustomPayload(channel, packetbuffer)); return true; } } } } catch (final CustomPayloadChannelException ex) { Canary.log.error(ex.getMessage(), ex); } return false; }
public void displayGUIMerchant(IMerchant p_71030_1_, String p_71030_2_) { // CraftBukkit start - Inventory open hook Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerMerchant(this.inventory, p_71030_1_, this.worldObj)); if (container == null) { return; } // CraftBukkit end this.getNextWindowId(); this.openContainer = container; // CraftBukkit - Use container we passed to event this.openContainer.windowId = this.currentWindowId; this.openContainer.addCraftingToCrafters(this); InventoryMerchant inventorymerchant = ((ContainerMerchant)this.openContainer).getMerchantInventory(); this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 6, p_71030_2_ == null ? "" : p_71030_2_, inventorymerchant.getSizeInventory(), p_71030_2_ != null)); MerchantRecipeList merchantrecipelist = p_71030_1_.getRecipes(this); if (merchantrecipelist != null) { PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); try { packetbuffer.writeInt(this.currentWindowId); merchantrecipelist.func_151391_a(packetbuffer); this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer)); } catch (Exception ioexception) // CraftBukkit - IOException -> Exception { logger.error("Couldn\'t send trade list", ioexception); } finally { packetbuffer.release(); } } }
public void displayGUIMerchant(IMerchant p_71030_1_, String p_71030_2_) { this.getNextWindowId(); this.openContainer = new ContainerMerchant(this.inventory, p_71030_1_, this.worldObj); this.openContainer.windowId = this.currentWindowId; this.openContainer.addCraftingToCrafters(this); InventoryMerchant inventorymerchant = ((ContainerMerchant)this.openContainer).getMerchantInventory(); this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 6, p_71030_2_ == null ? "" : p_71030_2_, inventorymerchant.getSizeInventory(), p_71030_2_ != null)); MerchantRecipeList merchantrecipelist = p_71030_1_.getRecipes(this); if (merchantrecipelist != null) { PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer()); try { packetbuffer.writeInt(this.currentWindowId); merchantrecipelist.func_151391_a(packetbuffer); this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer)); } catch (IOException ioexception) { logger.error("Couldn\'t send trade list", ioexception); } finally { packetbuffer.release(); } } }
public FireFlight(EntityLivingBase user, int level) { super(user, cooldown + (level * 5000)); this.user = user; starttime = System.currentTimeMillis(); if(level == 0){ flightTime = 1700; flightSpeed = 0.8; } if(level == 1){ flightTime = 3000; flightSpeed = 1; } if(level == 2){ flightTime = 5000; flightSpeed = 1.3; } PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("ContinueSound".getBytes().length); pb.writeBytes("ContinueSound".getBytes()); pb.writeInt((mod_Avatar.modid + ":" + "fire06looping").getBytes().length); pb.writeBytes((mod_Avatar.modid + ":" + "fire06looping").getBytes()); pb.writeInt(user.getUniqueID().toString().getBytes().length); pb.writeBytes(user.getUniqueID().toString().getBytes()); pb.writeBoolean(true); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarBend", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
@Override public void update() { if (user.isSneaking()) { BlockBukkit t = BlockBukkit.getTargetBlock(user); PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("FireLightning".getBytes().length); pb.writeBytes("FireLightning".getBytes()); pb.writeDouble(t.getX()); pb.writeDouble(t.getY()); pb.writeDouble(t.getZ()); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarBend", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); return; } else { strike(System.currentTimeMillis() - starttime); } if(user.worldObj.isRaining()){ isRaining = true; } }
public static void playPublicMusic(World world, String song) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("music".getBytes().length); pb.writeBytes("music".getBytes()); pb.writeStringToBuffer(song); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarMisc", pb); MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(packet); }
public static void playMusic(EntityPlayer player, String song) { PacketBuffer pb = new PacketBuffer(Unpooled.buffer()); try { pb.writeInt("music".getBytes().length); pb.writeBytes("music".getBytes()); pb.writeStringToBuffer(song); } catch (Exception ex) { ex.printStackTrace(); } S3FPacketCustomPayload packet = new S3FPacketCustomPayload("AvatarMisc", pb); ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(packet); }
@Override public void sendPluginMessage(PluginIdentifier source, String channel, byte[] message) { StandardMessenger.validatePluginMessage(NailedPlatform.instance().getMessenger(), source, channel, message); if(netHandler == null){ return; } if(channels.contains(channel)){ this.sendPacket(new S3FPacketCustomPayload(channel, Unpooled.copiedBuffer(message))); } }