Thor597 Posted October 8, 2012 Posted October 8, 2012 I have a block which changes the time, but when I choose one of the options and on client it changes the time, on server. Either it doesnt do anything, or it gives me an NPE on the if() lines, code: public void actionPerformed(GuiButton guibutton) { if(guibutton.id == 1) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(7000); } } if(guibutton.id == 2) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(17000); } } if(guibutton.id == 3) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(0); } } if(guibutton.id == 4) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(13000); } } } Quote http://i.imgur.com/Hppni.png[/img]
SanAndreaP Posted October 8, 2012 Posted October 8, 2012 On 10/8/2012 at 6:15 PM, Thor597 said: I have a block which changes the time, but when I choose one of the options and on client it changes the time, on server. Either it doesnt do anything, or it gives me an NPE on the if() lines, code: public void actionPerformed(GuiButton guibutton) { if(guibutton.id == 1) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(7000); } } if(guibutton.id == 2) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(17000); } } if(guibutton.id == 3) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(0); } } if(guibutton.id == 4) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(13000); } } } Because the GUI classes are only called client-side. If you call MinecraftServer.getServer() in a client, it gives you only the InternalServer. If you are connected to a dedi server, it gives you a null object (unless you call this method on the dedi server). I would recommend to send packets for this one. Quote Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter Quote This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
Thor597 Posted October 8, 2012 Author Posted October 8, 2012 On 10/8/2012 at 7:21 PM, SanAndreasP said: Quote I have a block which changes the time, but when I choose one of the options and on client it changes the time, on server. Either it doesnt do anything, or it gives me an NPE on the if() lines, code: public void actionPerformed(GuiButton guibutton) { if(guibutton.id == 1) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(7000); } } if(guibutton.id == 2) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(17000); } } if(guibutton.id == 3) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(0); } } if(guibutton.id == 4) { for (int var3 = 0; var3 < MinecraftServer.getServer().theWorldServer.length; ++var3) { MinecraftServer.getServer().theWorldServer[var3].setTime(13000); } } } Because the GUI classes are only called client-side. If you call MinecraftServer.getServer() in a client, it gives you only the InternalServer. If you are connected to a dedi server, it gives you a null object (unless you call this method on the dedi server). I would recommend to send packets for this one. oh gawd packets Quote http://i.imgur.com/Hppni.png[/img]
Recommended Posts
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.