All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minecraft.server.CommandScoreboard Maven / Gradle / Ivy

package net.minecraft.server;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.*;

public class CommandScoreboard extends CommandAbstract {
	
	public CommandScoreboard() {
	}
	
	public String getCommand() {
		return "scoreboard";
	}
	
	public int a() {
		return 2;
	}
	
	public String getUsage(ICommandListener icommandlistener) {
		return "commands.scoreboard.usage";
	}
	
	public void execute(ICommandListener icommandlistener, String[] astring) throws CommandException {
		if (!this.b(icommandlistener, astring)) {
			if (astring.length < 1) {
				throw new ExceptionUsage("commands.scoreboard.usage");
			} else {
				if (astring[0].equalsIgnoreCase("objectives")) {
					if (astring.length == 1) {
						throw new ExceptionUsage("commands.scoreboard.objectives.usage");
					}
					
					if (astring[1].equalsIgnoreCase("list")) {
						this.d(icommandlistener);
					} else if (astring[1].equalsIgnoreCase("add")) {
						if (astring.length < 4) {
							throw new ExceptionUsage("commands.scoreboard.objectives.add.usage");
						}
						
						this.b(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("remove")) {
						if (astring.length != 3) {
							throw new ExceptionUsage("commands.scoreboard.objectives.remove.usage");
						}
						
						this.h(icommandlistener, astring[2]);
					} else {
						if (!astring[1].equalsIgnoreCase("setdisplay")) {
							throw new ExceptionUsage("commands.scoreboard.objectives.usage");
						}
						
						if (astring.length != 3 && astring.length != 4) {
							throw new ExceptionUsage("commands.scoreboard.objectives.setdisplay.usage");
						}
						
						this.j(icommandlistener, astring, 2);
					}
				} else if (astring[0].equalsIgnoreCase("players")) {
					if (astring.length == 1) {
						throw new ExceptionUsage("commands.scoreboard.players.usage");
					}
					
					if (astring[1].equalsIgnoreCase("list")) {
						if (astring.length > 3) {
							throw new ExceptionUsage("commands.scoreboard.players.list.usage");
						}
						
						this.k(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("add")) {
						if (astring.length < 5) {
							throw new ExceptionUsage("commands.scoreboard.players.add.usage");
						}
						
						this.l(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("remove")) {
						if (astring.length < 5) {
							throw new ExceptionUsage("commands.scoreboard.players.remove.usage");
						}
						
						this.l(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("set")) {
						if (astring.length < 5) {
							throw new ExceptionUsage("commands.scoreboard.players.set.usage");
						}
						
						this.l(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("reset")) {
						if (astring.length != 3 && astring.length != 4) {
							throw new ExceptionUsage("commands.scoreboard.players.reset.usage");
						}
						
						this.m(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("enable")) {
						if (astring.length != 4) {
							throw new ExceptionUsage("commands.scoreboard.players.enable.usage");
						}
						
						this.n(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("test")) {
						if (astring.length != 5 && astring.length != 6) {
							throw new ExceptionUsage("commands.scoreboard.players.test.usage");
						}
						
						this.o(icommandlistener, astring, 2);
					} else {
						if (!astring[1].equalsIgnoreCase("operation")) {
							throw new ExceptionUsage("commands.scoreboard.players.usage");
						}
						
						if (astring.length != 7) {
							throw new ExceptionUsage("commands.scoreboard.players.operation.usage");
						}
						
						this.p(icommandlistener, astring, 2);
					}
				} else {
					if (!astring[0].equalsIgnoreCase("teams")) {
						throw new ExceptionUsage("commands.scoreboard.usage");
					}
					
					if (astring.length == 1) {
						throw new ExceptionUsage("commands.scoreboard.teams.usage");
					}
					
					if (astring[1].equalsIgnoreCase("list")) {
						if (astring.length > 3) {
							throw new ExceptionUsage("commands.scoreboard.teams.list.usage");
						}
						
						this.f(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("add")) {
						if (astring.length < 3) {
							throw new ExceptionUsage("commands.scoreboard.teams.add.usage");
						}
						
						this.c(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("remove")) {
						if (astring.length != 3) {
							throw new ExceptionUsage("commands.scoreboard.teams.remove.usage");
						}
						
						this.e(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("empty")) {
						if (astring.length != 3) {
							throw new ExceptionUsage("commands.scoreboard.teams.empty.usage");
						}
						
						this.i(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("join")) {
						if (astring.length < 4 && (astring.length != 3 || !(icommandlistener instanceof EntityHuman))) {
							throw new ExceptionUsage("commands.scoreboard.teams.join.usage");
						}
						
						this.g(icommandlistener, astring, 2);
					} else if (astring[1].equalsIgnoreCase("leave")) {
						if (astring.length < 3 && !(icommandlistener instanceof EntityHuman)) {
							throw new ExceptionUsage("commands.scoreboard.teams.leave.usage");
						}
						
						this.h(icommandlistener, astring, 2);
					} else {
						if (!astring[1].equalsIgnoreCase("option")) {
							throw new ExceptionUsage("commands.scoreboard.teams.usage");
						}
						
						if (astring.length != 4 && astring.length != 5) {
							throw new ExceptionUsage("commands.scoreboard.teams.option.usage");
						}
						
						this.d(icommandlistener, astring, 2);
					}
				}
				
			}
		}
	}
	
	private boolean b(ICommandListener icommandlistener, String[] astring) throws CommandException {
		int i = -1;
		
		for (int j = 0; j < astring.length; ++j) {
			if (this.isListStart(astring, j) && "*".equals(astring[j])) {
				if (i >= 0) {
					throw new CommandException("commands.scoreboard.noMultiWildcard");
				}
				
				i = j;
			}
		}
		
		if (i < 0) {
			return false;
		} else {
			ArrayList arraylist = Lists.newArrayList(this.d().getPlayers());
			String s = astring[i];
			ArrayList arraylist1 = Lists.newArrayList();
			Iterator iterator = arraylist.iterator();
			
			while (iterator.hasNext()) {
				String s1 = (String) iterator.next();
				
				astring[i] = s1;
				
				try {
					this.execute(icommandlistener, astring);
					arraylist1.add(s1);
				} catch (CommandException commandexception) {
					ChatMessage chatmessage = new ChatMessage(commandexception.getMessage(), commandexception.getArgs());
					
					chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
					icommandlistener.sendMessage(chatmessage);
				}
			}
			
			astring[i] = s;
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.AFFECTED_ENTITIES, arraylist1.size());
			if (arraylist1.size() == 0) {
				throw new ExceptionUsage("commands.scoreboard.allMatchesFailed");
			} else {
				return true;
			}
		}
	}
	
	protected Scoreboard d() {
		return MinecraftServer.getServer().getWorldServer(0).getScoreboard();
	}
	
	protected ScoreboardObjective a(String s, boolean flag) throws CommandException {
		Scoreboard scoreboard = this.d();
		ScoreboardObjective scoreboardobjective = scoreboard.getObjective(s);
		
		if (scoreboardobjective == null) {
			throw new CommandException("commands.scoreboard.objectiveNotFound", s);
		} else if (flag && scoreboardobjective.getCriteria().isReadOnly()) {
			throw new CommandException("commands.scoreboard.objectiveReadOnly", s);
		} else {
			return scoreboardobjective;
		}
	}
	
	protected ScoreboardTeam e(String s) throws CommandException {
		Scoreboard scoreboard = this.d();
		ScoreboardTeam scoreboardteam = scoreboard.getTeam(s);
		
		if (scoreboardteam == null) {
			throw new CommandException("commands.scoreboard.teamNotFound", s);
		} else {
			return scoreboardteam;
		}
	}
	
	protected void b(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		String s = astring[i++];
		String s1 = astring[i++];
		Scoreboard scoreboard = this.d();
		IScoreboardCriteria iscoreboardcriteria = IScoreboardCriteria.criteria.get(s1);
		
		if (iscoreboardcriteria == null) {
			throw new ExceptionUsage("commands.scoreboard.objectives.add.wrongType", s1);
		} else if (scoreboard.getObjective(s) != null) {
			throw new CommandException("commands.scoreboard.objectives.add.alreadyExists", s);
		} else if (s.length() > 16) {
			throw new ExceptionInvalidSyntax("commands.scoreboard.objectives.add.tooLong", s, Integer.valueOf(16));
		} else if (s.length() == 0) {
			throw new ExceptionUsage("commands.scoreboard.objectives.add.usage");
		} else {
			if (astring.length > i) {
				String s2 = a(icommandlistener, astring, i).c();
				
				if (s2.length() > 32) {
					throw new ExceptionInvalidSyntax("commands.scoreboard.objectives.add.displayTooLong", s2, Integer.valueOf(32));
				}
				
				if (s2.length() > 0) {
					scoreboard.registerObjective(s, iscoreboardcriteria).setDisplayName(s2);
				} else {
					scoreboard.registerObjective(s, iscoreboardcriteria);
				}
			} else {
				scoreboard.registerObjective(s, iscoreboardcriteria);
			}
			
			a(icommandlistener, this, "commands.scoreboard.objectives.add.success", s);
		}
	}
	
	protected void c(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		String s = astring[i++];
		Scoreboard scoreboard = this.d();
		
		if (scoreboard.getTeam(s) != null) {
			throw new CommandException("commands.scoreboard.teams.add.alreadyExists", s);
		} else if (s.length() > 16) {
			throw new ExceptionInvalidSyntax("commands.scoreboard.teams.add.tooLong", s, Integer.valueOf(16));
		} else if (s.length() == 0) {
			throw new ExceptionUsage("commands.scoreboard.teams.add.usage");
		} else {
			if (astring.length > i) {
				String s1 = a(icommandlistener, astring, i).c();
				
				if (s1.length() > 32) {
					throw new ExceptionInvalidSyntax("commands.scoreboard.teams.add.displayTooLong", s1, Integer.valueOf(32));
				}
				
				if (s1.length() > 0) {
					scoreboard.createTeam(s).setDisplayName(s1);
				} else {
					scoreboard.createTeam(s);
				}
			} else {
				scoreboard.createTeam(s);
			}
			
			a(icommandlistener, this, "commands.scoreboard.teams.add.success", s);
		}
	}
	
	protected void d(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		ScoreboardTeam scoreboardteam = this.e(astring[i++]);
		
		if (scoreboardteam != null) {
			String s = astring[i++].toLowerCase();
			
			if (!s.equalsIgnoreCase("color") && !s.equalsIgnoreCase("friendlyfire") && !s.equalsIgnoreCase("seeFriendlyInvisibles") && !s.equalsIgnoreCase("nametagVisibility") && !s.equalsIgnoreCase("deathMessageVisibility")) {
				throw new ExceptionUsage("commands.scoreboard.teams.option.usage");
			} else if (astring.length == 4) {
				if (s.equalsIgnoreCase("color")) {
					throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(EnumChatFormat.a(true, false)));
				} else if (!s.equalsIgnoreCase("friendlyfire") && !s.equalsIgnoreCase("seeFriendlyInvisibles")) {
					if (!s.equalsIgnoreCase("nametagVisibility") && !s.equalsIgnoreCase("deathMessageVisibility")) {
						throw new ExceptionUsage("commands.scoreboard.teams.option.usage");
					} else {
						throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(ScoreboardTeamBase.EnumNameTagVisibility.a()));
					}
				} else {
					throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(Arrays.asList(new String[]{"true", "false"})));
				}
			} else {
				String s1 = astring[i];
				
				if (s.equalsIgnoreCase("color")) {
					EnumChatFormat enumchatformat = EnumChatFormat.b(s1);
					
					if (enumchatformat == null || enumchatformat.isFormat()) {
						throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(EnumChatFormat.a(true, false)));
					}
					
					scoreboardteam.a(enumchatformat);
					scoreboardteam.setPrefix(enumchatformat.toString());
					scoreboardteam.setSuffix(EnumChatFormat.RESET.toString());
				} else if (s.equalsIgnoreCase("friendlyfire")) {
					if (!s1.equalsIgnoreCase("true") && !s1.equalsIgnoreCase("false")) {
						throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(Arrays.asList(new String[]{"true", "false"})));
					}
					
					scoreboardteam.setAllowFriendlyFire(s1.equalsIgnoreCase("true"));
				} else if (s.equalsIgnoreCase("seeFriendlyInvisibles")) {
					if (!s1.equalsIgnoreCase("true") && !s1.equalsIgnoreCase("false")) {
						throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(Arrays.asList(new String[]{"true", "false"})));
					}
					
					scoreboardteam.setCanSeeFriendlyInvisibles(s1.equalsIgnoreCase("true"));
				} else {
					ScoreboardTeamBase.EnumNameTagVisibility scoreboardteambase_enumnametagvisibility;
					
					if (s.equalsIgnoreCase("nametagVisibility")) {
						scoreboardteambase_enumnametagvisibility = ScoreboardTeamBase.EnumNameTagVisibility.a(s1);
						if (scoreboardteambase_enumnametagvisibility == null) {
							throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(ScoreboardTeamBase.EnumNameTagVisibility.a()));
						}
						
						scoreboardteam.setNameTagVisibility(scoreboardteambase_enumnametagvisibility);
					} else if (s.equalsIgnoreCase("deathMessageVisibility")) {
						scoreboardteambase_enumnametagvisibility = ScoreboardTeamBase.EnumNameTagVisibility.a(s1);
						if (scoreboardteambase_enumnametagvisibility == null) {
							throw new ExceptionUsage("commands.scoreboard.teams.option.noValue", s, a(ScoreboardTeamBase.EnumNameTagVisibility.a()));
						}
						
						scoreboardteam.b(scoreboardteambase_enumnametagvisibility);
					}
				}
				
				a(icommandlistener, this, "commands.scoreboard.teams.option.success", s, scoreboardteam.getName(), s1);
			}
		}
	}
	
	protected void e(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		ScoreboardTeam scoreboardteam = this.e(astring[i]);
		
		if (scoreboardteam != null) {
			scoreboard.removeTeam(scoreboardteam);
			a(icommandlistener, this, "commands.scoreboard.teams.remove.success", scoreboardteam.getName());
		}
	}
	
	protected void f(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		
		if (astring.length > i) {
			ScoreboardTeam scoreboardteam = this.e(astring[i]);
			
			if (scoreboardteam == null) {
				return;
			}
			
			Collection collection = scoreboardteam.getPlayerNameSet();
			
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.QUERY_RESULT, collection.size());
			if (collection.size() <= 0) {
				throw new CommandException("commands.scoreboard.teams.list.player.empty", scoreboardteam.getName());
			}
			
			ChatMessage chatmessage = new ChatMessage("commands.scoreboard.teams.list.player.count", Integer.valueOf(collection.size()), scoreboardteam.getName());
			
			chatmessage.getChatModifier().setColor(EnumChatFormat.DARK_GREEN);
			icommandlistener.sendMessage(chatmessage);
			icommandlistener.sendMessage(new ChatComponentText(a(collection.toArray())));
		} else {
			Collection collection1 = scoreboard.getTeams();
			
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.QUERY_RESULT, collection1.size());
			if (collection1.size() <= 0) {
				throw new CommandException("commands.scoreboard.teams.list.empty");
			}
			
			ChatMessage chatmessage1 = new ChatMessage("commands.scoreboard.teams.list.count", Integer.valueOf(collection1.size()));
			
			chatmessage1.getChatModifier().setColor(EnumChatFormat.DARK_GREEN);
			icommandlistener.sendMessage(chatmessage1);
			Iterator iterator = collection1.iterator();
			
			while (iterator.hasNext()) {
				ScoreboardTeam scoreboardteam1 = (ScoreboardTeam) iterator.next();
				
				icommandlistener.sendMessage(new ChatMessage("commands.scoreboard.teams.list.entry", scoreboardteam1.getName(), scoreboardteam1.getDisplayName(), Integer.valueOf(scoreboardteam1.getPlayerNameSet().size())));
			}
		}
		
	}
	
	protected void g(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		String s = astring[i++];
		HashSet hashset = Sets.newHashSet();
		HashSet hashset1 = Sets.newHashSet();
		String s1;
		
		if (icommandlistener instanceof EntityHuman && i == astring.length) {
			s1 = b(icommandlistener).getName();
			if (scoreboard.addPlayerToTeam(s1, s)) {
				hashset.add(s1);
			} else {
				hashset1.add(s1);
			}
		} else {
			while (i < astring.length) {
				s1 = astring[i++];
				if (s1.startsWith("@")) {
					List list = c(icommandlistener, s1);
					Iterator iterator = list.iterator();
					
					while (iterator.hasNext()) {
						Entity entity = (Entity) iterator.next();
						String s2 = e(icommandlistener, entity.getUniqueID().toString());
						
						if (scoreboard.addPlayerToTeam(s2, s)) {
							hashset.add(s2);
						} else {
							hashset1.add(s2);
						}
					}
				} else {
					String s3 = e(icommandlistener, s1);
					
					if (scoreboard.addPlayerToTeam(s3, s)) {
						hashset.add(s3);
					} else {
						hashset1.add(s3);
					}
				}
			}
		}
		
		if (!hashset.isEmpty()) {
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.AFFECTED_ENTITIES, hashset.size());
			a(icommandlistener, this, "commands.scoreboard.teams.join.success", Integer.valueOf(hashset.size()), s, a(hashset.toArray(new String[hashset.size()])));
		}
		
		if (!hashset1.isEmpty()) {
			throw new CommandException("commands.scoreboard.teams.join.failure", Integer.valueOf(hashset1.size()), s, a(hashset1.toArray(new String[hashset1.size()])));
		}
	}
	
