
net.minecraft.server.CommandBan Maven / Gradle / Ivy
package net.minecraft.server;
import com.mojang.authlib.GameProfile;
import java.util.List;
public class CommandBan extends CommandAbstract {
public CommandBan() {
}
public String getCommand() {
return "ban";
}
public int a() {
return 3;
}
public String getUsage(ICommandListener icommandlistener) {
return "commands.ban.usage";
}
public boolean canUse(ICommandListener icommandlistener) {
return MinecraftServer.getServer().getPlayerList().getProfileBans().isEnabled() && super.canUse(icommandlistener);
}
public void execute(ICommandListener icommandlistener, String[] astring) throws CommandException {
if (astring.length >= 1 && astring[0].length() > 0) {
MinecraftServer minecraftserver = MinecraftServer.getServer();
GameProfile gameprofile = minecraftserver.getUserCache().getProfile(astring[0]);
if (gameprofile == null) {
throw new CommandException("commands.ban.failed", astring[0]);
} else {
String s = null;
if (astring.length >= 2) {
s = a(icommandlistener, astring, 1).c();
}
GameProfileBanEntry gameprofilebanentry = new GameProfileBanEntry(gameprofile, null, icommandlistener.getName(), null, s);
minecraftserver.getPlayerList().getProfileBans().add(gameprofilebanentry);
EntityPlayer entityplayer = minecraftserver.getPlayerList().getPlayer(astring[0]);
if (entityplayer != null) {
entityplayer.playerConnection.disconnect("You are banned from this server.");
}
a(icommandlistener, this, "commands.ban.success", astring[0]);
}
} else {
throw new ExceptionUsage("commands.ban.usage");
}
}
public List tabComplete(ICommandListener icommandlistener, String[] astring, BlockPosition blockposition) {
return astring.length >= 1 ? a(astring, MinecraftServer.getServer().getPlayers()) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy