Posted January 18, 20169 yr Hey guys, I have a problem with some strings after I send them from the Client to the server. I need to split the string and after I split it the formatting is different then it is server side. argh... long text short Question printf outputs me the following Strings: @Potato @Potato@ The first one is the output after I receive it with the server and Split it. The Problem is I need it to get a value out of a HashMap can anybody help me? And maybe explain me for what kind of formatting "@" stands for? Thanks in advance - JTK222
January 18, 20169 yr Show some code? Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 18, 20169 yr Author private int recipeID; private Block craftingStation; private int stationID; private String category; public PacketCraft(){} public PacketCraft(Block craftingStation,String Category, int recipeID){ this.recipeID = recipeID; this.stationID = Block.getIdFromBlock(craftingStation); this.category = Category; } @Override public void fromBytes(ByteBuf buf) { String[] temp = new String(Arrays.copyOfRange(buf.array(),1,buf.array().length)).split(";"); recipeID = Integer.parseInt(temp[0]); stationID = Integer.parseInt(temp[1]); category = temp[2]; } @Override public void toBytes(ByteBuf buf) { String temp = String.valueOf(recipeID) + ";" + String.valueOf(stationID) + ";" + category; buf.writeBytes(temp.getBytes()); } @Override public void handleClientSide(PacketCraft message, EntityPlayer player) {} @Override public void handleServerSide(PacketCraft message, EntityPlayer player) { CraftingManager.craftItem(message.stationID,message.category,message.recipeID,player); } Here it is. Haven't though that it might be important as I though its something more related to String in general
January 18, 20169 yr Ok, why the duck are you encoding the values into a string? Just write them all to the bytebuffer. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 18, 20169 yr Author Ok, why the duck are you encoding the values into a string? Just write them all to the bytebuffer. To say the truth I am not really understanding how the bytebuffer stuff is working my English isn't very good and that creates the problem that googling explanations isn't the easiest thing when you don't know which words to use. I have managed to write this Code after a few hours of google and maybe a few more hours of trial and error. How could I read the Inserted Variables separately? A Link to a good explaining tutorial would be a big help.
January 19, 20169 yr In toByes you write the two ints and the String you're sending to the ByteBuf and in fromBytes you read the two ints and the String from the ByteBuffer. @Override public void fromBytes(ByteBuf buf) { recipeID = buf.readInt(); stationID = buf.readInt(); category = ByteBufUtils.readUTF8String(buf); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(recipeID); buf.writeInt(stationID); ByteBufUtils.writeUTF8String(buf, category); } Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
January 19, 20169 yr Author Oh man its so easy and I had so much Trouble with it *facepalm* Big thx haven't known that this is existing: ByteBufUtils.writeUTF8String(buf, category); Makes a lot easier ^^ Big thanks - JTK222
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.