I want to program a command for my spigot server (e.g. / reset) that resets all worlds (normal, nether, end). Since I have not had such a long code, it is difficult for me to code such a command. The command should, so to speak, stop the server, delete the world folder and then run the server again (with the Start.bat file), so that a completely new world is generated with a new seed. I want to play challenges or do speed runs on the server and if you have to stop the server and delete the worlds by hand every time, it gets annoying after a while.
I code with Eclipse and I hope that someone can help me here.
Moin, I'm not programming that long, but you could either check if there's a Mutliverse API (if you use MV) or else you just delete the worlds and create new ones by dispatching the command via the console.
You can stop your server like this:
Bukkit.getServer (). Shutdown ();
And to reset the worlds you can do that:
Bukkit.dispatchCommand ((CommandSender) Bukkit.getConsoleSender (), "mv delete world");
Then wait a second, this can be done with a scheduler and then do the following:
Bukkit.dispatchCommand ((CommandSender) Bukkit.getConsoleSender (), "mv confirm");
This is how it should work, if not you can just answer.
After the server has been stopped, however, as far as I know, you can't restart it, because the plugin is then deactivated.
Thank you for the fast answer! Unfortunately, I haven't had much time in the last few days, which is why I will continue programming right away. Are the two commands below only compatible with MV-Core or would that work?
Had programmed the following this afternoon:
package de.m4trixxlp.m4utils.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ResetCommand implements CommandExecutor {
@Override
public boolean onCommand (CommandSender sender, Command command, String label, String [] args) {
if (sender instanceof Player) {
Player player = (player) transmitter;
if (player.hasPermission ("m4utils.reset")) {
if (args.length == 0) {
player.sendMessage ("§cThe server is being reset.");
Bukkit.getServer (). Shutdown ();
}
} else
player.sendMessage ("§cYou have no rights to do this!");
} return false;
}
}
The server is stopped, everything is working. What can I now program so that the world folder is deleted and the start.bat file is executed automatically?
Yes, the method is only compatible with MV. If you manage your worlds with another plugin, you simply have to insert the command of the respective plugin when dispatching.
After the server has been stopped, however, as far as I know, you can't restart it, because the plugin is then deactivated.
However, you could also create a world via dispatch and then teleport the player there. A cooldown would have to lie between creating and teleporting, because the world has to be generated first.
Now I did MV and coded the command with the scheduler, but when I run / reset in game, only the / mv delete (world name) is output from the plugin, but not after the scheduler the / mvconfirm. Did I do something wrong with the scheduler? D: Hope you can help me.
Here is my code: .html
You have to add that the int is decreased by 1 every second.
Now this int is defined as 1, so it can't come to 0 at all.
Found the error, had to enter countdown - after the scheduler and now it works.
Hay,
have now tried to put everything into the scheduler in one go but it doesn't seem to work properly because only the teleport to the lobby takes place. After that, this message is always executed every second in the console:
[13:54:50] [Server thread / INFO]: This command has already been run! Please type the original command again if you want to rerun it.
Could you possibly tell me what I did wrong again?
Here is my new code: .html
I do not understand why you run 8 mvconfirm? You don't need this if you teleport a player.
Okay try it if it doesn't work, what can it be?
It does not work without since mv does not accept the tp without confirm because there's also "no safe location found" in the chat