@Override public IMessage handleServerMessage(EntityPlayer player, MessageSyncAdd message, MessageContext ctx) { if ((player != null) && (message != null) && (ctx != null)) { EntityLivingBase en = (EntityLivingBase) player.getEntityWorld().getEntityByID(message.entityId); if (en != null) { if (player.getEntityId() == en.getEntityId() && en.getEntityWorld() != null && en.hasCapability(Currency.ACCOUNT_DATA, null)) { AccountCapability entityData = en.getCapability(Currency.ACCOUNT_DATA, null); for (ItemStack stack : CurrencyUtils.itemMoneyAmount(message.amount)) { if (stack != null && stack != ItemStack.EMPTY && en instanceof EntityPlayer) { EntityPlayer pl = (EntityPlayer) en; pl.inventory.addItemStackToInventory(stack); } } } } } return null; }
@Override public IMessage onMessage(final PacketClassGui message, final MessageContext ctx) { IThreadListener mainThread = Minecraft.getMinecraft(); mainThread.addScheduledTask(new Runnable() { @Override public void run() { EntityPlayer player = Minecraft.getMinecraft().player; PlayerInformation playerInfo = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null); if (playerInfo != null && playerInfo.getPlayerClass() == 0) { player.openGui(LootSlashConquer.instance, GuiHandler.CLASS_SELECTION, player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ()); } } }); return null; }
@Override public IMessage onMessage(final PacketUpdateChunkLevel message, final MessageContext ctx) { IThreadListener mainThread = Minecraft.getMinecraft(); mainThread.addScheduledTask(new Runnable() { @Override public void run() { World world = Minecraft.getMinecraft().world; ChunkPos chunkPos = new ChunkPos(message.chunkX, message.chunkZ); IChunkLevelHolder chunkLevelHolder = CapabilityChunkLevel.getChunkLevelHolder(world); if (chunkLevelHolder.getChunkLevel(chunkPos) != null) return; IChunkLevel chunkLevel = new ChunkLevel(world, chunkPos, message.level); chunkLevelHolder.setChunkLevel(chunkPos, chunkLevel); } }); return null; }
@Override public IMessage onMessage(final MessageWorldCraft message, final MessageContext ctx) { if(ctx.side != Side.SERVER) { System.err.println("MessageWorldCraft received on wrong side:" + ctx.side); return null; } final EntityPlayerMP sendingPlayer = ctx.getServerHandler().player; if(sendingPlayer == null) { System.err.println("MessageWorldCraft received with null player."); return null; } final WorldServer playerWorldServer = sendingPlayer.getServerWorld(); playerWorldServer.addScheduledTask(() -> processMessage(message, ctx, playerWorldServer)); return null; }
@Override public IMessage onMessage(TeleportRequest message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().player; if(Perms.isOP(player) == false){ Main.LOGGER.info(player.getName() + " tried to teleport, but was denied to do so!"); return null; } new RunInServerThread(new Runnable() { @Override public void run() { Entity e = FMLCommonHandler.instance().getMinecraftServerInstance().getEntityFromUuid(message.uuid); if(e == null){ player.sendMessage(new TextComponentString(TextFormatting.RED + "Woops! This tile entity no longer exists!")); return; } Teleport.teleportPlayer(player, e.dimension, e.posX, e.posY, e.posZ); } }); return null; }
@Override @SideOnly(Side.CLIENT) public IMessage onMessage(MessageReceiveConfiguration message, MessageContext ctx) { FirstAid.activeHealingConfig = message.healingCfg; FirstAid.activeDamageConfig = message.damageCfg; FirstAid.scaleMaxHealth = message.scaleMaxHealth; AbstractPlayerDamageModel damageModel = PlayerDamageModel.create(); damageModel.deserializeNBT(message.playerDamageModel); Minecraft mc = Minecraft.getMinecraft(); FirstAid.playerMaxHealth = FirstAid.activeDamageConfig.maxHealthHead + FirstAid.activeDamageConfig.maxHealthLeftArm + FirstAid.activeDamageConfig.maxHealthLeftLeg + FirstAid.activeDamageConfig.maxHealthLeftFoot + FirstAid.activeDamageConfig.maxHealthBody + FirstAid.activeDamageConfig.maxHealthRightArm + FirstAid.activeDamageConfig.maxHealthRightLeg + FirstAid.activeDamageConfig.maxHealthRightFoot; FirstAid.logger.info("Received configuration"); mc.addScheduledTask(() -> { PlayerDataManager.capList.put(mc.player, damageModel); if (damageModel.hasTutorial) PlayerDataManager.tutorialDone.add(mc.player.getName()); else mc.player.sendMessage(new TextComponentString("[First Aid] " + I18n.format("firstaid.tutorial.hint", ClientProxy.showWounds.getDisplayName()))); }); return null; }
@Override public IMessage onMessage(final JumpkinRotationMessage message, MessageContext ctx) { Minecraft minecraft = Minecraft.getMinecraft(); final WorldClient world = minecraft.world; minecraft.addScheduledTask(new Runnable() { @Override public void run() { EntityJumpkin entity = (EntityJumpkin)world.getEntityByID(message.entityId); entity.rotationYaw = message.rotationYaw; entity.rotationPitch = message.rotationPitch; } }); return null; }
@Override public IMessage onMessage(MessageGlassJarUpdateStats message, MessageContext ctx) { ItemStack stack = message.stack; BlockPos pos = message.pos; WorldClient world = Minecraft.getMinecraft().world; if (world.isBlockLoaded(pos) && world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))) { TileEntity te = world.getTileEntity(pos); if (te instanceof TileFaerieHome) { IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (handler != null) { handler.insertItem(0, stack, false); } } } return null; }
@Override public IMessage onMessage(EnergyMessage message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(() -> { final EntityPlayer entityTarget = Minecraft.getMinecraft().world.getPlayerEntityByUUID(message.target); if (entityTarget != null) { final Optional<IEnergy> optData = EnergyHandler.getEnergy(entityTarget); if (optData.isPresent()) { final IEnergy data = optData.get(); data.set(message.energy.get()); data.setMax(message.energy.getMax()); data.setRegen(message.energy.getRegenTime(), message.energy.getRegenBurst()); data.setUses(message.energy.getUses()); data.setType(message.energy.getType()); } } }); return null; }
/** IMPORTANT: Call this from the onMessage method in the subclass. */ public IMessage processMessage(final ObservationRequestMessage message, final MessageContext ctx) { IThreadListener mainThread = (WorldServer)ctx.getServerHandler().playerEntity.worldObj; mainThread.addScheduledTask(new Runnable() { @Override public void run() { EntityPlayerMP player = ctx.getServerHandler().playerEntity; JsonObject json = new JsonObject(); buildJson(json, player, message, ctx); // Send this message back again now we've filled in the json stats. Map<String, String> returnData = new HashMap<String, String>(); returnData.put("json", json.toString()); message.addReturnData(returnData); MalmoMod.network.sendTo(new MalmoMod.MalmoMessage(MalmoMessageType.SERVER_OBSERVATIONSREADY, message.id, returnData), player); } }); return null; // no response in this case }
@SideOnly(Side.CLIENT) @Override public IMessage onMessage(final MessageSoulDrainFX message, final MessageContext ctx) { World world = Minecraft.getMinecraft().world; if (world.isRemote) { for (double i = 0; i < 8; i++) { double xCoord = message.posX + (rand.nextDouble() - 0.5); double yCoord = message.posY + (rand.nextDouble() - 0.5); double zCoord = message.posZ + (rand.nextDouble() - 0.5); world.spawnParticle(EnumParticleTypes.CRIT, true, xCoord, yCoord, zCoord, (rand.nextDouble() - 0.5), (rand.nextDouble() - 0.5), (rand.nextDouble() - 0.5)); } ParticleUtils.spawnParticleBeam(world, EnumParticleTypes.CRIT, message.posX, message.posY, message.posZ, message.castX, message.castY, message.castZ, 0.2); } return null; }
@Override public IMessage onMessage(SPacketUnlock message, MessageContext ctx) { ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> { boolean result = false; TileEntity te = ctx.getServerHandler().player.world.getTileEntity(message.pos); if(te != null && te instanceof TileCodeStorage) { TileCodeStorage storage = (TileCodeStorage) te; result = storage.tryUnlock(message.code); } NetworkManager.sendTo(new CPacketUnlockResponse(result), ctx.getServerHandler().player); }); return null; }
@Override @SideOnly(Side.CLIENT) public IMessage onMessage(RandoresDataNeededQuery message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(() -> { Randores.debug("Received data needed query from server: " + message.getId()); World world = Minecraft.getMinecraft().world; RandoresWorldData data = RandoresWorldData.getSimply(world); if(!data.isLoaded() || !data.getId().equals(message.getId())) { RandoresNetworking.INSTANCE.sendToServer(new RandoresDataRequest().setId(message.getId())); Randores.debug("Sent request for data; an update is required"); } else { Randores.debug("Update not required."); } }); return null; }
public void sendTo(IMessage message, EntityPlayerMP player) { if(useUdp && discriminators.containsKey(message.getClass())) { InetSocketAddress address=TF2weapons.udpServer.outboundTargets.get(player.getCapability(TF2weapons.PLAYER_CAP, null).udpServerId); if (address != null) { ByteBuf buffer = Unpooled.buffer(); buffer.writeShort(0); buffer.writeByte(discriminators.get(message.getClass())); message.toBytes(buffer); DatagramPacket packet = new DatagramPacket(buffer, address); TF2weapons.udpServer.channel.writeAndFlush(packet); } } else { super.sendTo(message, player); } }
@Override public IMessage onMessage(RandoresDataRequest message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().player; player.getServerWorld().addScheduledTask(() -> { RandoresNetworking.INSTANCE.sendTo(new RandoresClearDataCacheRequest().setDoClear(true), player); World world = player.world; RandoresWorldData data = RandoresWorldData.getSimply(world); if (data.getId().equals(message.getId())) { Kind kind = data.getKind(); RandoresNetworking.INSTANCE.sendTo(new RandoresBeginDataTransferRequest().setId(data.getId()), player); data.getPluginSeeds().forEach((plugin, seed) -> { RandoresNetworking.INSTANCE.sendTo(new RandoresUpdatePluginSeedRequest().setPlugin(plugin).setSeed(seed), player); }); if (kind == Kind.SEEDED) { RandoresNetworking.INSTANCE.sendTo(new RandoresDefineBySeedRequest().setSeed(data.getSeed()), player); } else if (kind == Kind.CUSTOM) { data.getCache().stream().map(def -> new RandoresDefineByDataRequest().setDefinition(def)).forEach(req -> RandoresNetworking.INSTANCE.sendTo(req, player)); } RandoresNetworking.INSTANCE.sendTo(new RandoresEndDataTransferRequest().setId(data.getId()), player); } }); return null; }
@Override public IMessage onMessage(CraftMessage message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; // Try crafting recipes first: List<IRecipe> matching_recipes = CraftingHelper.getRecipesForRequestedOutput(message.parameters); for (IRecipe recipe : matching_recipes) { if (CraftingHelper.attemptCrafting(player, recipe)) return null; } // Now try furnace recipes: ItemStack input = CraftingHelper.getSmeltingRecipeForRequestedOutput(message.parameters); if (input != null) { if (CraftingHelper.attemptSmelting(player, input)) return null; } return null; }
@Override @SideOnly(Side.CLIENT) public IMessage onMessage(CPacketUnlockResponse message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(() -> { if(Minecraft.getMinecraft().currentScreen != null) { if (Minecraft.getMinecraft().currentScreen instanceof PXLGui) { for (Control c : ((PXLGui) Minecraft.getMinecraft().currentScreen).gui.controls) { if (c instanceof GuiCodeStorageUnlock) { ((GuiCodeStorageUnlock) c).handleResponsePacket(message); } } } } }); return null; }
@Override public IMessage onMessage(TF2Message.InitClientMessage message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().player; ((WorldServer)player.world).addScheduledTask(() -> { WeaponsCapability.get(player).sentryTargets = message.sentryTargets; WeaponsCapability.get(player).dispenserPlayer = message.dispenserPlayer; WeaponsCapability.get(player).teleporterPlayer = message.teleporterPlayer; WeaponsCapability.get(player).teleporterEntity = message.teleporterEntity; }); // System.out.println("setting "+message.value); // TF2weapons.proxy.playReloadSound(player,stack); return null; }
@Override public IMessage onMessage(final GuiConfigMessage message, final MessageContext ctx) { TF2weapons.server.addScheduledTask(new Runnable() { @Override public void run() { Entity ent = ctx.getServerHandler().player.world.getEntityByID(message.entityid); if (ent != null && ent instanceof EntityBuilding && ((EntityBuilding) ent).getOwner() == ctx.getServerHandler().player) { if (message.id == 127) { ((EntityBuilding) ent).grab(); return; } if (ent instanceof EntityTeleporter) { if (message.id == 0) ((EntityTeleporter) ent).setID(MathHelper.clamp(message.value,0,EntityTeleporter.TP_PER_PLAYER-1)); else if (message.id == 1) ((EntityTeleporter) ent).setExit(message.value == 1); } else if (ent instanceof EntitySentry) if (message.id == 0) ((EntitySentry) ent).setTargetInfo(message.value); } } }); return null; }
@Override public IMessage onMessage(MessageFailLoadImage message, MessageContext ctx) { if (ctx.side == Side.CLIENT) { PictureFactory.fildToLoadPicture.put(message.imagename, message.type); if(PictureFactory.lodingPicture.contains(message.imagename)) { PictureFactory.lodingPicture.remove(message.imagename); } } return null; }
@Override public IMessage onMessage(MessagePlayerViewRender message, MessageContext ctx) { if (ctx.side == Side.SERVER) { if(ctx.getServerHandler().playerEntity!=null){ ctx.getServerHandler().playerEntity.getEntityData().removeTag("renderViewCamera"); } } return null; }
@Override public IMessage handleMessage (MessageContext context) { final EntityPlayer player = context.getServerHandler().player; final IStageData info = PlayerDataHandler.getStageData(player); MinecraftForge.EVENT_BUS.post(new StageDataEvent.SyncRequested(player, info)); GameStages.LOG.info("Syncing data for " + player.getName()); return new PacketStageAll(info.getUnlockedStages()); }
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side, boolean useUdp) { try { registerMessage(messageHandler.newInstance(), requestMessageType, discriminator, side, useUdp); } catch (Exception e) { } }
@Override public IMessage onMessage(MessagePictureBookInput message, MessageContext ctx) { if (ctx.side == Side.SERVER) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; if (player != null && player.openContainer != null && player.openContainer instanceof ContainerPictureBook) { ContainerPictureBook contaner = (ContainerPictureBook) player.openContainer; if (contaner.getSlot(0).getHasStack() && contaner.getSlot(0).getStack().hasTagCompound() && contaner.getSlot(0).getStack().getTagCompound().hasKey("pid")) { ItemStack itemStack = contaner.getSlot(0).getStack(); String pid = itemStack.getTagCompound().getString("pid"); if (contaner.getTotalPictureNum() <= 100) { contaner.getListPid().add(pid); contaner.setTotalPictureNum(contaner.getTotalPictureNum() + 1); if (contaner.getTotalPictureNum() == 1) { contaner.setIndex(0); } } else { player.addChatComponentMessage(new TextComponentTranslation("chat.picturebook.tomany")); return null; } } contaner.getSlot(0).decrStackSize(64); } } return null; }
@Override public IMessage onMessage(final MalmoMessage message, final MessageContext ctx) { final List<IMalmoMessageListener> interestedParties = listeners.get(message.messageType); if (interestedParties != null && interestedParties.size() > 0) { IThreadListener mainThread = null; if (ctx.side == Side.CLIENT) mainThread = Minecraft.getMinecraft(); else mainThread = MinecraftServer.getServer(); mainThread.addScheduledTask(new Runnable() { @Override public void run() { for (IMalmoMessageListener l : interestedParties) { // If the message's uid is set (ie non-zero), then use it to ensure that only the matching listener receives this message. // Otherwise, let all listeners who are interested get a look. if (message.uid == 0 || System.identityHashCode(l) == message.uid) l.onMessage(message.messageType, message.data); } } }); } return null; // no response in this case }
@Override public IMessage onMessage(final ShowGuiMessage message, MessageContext ctx) { if (message.id != 99) FMLNetworkHandler.openGui(ctx.getServerHandler().player, TF2weapons.instance, message.id, ctx.getServerHandler().player.world, 0, 0, 0); else { } return null; }
@Override public IMessage onMessage(PacketFriendermanRegistrySync message, MessageContext ctx) { FMLCommonHandler.instance().getWorldThread(ctx.netHandler).addScheduledTask(() -> { if (ctx.getClientHandler() != null) { ModRegistries.setTamedFriendermanRegistry(message.registry); } }); return null; }
public static void sendTracking(IMessage message,Entity entity){ if(entity instanceof EntityPlayerMP) TF2weapons.network.sendTo(message, (EntityPlayerMP) entity); for(EntityPlayer player:((WorldServer)entity.world).getEntityTracker().getTrackingPlayers(entity)){ TF2weapons.network.sendTo(message, (EntityPlayerMP) player); } }
@SideOnly(Side.CLIENT) @Override public IMessage onMessage(MessageExtraBlockBreak message, MessageContext ctx) { BlockPos[] positions = new BlockPos[message.numBlocks]; for (int i = 0; i < message.numBlocks; i++) { positions[i] = new BlockPos(message.positions[i][0], message.positions[i][1], message.positions[i][2]); } ExtraBlockBreakHandler.INSTANCE.sendBlockBreakProgress(message.entityID, positions, message.progress); return null; }
@Override public IMessage onMessage(final MessageUsingProbe message, MessageContext ctx) { final EntityPlayerMP player = ctx.getServerHandler().playerEntity; player.getServerWorld().addScheduledTask(new Runnable() { @Override public void run() { handle(player, message); } }); return null; }
@Override public IMessage onMessage(final MessageProcessorAction message, MessageContext ctx) { if (message.action == null) { return null; } final EntityPlayerMP payer = ctx.getServerHandler().player; payer.getServerWorld().addScheduledTask(new Worker(payer, message)); return null; }
@Override @Nullable public IMessage onMessage(final T message, final MessageContext context) { final IThreadListener thread = FMLCommonHandler.instance().getWorldThread(context.netHandler); if (thread.isCallingFromMinecraftThread()) { onMessageSynchronized(message, context); } else { thread.addScheduledTask(() -> onMessageSynchronized(message, context)); } return null; }
@Override public IMessage onMessage(TF2Message.InitMessage message, MessageContext ctx) { try { TF2UdpClient.instance = new TF2UdpClient(SocketUtils.socketAddress(TF2UdpClient.addressToUse, message.port)); TF2UdpClient.playerId = message.id; TF2weapons.network.useUdp = false; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // System.out.println("setting "+message.value); // TF2weapons.proxy.playReloadSound(player,stack); return null; }
@Override public IMessage handleClientMessage(EntityPlayer player, MessageSyncAccount message, MessageContext ctx) { if ((player != null) && (message != null) && (ctx != null)) { EntityLivingBase en = (EntityLivingBase) player.getEntityWorld().getEntityByID(message.entityId); if (en != null) { if (en.getEntityWorld() != null && en.hasCapability(Currency.ACCOUNT_DATA, null)) { AccountCapability entityData = en.getCapability(Currency.ACCOUNT_DATA, null); entityData.setAmount(message.amount, false); } } } return null; }
@Override public IMessage handleClientMessage(EntityPlayer player, MessageSyncPrice message, MessageContext ctx) { if ((player != null) && (message != null) && (ctx != null)) { if (player.getEntityWorld().getTileEntity(message.pos) instanceof TileEntityStockCrate) { TileEntityStockCrate crate = (TileEntityStockCrate) player.getEntityWorld().getTileEntity(message.pos); crate.setAmount(message.amount); } } return null; }
@Override public IMessage onMessage(ParticleMessage message, MessageContext ctx) { if (ctx.side == Side.CLIENT) { for (int i = 0; i < message.amount; i++) { Bewitchment.proxy.spawnParticle(message.particleF, message.x, message.y, message.z, message.xSpeed, message.ySpeed, message.zSpeed, message.args); } } return null; }
@Override @SideOnly(Side.CLIENT) public IMessage onMessage(MessageReceiveDamage message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(() -> { AbstractPlayerDamageModel damageModel = PlayerDataManager.getDamageModel(Minecraft.getMinecraft().player); Objects.requireNonNull(damageModel); AbstractDamageablePart part = damageModel.getFromEnum(message.part); part.damage(message.damageAmount, null, false, message.minHealth); }); return null; }
@Override public IMessage onMessage(final BulletMessage message, MessageContext ctx) { /* * final EntityPlayer shooter=ctx.getServerHandler().player; * ((WorldServer)shooter.world).addScheduledTask(new Runnable(){ * * @Override public void run() { ItemStack * stack=message.hand==EnumHand.MAIN_HAND?shooter.inventory. * getStackInSlot(message.slot):shooter.getHeldItemOffhand(); if(stack * == null || !(stack.getItem() instanceof ItemBulletWeapon)) return; * ItemBulletWeapon item=(ItemBulletWeapon) stack.getItem(); int * totalCrit=0; * if((!item.rapidFireCrits(stack)&&item.hasRandomCrits(stack,shooter) * && shooter.getRNG().nextFloat()<item.critChance(stack, * shooter))||stack.getTagCompound().getShort("crittime")>0){ * totalCrit=2; } for(Object[] obj:message.readData){ Entity * target=shooter.world.getEntityByID((Integer) obj[0]); * if(target==null) continue; * * if(!shotInfo.containsKey(target)||shotInfo.get(target)==null){ * shotInfo.put(target, new float[3]); } int critical=totalCrit; * //System.out.println(var4.hitInfo); if((Boolean)obj[1]){ critical=2; * } critical=item.setCritical(stack, shooter, target, critical); * if(critical>0){ totalCrit=critical; } * //ItemRangedWeapon.critical=critical; float[] * values=shotInfo.get(target); * //System.out.println(obj[2]+" "+critical); values[0]++; * values[1]+=TF2weapons.calculateDamage(target,shooter.world, * shooter, stack, critical, (Float) obj[2]); } * ItemBulletWeapon.handleShoot(shooter, stack, shooter.world, * shotInfo,totalCrit); ItemBulletWeapon.processShotServer=true; * ((ItemBulletWeapon)stack.getItem()).use(stack, shooter, * shooter.world, message.hand, message); * ItemBulletWeapon.processShotServer=false; shotInfo.clear(); } * * }); */ return null; }
@Override @SideOnly(Side.CLIENT) public IMessage onMessage(CPacketSpawnSipParticle msg, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(() -> ParticleEngine.addParticle(new ParticleSipMovingTo(msg.pos, msg.posTo, msg.sipType, msg.amount, msg.speed))); return null; }
@Override public IMessage onMessage(MessageRequestEntityAnimation message, MessageContext ctx) { Entity entity = ctx.getServerHandler().player.world.getEntityByID(message.entityID); if(ObsidianAPIUtil.isAnimatedEntity(entity)) { EntityAnimationProperties animationProps = EntityAnimationProperties.get(entity); if(animationProps != null) return new MessageAnimationStart(entity, animationProps.getActiveAnimation(), animationProps.getLoopAnim(), 0.0F); } return null; }