package net.minecraft.server;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.Collection;
import java.util.Iterator;
public class CommandDeop {
private static final SimpleCommandExceptionType a = new SimpleCommandExceptionType(new ChatMessage("commands.deop.failed", new Object[0]));
public static void a(com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> com_mojang_brigadier_commanddispatcher) {
com_mojang_brigadier_commanddispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) CommandDispatcher.a("deop").requires((commandlistenerwrapper) -> {
return commandlistenerwrapper.hasPermission(3);
})).then(CommandDispatcher.a("targets", (ArgumentType) ArgumentProfile.a()).suggests((commandcontext, suggestionsbuilder) -> {
return ICompletionProvider.a(((CommandListenerWrapper) commandcontext.getSource()).getServer().getPlayerList().m(), suggestionsbuilder);
}).executes((commandcontext) -> {
return a((CommandListenerWrapper) commandcontext.getSource(), ArgumentProfile.a(commandcontext, "targets"));
})));
}
private static int a(CommandListenerWrapper commandlistenerwrapper, Collection<GameProfile> collection) throws CommandSyntaxException {
PlayerList playerlist = commandlistenerwrapper.getServer().getPlayerList();
int i = 0;
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
GameProfile gameprofile = (GameProfile) iterator.next();
if (playerlist.isOp(gameprofile)) {
playerlist.removeOp(gameprofile);
++i;
commandlistenerwrapper.sendMessage(new ChatMessage("commands.deop.success", new Object[]{((GameProfile) collection.iterator().next()).getName()}), true);
}
}
if (i == 0) {
throw CommandDeop.a.create();
} else {
commandlistenerwrapper.getServer().a(commandlistenerwrapper);
return i;
}
}
}