	protected void h(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		HashSet hashset = Sets.newHashSet();
		HashSet hashset1 = Sets.newHashSet();
		String s;
		
		if (icommandlistener instanceof EntityHuman && i == astring.length) {
			s = b(icommandlistener).getName();
			if (scoreboard.removePlayerFromTeam(s)) {
				hashset.add(s);
			} else {
				hashset1.add(s);
			}
		} else {
			while (i < astring.length) {
				s = astring[i++];
				if (s.startsWith("@")) {
					List list = c(icommandlistener, s);
					Iterator iterator = list.iterator();
					
					while (iterator.hasNext()) {
						Entity entity = (Entity) iterator.next();
						String s1 = e(icommandlistener, entity.getUniqueID().toString());
						
						if (scoreboard.removePlayerFromTeam(s1)) {
							hashset.add(s1);
						} else {
							hashset1.add(s1);
						}
					}
				} else {
					String s2 = e(icommandlistener, s);
					
					if (scoreboard.removePlayerFromTeam(s2)) {
						hashset.add(s2);
					} else {
						hashset1.add(s2);
					}
				}
			}
		}
		
		if (!hashset.isEmpty()) {
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.AFFECTED_ENTITIES, hashset.size());
			a(icommandlistener, this, "commands.scoreboard.teams.leave.success", Integer.valueOf(hashset.size()), a(hashset.toArray(new String[hashset.size()])));
		}
		
