I have made a plugin that resets my 'mine_world' but first it needs to teleport all players in 'mine_world' to 'world' Code:java if (cmd.getName().equalsIgnoreCase("mw-delete")) { for(Player online : Bukkit.getOnlinePlayers()) { online.teleport(online.getServer().getWorld("world").getSpawnLocation()); } this teleports everyone and that's going to get annoying fast for my players, how would i achieve the intended output?
Try this (in on phone so don't get the code box) Code:java Player[] players = Bukkit.getOnlinePlayers()for(int A = 0; A >= players.length;){ Player player = players[A]; if (player.getWorld().equals(worldToBeRemoved){ player.teleport(NewLocation); } A++;}
Code: if(cmd.getName().equalsIgnoreCase("mw-delete")) { for(Player p : Bukkit.getOnlinePlayers()) { if(p.getWorld().getName().equalsIgnoreCase("mine-world")) { p.teleport(loc); } else { return false; } } }
Pixelatorx2 this is what it says now Code:java Player p = (Player) sender; Location loc = (Bukkit.getServer().getWorld("world").getSpawnLocation()); if (cmd.getName().equalsIgnoreCase("mw-delete")) {// for(Player online : Bukkit.getOnlinePlayers()) {// online.teleport(online.getServer().getWorld("world").getSpawnLocation());// } for(Player o : Bukkit.getOnlinePlayers()) { if(o.getWorld().getName().equals("mine-world")) { o.teleport(loc); } else { return false; } } ignore the comments its just incase i need to go back to it This code just sends me /mw-delete in my game window but does nothing else
Kilovice problem is, it is not actually teleporting the players at all The delete process works if i use the commented out lines and teleports everyone successfully.
Pixelatorx2 name: CC-Essentials main: me.rebz.essentials.Main version: 1.0.1 commands: mw-delete: usage: /mw-delete permission: ccessentials.reset permission-message: You can't do that! mw-create: usage: /mw-create permission: ccessentials.reset permission-message: You can't do that! mn-delete: usage: /mn-delete permission: ccessentials.reset permission-message: You can't do that! mn-create: usage: /mn-create permission: ccessentials.reset permission-message: You can't do that! permissions: ccessentials.reset: default: op
Pixelatorx2 Done that and it didn't fix anything Like i said if i change back to the original code it was teleporting everyone i only want those in the world 'mine_world' to be teleported so i don't see how removing usage helps
Pixelatorx2 Lol. How was that meant to actually fix the problem? All that would do is ensure that there isn't a message to send. RebzO1 It doesn't help, you should put back in. For your information,the command's usage message is displayed whenever it hits a "return false" in your command - you should return true if the command was successful, which would prevent you being shown the usage message. In order to solve your problem, you should put in some debug statements to see what parts is executed. I'll give you a hint though, this is what your method currently does when somebody performs that command: Get the list of online players Check if the first person is in the mine_world world If they are, teleport them to the main spawn and repeat with the next online player If they're not in that world, command ended. Which I doubt is what you want. As soon as it finds someone who isn't in the mine_world world, it will stop looking, regardless of where everyone else is.
AdamQpzm He asked why there was a message, so I told him how to remove it. As to this, he is trying to get everyone in the world, ending the command there for one person wouldnt help at all frankly. and what do you think this is doing?
Pixelatorx2 But by removing the message, you're just hiding the real issue, not solving it. And that solution creates another problem - what if he wants a usage message? And that would be like solving an exception by catching it and making sure that it doesn't print the stacktrace... you've hidden the problem, not solved it. And I didn't say that's what he should do, I said that's what he's currently doing. teej107 As above, I was simply telling him what he was doing, not what he should be doing.
AdamQpzm I never have the usage parameter, yet I still get Stacktraces fine.. So I dont see how I was hiding the problem.
Pixelatorx2 I'm not saying not having a usage message will prevent stacktraces, I'm saying that these two situations essentially work on the same logic that you're advising, and both aren't really solutions: Problem: "My command's usage message is being displayed" Solution: "Remove the usage message, then it has nothing to display" Problem: "I'm getting an exception" Solution: "Catch the exception, and then don't print it out. The error will stop displaying." The usage isn't a "show this every time someone performs the command" it's a "show this when the command returns false". The real solution is to return true if the command is successful, not to remove the message.
RebzO1 The reason this code: doesnt work is because you are returning (stopping) the code from being executed at the wrong time. Code:java if (cmd.getName().equalsIgnoreCase("yourCommandHere"){for (Player p : Bukkit.getWorld("mine-world").getPlayers()){p.teleport(loc);}sender.sendMessage("Teleported all players in mine-world to world");return true;} Edit: For future reference, returning true or false or whatever stops executing that method. It is important to complete all relevant code before a return (if you need to return). Putting a if statement with a return in it will only return if the if was true. With the bukkit commandHandler you made, it was saying the usage of the command because you were returning false, which basically says "I didnt do anything useful with this command", which is useful if the arg you were coding was not one of the ones you coded (by returning false at the bottom of the commandHandler). Returning true means "Yes, I needed to do something with this command", and it wont send the usage (or error if there is no usage) to the player.
Plo124 I will try this in a few i need my coffeez just wanted to thank you for the reply! Plo124 with a lil modification it works now i can finally delete worlds without stopping the server ty for your help EDIT by Moderator: merged posts, please use the edit button instead of double posting.