mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 16:57:42 +01:00
[Bleeding] Add 1.7 setworldspawn and setidletimeout commands. Addresses BUKKIT-4932
By: t00thpick1 <t00thpick1dirko@gmail.com>
This commit is contained in:
parent
038c99a7f4
commit
c0e5d3fbf0
@ -666,7 +666,7 @@ public final class Bukkit {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#loadServerIcon(File)()
|
||||
* @see Server#loadServerIcon(File)
|
||||
*/
|
||||
public static CachedServerIcon loadServerIcon(File file) throws Exception {
|
||||
return server.loadServerIcon(file);
|
||||
@ -678,4 +678,18 @@ public final class Bukkit {
|
||||
public static CachedServerIcon loadServerIcon(BufferedImage image) throws Exception {
|
||||
return server.loadServerIcon(image);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#setIdleTimeout(int)
|
||||
*/
|
||||
public static void setIdleTimeout(int threshold) {
|
||||
server.setIdleTimeout(threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#getIdleTimeout()
|
||||
*/
|
||||
public static int getIdleTimeout() {
|
||||
return server.getIdleTimeout();
|
||||
}
|
||||
}
|
||||
|
@ -782,4 +782,21 @@ public interface Server extends PluginMessageRecipient {
|
||||
* ServerListPingEvent#setServerIcon(CachedServerIcon)}
|
||||
*/
|
||||
CachedServerIcon loadServerIcon(BufferedImage image) throws IllegalArgumentException, Exception;
|
||||
|
||||
/**
|
||||
* Set the idle kick timeout. Any players idle for the specified amount of
|
||||
* time will be automatically kicked.
|
||||
* <p>
|
||||
* A value of 0 will disable the idle kick timeout.
|
||||
*
|
||||
* @param threshold the idle timeout in minutes
|
||||
*/
|
||||
public void setIdleTimeout(int threshold);
|
||||
|
||||
/**
|
||||
* Gets the idle kick timeout.
|
||||
*
|
||||
* @return the idle timeout in minutes
|
||||
*/
|
||||
public int getIdleTimeout();
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ public class SimpleCommandMap implements CommandMap {
|
||||
fallbackCommands.add(new ScoreboardCommand());
|
||||
fallbackCommands.add(new PlaySoundCommand());
|
||||
fallbackCommands.add(new SpreadPlayersCommand());
|
||||
fallbackCommands.add(new SetWorldSpawnCommand());
|
||||
fallbackCommands.add(new SetIdleTimeoutCommand());
|
||||
}
|
||||
|
||||
public SimpleCommandMap(final Server server) {
|
||||
|
@ -0,0 +1,53 @@
|
||||
package org.bukkit.command.defaults;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SetIdleTimeoutCommand extends VanillaCommand {
|
||||
|
||||
public SetIdleTimeoutCommand() {
|
||||
super("setidletimeout");
|
||||
this.description = "Sets the server's idle timeout";
|
||||
this.usageMessage = "/setidletimeout <Minutes until kick>";
|
||||
this.setPermission("bukkit.command.setidletimeout");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (!testPermission(sender)) return true;
|
||||
|
||||
if (args.length == 1) {
|
||||
int minutes;
|
||||
|
||||
try {
|
||||
minutes = getInteger(sender, args[0], 0, Integer.MAX_VALUE, true);
|
||||
} catch (NumberFormatException ex) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
Bukkit.getServer().setIdleTimeout(minutes);
|
||||
|
||||
Command.broadcastCommandMessage(sender, "Successfully set the idle timeout to " + minutes + " minutes.");
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
|
||||
Validate.notNull(sender, "Sender cannot be null");
|
||||
Validate.notNull(args, "Arguments cannot be null");
|
||||
Validate.notNull(alias, "Alias cannot be null");
|
||||
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package org.bukkit.command.defaults;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SetWorldSpawnCommand extends VanillaCommand {
|
||||
|
||||
public SetWorldSpawnCommand() {
|
||||
super("setworldspawn");
|
||||
this.description = "Sets a worlds's spawn point. If no coordinates are specified, the player's coordinates will be used.";
|
||||
this.usageMessage = "/setworldspawn OR /setworldspawn <x> <y> <z>";
|
||||
this.setPermission("bukkit.command.setworldspawn");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (!testPermission(sender)) return true;
|
||||
|
||||
Player player = null;
|
||||
World world;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
world = player.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
}
|
||||
|
||||
final int x, y, z;
|
||||
|
||||
if (args.length == 0) {
|
||||
if (player == null) {
|
||||
sender.sendMessage("You can only perform this command as a player");
|
||||
return true;
|
||||
}
|
||||
|
||||
Location location = player.getLocation();
|
||||
|
||||
x = location.getBlockX();
|
||||
y = location.getBlockY();
|
||||
z = location.getBlockZ();
|
||||
} else if (args.length == 3) {
|
||||
try {
|
||||
x = getInteger(sender, args[0], MIN_COORD, MAX_COORD, true);
|
||||
y = getInteger(sender, args[1], 0, world.getMaxHeight(), true);
|
||||
z = getInteger(sender, args[2], MIN_COORD, MAX_COORD, true);
|
||||
} catch (NumberFormatException ex) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
world.setSpawnLocation(x, y, z);
|
||||
|
||||
Command.broadcastCommandMessage(sender, "Set world " + world.getName() + "'s spawnpoint to (" + x + ", " + y + ", " + z + ")");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
|
||||
Validate.notNull(sender, "Sender cannot be null");
|
||||
Validate.notNull(args, "Arguments cannot be null");
|
||||
Validate.notNull(alias, "Alias cannot be null");
|
||||
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user