		if (!hashset1.isEmpty()) {
			throw new CommandException("commands.scoreboard.teams.leave.failure", Integer.valueOf(hashset1.size()), a(hashset1.toArray(new String[hashset1.size()])));
		}
	}
	
	protected void i(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		ScoreboardTeam scoreboardteam = this.e(astring[i]);
		
		if (scoreboardteam != null) {
			ArrayList arraylist = Lists.newArrayList(scoreboardteam.getPlayerNameSet());
			
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.AFFECTED_ENTITIES, arraylist.size());
			if (arraylist.isEmpty()) {
				throw new CommandException("commands.scoreboard.teams.empty.alreadyEmpty", scoreboardteam.getName());
			} else {
				Iterator iterator = arraylist.iterator();
				
				while (iterator.hasNext()) {
					String s = (String) iterator.next();
					
					scoreboard.removePlayerFromTeam(s, scoreboardteam);
				}
				
				a(icommandlistener, this, "commands.scoreboard.teams.empty.success", Integer.valueOf(arraylist.size()), scoreboardteam.getName());
			}
		}
	}
	
	protected void h(ICommandListener icommandlistener, String s) throws CommandException {
		Scoreboard scoreboard = this.d();
		ScoreboardObjective scoreboardobjective = this.a(s, false);
		
		scoreboard.unregisterObjective(scoreboardobjective);
		a(icommandlistener, this, "commands.scoreboard.objectives.remove.success", s);
	}
	
	protected void d(ICommandListener icommandlistener) throws CommandException {
		Scoreboard scoreboard = this.d();
		Collection collection = scoreboard.getObjectives();
		
		if (collection.size() <= 0) {
			throw new CommandException("commands.scoreboard.objectives.list.empty");
		} else {
			ChatMessage chatmessage = new ChatMessage("commands.scoreboard.objectives.list.count", Integer.valueOf(collection.size()));
			
			chatmessage.getChatModifier().setColor(EnumChatFormat.DARK_GREEN);
			icommandlistener.sendMessage(chatmessage);
			Iterator iterator = collection.iterator();
			
			while (iterator.hasNext()) {
				ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next();
				
				icommandlistener.sendMessage(new ChatMessage("commands.scoreboard.objectives.list.entry", scoreboardobjective.getName(), scoreboardobjective.getDisplayName(), scoreboardobjective.getCriteria().getName()));
			}
			
		}
	}
	
	protected void j(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		String s = astring[i++];
		int j = Scoreboard.getSlotForName(s);
		ScoreboardObjective scoreboardobjective = null;
		
		if (astring.length == 4) {
			scoreboardobjective = this.a(astring[i], false);
		}
		
		if (j < 0) {
			throw new CommandException("commands.scoreboard.objectives.setdisplay.invalidSlot", s);
		} else {
			scoreboard.setDisplaySlot(j, scoreboardobjective);
			if (scoreboardobjective != null) {
				a(icommandlistener, this, "commands.scoreboard.objectives.setdisplay.successSet", Scoreboard.getSlotName(j), scoreboardobjective.getName());
			} else {
				a(icommandlistener, this, "commands.scoreboard.objectives.setdisplay.successCleared", Scoreboard.getSlotName(j));
			}
			
		}
	}
	
	protected void k(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		
		if (astring.length > i) {
			String s = e(icommandlistener, astring[i]);
			Map map = scoreboard.getPlayerObjectives(s);
			
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.QUERY_RESULT, map.size());
			if (map.size() <= 0) {
				throw new CommandException("commands.scoreboard.players.list.player.empty", s);
			}
			
			ChatMessage chatmessage = new ChatMessage("commands.scoreboard.players.list.player.count", Integer.valueOf(map.size()), s);
			
			chatmessage.getChatModifier().setColor(EnumChatFormat.DARK_GREEN);
			icommandlistener.sendMessage(chatmessage);
			Iterator iterator = map.values().iterator();
			
			while (iterator.hasNext()) {
				ScoreboardScore scoreboardscore = (ScoreboardScore) iterator.next();
				
				icommandlistener.sendMessage(new ChatMessage("commands.scoreboard.players.list.player.entry", Integer.valueOf(scoreboardscore.getScore()), scoreboardscore.getObjective().getDisplayName(), scoreboardscore.getObjective().getName()));
			}
		} else {
			Collection collection = scoreboard.getPlayers();
			
			icommandlistener.setCommandStat(CommandObjectiveExecutor.EnumCommandResult.QUERY_RESULT, collection.size());
			if (collection.size() <= 0) {
				throw new CommandException("commands.scoreboard.players.list.empty");
			}
			
			ChatMessage chatmessage1 = new ChatMessage("commands.scoreboard.players.list.count", Integer.valueOf(collection.size()));
			
			chatmessage1.getChatModifier().setColor(EnumChatFormat.DARK_GREEN);
			icommandlistener.sendMessage(chatmessage1);
			icommandlistener.sendMessage(new ChatComponentText(a(collection.toArray())));
		}
		
	}
	
	protected void l(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		String s = astring[i - 1];
		int j = i;
		String s1 = e(icommandlistener, astring[i++]);
		
		if (s1.length() > 40) {
			throw new ExceptionInvalidSyntax("commands.scoreboard.players.name.tooLong", s1, Integer.valueOf(40));
		} else {
			ScoreboardObjective scoreboardobjective = this.a(astring[i++], true);
			int k = s.equalsIgnoreCase("set") ? a(astring[i++]) : a(astring[i++], 0);
			
			if (astring.length > i) {
				Entity entity = b(icommandlistener, astring[j]);
				
				try {
					NBTTagCompound nbttagcompound = MojangsonParser.parse(a(astring, i));
					NBTTagCompound nbttagcompound1 = new NBTTagCompound();
					
					entity.writeToNBT(nbttagcompound1);
					if (!GameProfileSerializer.a(nbttagcompound, nbttagcompound1, true)) {
						throw new CommandException("commands.scoreboard.players.set.tagMismatch", s1);
					}
				} catch (MojangsonParseException mojangsonparseexception) {
					throw new CommandException("commands.scoreboard.players.set.tagError", mojangsonparseexception.getMessage());
				}
			}
			
			Scoreboard scoreboard = this.d();
			ScoreboardScore scoreboardscore = scoreboard.getPlayerScoreForObjective(s1, scoreboardobjective);
			
			if (s.equalsIgnoreCase("set")) {
				scoreboardscore.setScore(k);
			} else if (s.equalsIgnoreCase("add")) {
				scoreboardscore.addScore(k);
			} else {
				scoreboardscore.removeScore(k);
			}
			
			a(icommandlistener, this, "commands.scoreboard.players.set.success", scoreboardobjective.getName(), s1, Integer.valueOf(scoreboardscore.getScore()));
		}
	}
	
	protected void m(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		String s = e(icommandlistener, astring[i++]);
		
		if (astring.length > i) {
			ScoreboardObjective scoreboardobjective = this.a(astring[i++], false);
			
			scoreboard.resetPlayerScores(s, scoreboardobjective);
			a(icommandlistener, this, "commands.scoreboard.players.resetscore.success", scoreboardobjective.getName(), s);
		} else {
			scoreboard.resetPlayerScores(s, null);
			a(icommandlistener, this, "commands.scoreboard.players.reset.success", s);
		}
		
	}
	
	protected void n(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		String s = d(icommandlistener, astring[i++]);
		
		if (s.length() > 40) {
			throw new ExceptionInvalidSyntax("commands.scoreboard.players.name.tooLong", s, Integer.valueOf(40));
		} else {
			ScoreboardObjective scoreboardobjective = this.a(astring[i], false);
			
			if (scoreboardobjective.getCriteria() != IScoreboardCriteria.c) {
				throw new CommandException("commands.scoreboard.players.enable.noTrigger", scoreboardobjective.getName());
			} else {
				ScoreboardScore scoreboardscore = scoreboard.getPlayerScoreForObjective(s, scoreboardobjective);
				
				scoreboardscore.a(false);
				a(icommandlistener, this, "commands.scoreboard.players.enable.success", scoreboardobjective.getName(), s);
			}
		}
	}
	
	protected void o(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		String s = e(icommandlistener, astring[i++]);
		
		if (s.length() > 40) {
			throw new ExceptionInvalidSyntax("commands.scoreboard.players.name.tooLong", s, Integer.valueOf(40));
		} else {
			ScoreboardObjective scoreboardobjective = this.a(astring[i++], false);
			
			if (!scoreboard.b(s, scoreboardobjective)) {
				throw new CommandException("commands.scoreboard.players.test.notFound", scoreboardobjective.getName(), s);
			} else {
				int j = astring[i].equals("*") ? Integer.MIN_VALUE : a(astring[i]);
				
				++i;
				int k = i < astring.length && !astring[i].equals("*") ? a(astring[i], j) : Integer.MAX_VALUE;
				ScoreboardScore scoreboardscore = scoreboard.getPlayerScoreForObjective(s, scoreboardobjective);
				
				if (scoreboardscore.getScore() >= j && scoreboardscore.getScore() <= k) {
					a(icommandlistener, this, "commands.scoreboard.players.test.success", Integer.valueOf(scoreboardscore.getScore()), Integer.valueOf(j), Integer.valueOf(k));
				} else {
					throw new CommandException("commands.scoreboard.players.test.failed", Integer.valueOf(scoreboardscore.getScore()), Integer.valueOf(j), Integer.valueOf(k));
				}
			}
		}
	}
	
	protected void p(ICommandListener icommandlistener, String[] astring, int i) throws CommandException {
		Scoreboard scoreboard = this.d();
		String s = e(icommandlistener, astring[i++]);
		ScoreboardObjective scoreboardobjective = this.a(astring[i++], true);
		String s1 = astring[i++];
		String s2 = e(icommandlistener, astring[i++]);
		ScoreboardObjective scoreboardobjective1 = this.a(astring[i], false);
		
		if (s.length() > 40) {
			throw new ExceptionInvalidSyntax("commands.scoreboard.players.name.tooLong", s, Integer.valueOf(40));
		} else if (s2.length() > 40) {
			throw new ExceptionInvalidSyntax("commands.scoreboard.players.name.tooLong", s2, Integer.valueOf(40));
		} else {
			ScoreboardScore scoreboardscore = scoreboard.getPlayerScoreForObjective(s, scoreboardobjective);
			
			if (!scoreboard.b(s2, scoreboardobjective1)) {
				throw new CommandException("commands.scoreboard.players.operation.notFound", scoreboardobjective1.getName(), s2);
			} else {
				ScoreboardScore scoreboardscore1 = scoreboard.getPlayerScoreForObjective(s2, scoreboardobjective1);
				
				if (s1.equals("+=")) {
					scoreboardscore.setScore(scoreboardscore.getScore() + scoreboardscore1.getScore());
				} else if (s1.equals("-=")) {
					scoreboardscore.setScore(scoreboardscore.getScore() - scoreboardscore1.getScore());
				} else if (s1.equals("*=")) {
					scoreboardscore.setScore(scoreboardscore.getScore() * scoreboardscore1.getScore());
				} else if (s1.equals("/=")) {
					if (scoreboardscore1.getScore() != 0) {
						scoreboardscore.setScore(scoreboardscore.getScore() / scoreboardscore1.getScore());
					}
				} else if (s1.equals("%=")) {
					if (scoreboardscore1.getScore() != 0) {
						scoreboardscore.setScore(scoreboardscore.getScore() % scoreboardscore1.getScore());
					}
				} else if (s1.equals("=")) {
					scoreboardscore.setScore(scoreboardscore1.getScore());
				} else if (s1.equals("<")) {
					scoreboardscore.setScore(Math.min(scoreboardscore.getScore(), scoreboardscore1.getScore()));
				} else if (s1.equals(">")) {
					scoreboardscore.setScore(Math.max(scoreboardscore.getScore(), scoreboardscore1.getScore()));
				} else {
					if (!s1.equals("><")) {
						throw new CommandException("commands.scoreboard.players.operation.invalidOperation", s1);
					}
					
					int j = scoreboardscore.getScore();
					
					scoreboardscore.setScore(scoreboardscore1.getScore());
					scoreboardscore1.setScore(j);
				}
				
				a(icommandlistener, this, "commands.scoreboard.players.operation.success");
			}
		}
	}
	
	public List tabComplete(ICommandListener icommandlistener, String[] astring, BlockPosition blockposition) {
		if (astring.length == 1) {
			return a(astring, "objectives", "players", "teams");
		} else {
			if (astring[0].equalsIgnoreCase("objectives")) {
				if (astring.length == 2) {
					return a(astring, "list", "add", "remove", "setdisplay");
				}
				
				if (astring[1].equalsIgnoreCase("add")) {
					if (astring.length == 4) {
						Set set = IScoreboardCriteria.criteria.keySet();
						
						return a(astring, set);
					}
				} else if (astring[1].equalsIgnoreCase("remove")) {
					if (astring.length == 3) {
						return a(astring, this.a(false));
					}
				} else if (astring[1].equalsIgnoreCase("setdisplay")) {
					if (astring.length == 3) {
						return a(astring, Scoreboard.h());
					}
					
					if (astring.length == 4) {
						return a(astring, this.a(false));
					}
				}
			} else if (astring[0].equalsIgnoreCase("players")) {
				if (astring.length == 2) {
					return a(astring, "set", "add", "remove", "reset", "list", "enable", "test", "operation");
				}
				
				if (!astring[1].equalsIgnoreCase("set") && !astring[1].equalsIgnoreCase("add") && !astring[1].equalsIgnoreCase("remove") && !astring[1].equalsIgnoreCase("reset")) {
					if (astring[1].equalsIgnoreCase("enable")) {
						if (astring.length == 3) {
							return a(astring, MinecraftServer.getServer().getPlayers());
						}
						
						if (astring.length == 4) {
							return a(astring, this.e());
						}
					} else if (!astring[1].equalsIgnoreCase("list") && !astring[1].equalsIgnoreCase("test")) {
						if (astring[1].equalsIgnoreCase("operation")) {
							if (astring.length == 3) {
								return a(astring, this.d().getPlayers());
							}
							
							if (astring.length == 4) {
								return a(astring, this.a(true));
							}
							
							if (astring.length == 5) {
								return a(astring, "+=", "-=", "*=", "/=", "%=", "=", "<", ">", "><");
							}
							
							if (astring.length == 6) {
								return a(astring, MinecraftServer.getServer().getPlayers());
							}
							
							if (astring.length == 7) {
								return a(astring, this.a(false));
							}
						}
					} else {
						if (astring.length == 3) {
							return a(astring, this.d().getPlayers());
						}
						
						if (astring.length == 4 && astring[1].equalsIgnoreCase("test")) {
							return a(astring, this.a(false));
						}
					}
				} else {
					if (astring.length == 3) {
						return a(astring, MinecraftServer.getServer().getPlayers());
					}
					
					if (astring.length == 4) {
						return a(astring, this.a(true));
					}
				}
			} else if (astring[0].equalsIgnoreCase("teams")) {
				if (astring.length == 2) {
					return a(astring, "add", "remove", "join", "leave", "empty", "list", "option");
				}
				
				if (astring[1].equalsIgnoreCase("join")) {
					if (astring.length == 3) {
						return a(astring, this.d().getTeamNames());
					}
					
					if (astring.length >= 4) {
						return a(astring, MinecraftServer.getServer().getPlayers());
					}
				} else {
					if (astring[1].equalsIgnoreCase("leave")) {
						return a(astring, MinecraftServer.getServer().getPlayers());
					}
					
					if (!astring[1].equalsIgnoreCase("empty") && !astring[1].equalsIgnoreCase("list") && !astring[1].equalsIgnoreCase("remove")) {
						if (astring[1].equalsIgnoreCase("option")) {
							if (astring.length == 3) {
								return a(astring, this.d().getTeamNames());
							}
							
							if (astring.length == 4) {
								return a(astring, "color", "friendlyfire", "seeFriendlyInvisibles", "nametagVisibility", "deathMessageVisibility");
							}
							
							if (astring.length == 5) {
								if (astring[3].equalsIgnoreCase("color")) {
									return a(astring, EnumChatFormat.a(true, false));
								}
								
								if (astring[3].equalsIgnoreCase("nametagVisibility") || astring[3].equalsIgnoreCase("deathMessageVisibility")) {
									return a(astring, ScoreboardTeamBase.EnumNameTagVisibility.a());
								}
								
								if (astring[3].equalsIgnoreCase("friendlyfire") || astring[3].equalsIgnoreCase("seeFriendlyInvisibles")) {
									return a(astring, "true", "false");
								}
							}
						}
					} else if (astring.length == 3) {
						return a(astring, this.d().getTeamNames());
					}
				}
			}
			
			return null;
		}
	}
	
	protected List a(boolean flag) {
		Collection collection = this.d().getObjectives();
		ArrayList arraylist = Lists.newArrayList();
		Iterator iterator = collection.iterator();
		
		while (iterator.hasNext()) {
			ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next();
			
			if (!flag || !scoreboardobjective.getCriteria().isReadOnly()) {
				arraylist.add(scoreboardobjective.getName());
			}
		}
		
		return arraylist;
	}
	
	protected List e() {
		Collection collection = this.d().getObjectives();
		ArrayList arraylist = Lists.newArrayList();
		Iterator iterator = collection.iterator();
		
		while (iterator.hasNext()) {
			ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next();
			
			if (scoreboardobjective.getCriteria() == IScoreboardCriteria.c) {
				arraylist.add(scoreboardobjective.getName());
			}
		}
		
		return arraylist;
	}
	
	public boolean isListStart(String[] astring, int i) {
		return !astring[0].equalsIgnoreCase("players") ? (astring[0].equalsIgnoreCase("teams") && i == 2) : (astring.length > 1 && astring[1].equalsIgnoreCase("operation") ? i == 2 || i == 5 : i == 2);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy