Advertisement
Earthcomputer

ScoreboardCommand.java

Sep 10th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.51 KB | None | 0 0
  1. package net.minecraft.command.impl;
  2.  
  3. import com.google.common.collect.Lists;
  4. import com.mojang.brigadier.CommandDispatcher;
  5. import com.mojang.brigadier.arguments.IntegerArgumentType;
  6. import com.mojang.brigadier.arguments.StringArgumentType;
  7. import com.mojang.brigadier.builder.LiteralArgumentBuilder;
  8. import com.mojang.brigadier.builder.RequiredArgumentBuilder;
  9. import com.mojang.brigadier.exceptions.CommandSyntaxException;
  10. import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType;
  11. import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
  12. import com.mojang.brigadier.suggestion.Suggestions;
  13. import com.mojang.brigadier.suggestion.SuggestionsBuilder;
  14. import java.util.Collection;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Map.Entry;
  18. import java.util.concurrent.CompletableFuture;
  19. import net.minecraft.command.CommandSource;
  20. import net.minecraft.command.Commands;
  21. import net.minecraft.command.ISuggestionProvider;
  22. import net.minecraft.command.arguments.ComponentArgument;
  23. import net.minecraft.command.arguments.ObjectiveArgument;
  24. import net.minecraft.command.arguments.ObjectiveCriteriaArgument;
  25. import net.minecraft.command.arguments.OperationArgument;
  26. import net.minecraft.command.arguments.ScoreHolderArgument;
  27. import net.minecraft.command.arguments.ScoreboardSlotArgument;
  28. import net.minecraft.scoreboard.IScoreCriteria;
  29. import net.minecraft.scoreboard.Score;
  30. import net.minecraft.scoreboard.ScoreObjective;
  31. import net.minecraft.scoreboard.Scoreboard;
  32. import net.minecraft.util.text.ITextComponent;
  33. import net.minecraft.util.text.TextComponentString;
  34. import net.minecraft.util.text.TextComponentTranslation;
  35. import net.minecraft.util.text.TextComponentUtils;
  36.  
  37. public class ScoreboardCommand {
  38.     private static final SimpleCommandExceptionType OBJECTIVE_ALREADY_EXISTS_EXCEPTION = new SimpleCommandExceptionType(new TextComponentTranslation("commands.scoreboard.objectives.add.duplicate", new Object[0]));
  39.     private static final SimpleCommandExceptionType DISPLAY_ALREADY_CLEAR_EXCEPTION = new SimpleCommandExceptionType(new TextComponentTranslation("commands.scoreboard.objectives.display.alreadyEmpty", new Object[0]));
  40.     private static final SimpleCommandExceptionType DISPLAY_ALREADY_SET_EXCEPTION = new SimpleCommandExceptionType(new TextComponentTranslation("commands.scoreboard.objectives.display.alreadySet", new Object[0]));
  41.     private static final SimpleCommandExceptionType ENABLE_TRIGGER_FAILED = new SimpleCommandExceptionType(new TextComponentTranslation("commands.scoreboard.players.enable.failed", new Object[0]));
  42.     private static final SimpleCommandExceptionType ENABLE_TRIGGER_INVALID = new SimpleCommandExceptionType(new TextComponentTranslation("commands.scoreboard.players.enable.invalid", new Object[0]));
  43.     private static final Dynamic2CommandExceptionType SCOREBOARD_PLAYER_NOT_FOUND_EXCEPTION = new Dynamic2CommandExceptionType((p_208907_0_, p_208907_1_) -> {
  44.         return new TextComponentTranslation("commands.scoreboard.players.get.null", new Object[]{p_208907_0_, p_208907_1_});
  45.     });
  46.  
  47.     public static void register(CommandDispatcher<CommandSource> dispatcher) {
  48.         dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("scoreboard").requires((p_198650_0_) -> {
  49.             return p_198650_0_.hasPermissionLevel(2);
  50.         })).then(((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("objectives").then(Commands.literal("list").executes((p_198640_0_) -> {
  51.             return listObjectives((CommandSource)p_198640_0_.getSource());
  52.         }))).then(Commands.literal("add").then(Commands.argument("objective", StringArgumentType.word()).then(((RequiredArgumentBuilder)Commands.argument("criteria", ObjectiveCriteriaArgument.objectiveCriteria()).executes((p_198636_0_) -> {
  53.             return addObjective((CommandSource)p_198636_0_.getSource(), StringArgumentType.getString(p_198636_0_, "objective"), ObjectiveCriteriaArgument.getObjectiveCriteria(p_198636_0_, "criteria"), new TextComponentString(StringArgumentType.getString(p_198636_0_, "objective")));
  54.         })).then(Commands.argument("displayName", ComponentArgument.component()).executes((p_198649_0_) -> {
  55.             return addObjective((CommandSource)p_198649_0_.getSource(), StringArgumentType.getString(p_198649_0_, "objective"), ObjectiveCriteriaArgument.getObjectiveCriteria(p_198649_0_, "criteria"), ComponentArgument.getComponent(p_198649_0_, "displayName"));
  56.         })))))).then(Commands.literal("modify").then(((RequiredArgumentBuilder)Commands.argument("objective", ObjectiveArgument.objective()).then(Commands.literal("displayname").then(Commands.argument("displayName", ComponentArgument.component()).executes((p_211750_0_) -> {
  57.             return setDisplayName((CommandSource)p_211750_0_.getSource(), ObjectiveArgument.getObjective(p_211750_0_, "objective"), ComponentArgument.getComponent(p_211750_0_, "displayName"));
  58.         })))).then(createRenderTypeArgument())))).then(Commands.literal("remove").then(Commands.argument("objective", ObjectiveArgument.objective()).executes((p_198646_0_) -> {
  59.             return removeObjective((CommandSource)p_198646_0_.getSource(), ObjectiveArgument.getObjective(p_198646_0_, "objective"));
  60.         })))).then(Commands.literal("setdisplay").then(((RequiredArgumentBuilder)Commands.argument("slot", ScoreboardSlotArgument.scoreboardSlot()).executes((p_198652_0_) -> {
  61.             return clearObjectiveDisplaySlot((CommandSource)p_198652_0_.getSource(), ScoreboardSlotArgument.getScoreboardSlot(p_198652_0_, "slot"));
  62.         })).then(Commands.argument("objective", ObjectiveArgument.objective()).executes((p_198639_0_) -> {
  63.             return setObjectiveDisplaySlot((CommandSource)p_198639_0_.getSource(), ScoreboardSlotArgument.getScoreboardSlot(p_198639_0_, "slot"), ObjectiveArgument.getObjective(p_198639_0_, "objective"));
  64.         })))))).then(((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("players").then(((LiteralArgumentBuilder)Commands.literal("list").executes((p_198642_0_) -> {
  65.             return listPlayers((CommandSource)p_198642_0_.getSource());
  66.         })).then(Commands.argument("target", ScoreHolderArgument.singleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).executes((p_198631_0_) -> {
  67.             return listPlayerScores((CommandSource)p_198631_0_.getSource(), ScoreHolderArgument.func_197211_a(p_198631_0_, "target"));
  68.         })))).then(Commands.literal("set").then(Commands.argument("targets", ScoreHolderArgument.multipleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).then(Commands.argument("objective", ObjectiveArgument.objective()).then(Commands.argument("score", IntegerArgumentType.integer()).executes((p_198655_0_) -> {
  69.             return setPlayerScore((CommandSource)p_198655_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198655_0_, "targets"), ObjectiveArgument.getWritableObjective(p_198655_0_, "objective"), IntegerArgumentType.getInteger(p_198655_0_, "score"));
  70.         })))))).then(Commands.literal("get").then(Commands.argument("target", ScoreHolderArgument.singleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).then(Commands.argument("objective", ObjectiveArgument.objective()).executes((p_198660_0_) -> {
  71.             return getPlayerScore((CommandSource)p_198660_0_.getSource(), ScoreHolderArgument.func_197211_a(p_198660_0_, "target"), ObjectiveArgument.getObjective(p_198660_0_, "objective"));
  72.         }))))).then(Commands.literal("add").then(Commands.argument("targets", ScoreHolderArgument.multipleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).then(Commands.argument("objective", ObjectiveArgument.objective()).then(Commands.argument("score", IntegerArgumentType.integer(0)).executes((p_198645_0_) -> {
  73.             return addToPlayerScore((CommandSource)p_198645_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198645_0_, "targets"), ObjectiveArgument.getWritableObjective(p_198645_0_, "objective"), IntegerArgumentType.getInteger(p_198645_0_, "score"));
  74.         })))))).then(Commands.literal("remove").then(Commands.argument("targets", ScoreHolderArgument.multipleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).then(Commands.argument("objective", ObjectiveArgument.objective()).then(Commands.argument("score", IntegerArgumentType.integer(0)).executes((p_198648_0_) -> {
  75.             return removeFromPlayerScore((CommandSource)p_198648_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198648_0_, "targets"), ObjectiveArgument.getWritableObjective(p_198648_0_, "objective"), IntegerArgumentType.getInteger(p_198648_0_, "score"));
  76.         })))))).then(Commands.literal("reset").then(((RequiredArgumentBuilder)Commands.argument("targets", ScoreHolderArgument.multipleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).executes((p_198635_0_) -> {
  77.             return resetPlayerAllScores((CommandSource)p_198635_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198635_0_, "targets"));
  78.         })).then(Commands.argument("objective", ObjectiveArgument.objective()).executes((p_198630_0_) -> {
  79.             return resetPlayerScore((CommandSource)p_198630_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198630_0_, "targets"), ObjectiveArgument.getObjective(p_198630_0_, "objective"));
  80.         }))))).then(Commands.literal("enable").then(Commands.argument("targets", ScoreHolderArgument.multipleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).then(Commands.argument("objective", ObjectiveArgument.objective()).suggests((p_198638_0_, p_198638_1_) -> {
  81.             return suggestTriggers((CommandSource)p_198638_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198638_0_, "targets"), p_198638_1_);
  82.         }).executes((p_198628_0_) -> {
  83.             return enableTrigger((CommandSource)p_198628_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198628_0_, "targets"), ObjectiveArgument.getObjective(p_198628_0_, "objective"));
  84.         }))))).then(Commands.literal("operation").then(Commands.argument("targets", ScoreHolderArgument.multipleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).then(Commands.argument("targetObjective", ObjectiveArgument.objective()).then(Commands.argument("operation", OperationArgument.operation()).then(Commands.argument("source", ScoreHolderArgument.multipleScoreHolder()).suggests(ScoreHolderArgument.field_201326_a).then(Commands.argument("sourceObjective", ObjectiveArgument.objective()).executes((p_198657_0_) -> {
  85.             return applyScoreOperation((CommandSource)p_198657_0_.getSource(), ScoreHolderArgument.getScoreHolder(p_198657_0_, "targets"), ObjectiveArgument.getWritableObjective(p_198657_0_, "targetObjective"), OperationArgument.getOperation(p_198657_0_, "operation"), ScoreHolderArgument.getScoreHolder(p_198657_0_, "source"), ObjectiveArgument.getObjective(p_198657_0_, "sourceObjective"));
  86.         })))))))));
  87.     }
  88.  
  89.     private static LiteralArgumentBuilder<CommandSource> createRenderTypeArgument() {
  90.         LiteralArgumentBuilder<CommandSource> literalargumentbuilder = Commands.literal("rendertype");
  91.  
  92.         for (IScoreCriteria.EnumRenderType iscorecriteria$enumrendertype : IScoreCriteria.EnumRenderType.values()) {
  93.             literalargumentbuilder.then(Commands.literal(iscorecriteria$enumrendertype.getId()).executes((p_211912_1_) -> {
  94.                 return setRenderType((CommandSource)p_211912_1_.getSource(), ObjectiveArgument.getObjective(p_211912_1_, "objective"), iscorecriteria$enumrendertype);
  95.             }));
  96.         }
  97.  
  98.         return literalargumentbuilder;
  99.     }
  100.  
  101.     private static CompletableFuture<Suggestions> suggestTriggers(CommandSource source, Collection<String> targets, SuggestionsBuilder suggestions) {
  102.         List<String> list = Lists.<String>newArrayList();
  103.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  104.  
  105.         for (ScoreObjective scoreobjective : scoreboard.getScoreObjectives()) {
  106.             if (scoreobjective.getCriteria() == IScoreCriteria.TRIGGER) {
  107.                 boolean flag = false;
  108.  
  109.                 for (String s : targets) {
  110.                     if (!scoreboard.entityHasObjective(s, scoreobjective) || scoreboard.getOrCreateScore(s, scoreobjective).isLocked()) {
  111.                         flag = true;
  112.                         break;
  113.                     }
  114.                 }
  115.  
  116.                 if (flag) {
  117.                     list.add(scoreobjective.getName());
  118.                 }
  119.             }
  120.         }
  121.  
  122.         return ISuggestionProvider.suggest(list, suggestions);
  123.     }
  124.  
  125.     private static int getPlayerScore(CommandSource source, String player, ScoreObjective objective) throws CommandSyntaxException {
  126.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  127.  
  128.         if (!scoreboard.entityHasObjective(player, objective)) {
  129.             throw SCOREBOARD_PLAYER_NOT_FOUND_EXCEPTION.create(objective.getName(), player);
  130.         } else {
  131.             Score score = scoreboard.getOrCreateScore(player, objective);
  132.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.get.success", new Object[] {player, score.getScorePoints(), objective.func_197890_e()}), false);
  133.             return score.getScorePoints();
  134.         }
  135.     }
  136.  
  137.     private static int applyScoreOperation(CommandSource source, Collection<String> targetEntities, ScoreObjective targetObjectives, OperationArgument.IOperation operation, Collection<String> sourceEntities, ScoreObjective sourceObjective) throws CommandSyntaxException {
  138.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  139.         int i = 0;
  140.  
  141.         for (String s : targetEntities) {
  142.             Score score = scoreboard.getOrCreateScore(s, targetObjectives);
  143.  
  144.             for (String s1 : sourceEntities) {
  145.                 Score score1 = scoreboard.getOrCreateScore(s1, sourceObjective);
  146.                 operation.apply(score, score1);
  147.             }
  148.  
  149.             i += score.getScorePoints();
  150.         }
  151.  
  152.         if (targetEntities.size() == 1) {
  153.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.operation.success.single", new Object[] {targetObjectives.func_197890_e(), targetEntities.iterator().next(), i}), true);
  154.         } else {
  155.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.operation.success.multiple", new Object[] {targetObjectives.func_197890_e(), targetEntities.size()}), true);
  156.         }
  157.  
  158.         return i;
  159.     }
  160.  
  161.     private static int enableTrigger(CommandSource source, Collection<String> targets, ScoreObjective objective) throws CommandSyntaxException {
  162.         if (objective.getCriteria() != IScoreCriteria.TRIGGER) {
  163.             throw ENABLE_TRIGGER_INVALID.create();
  164.         } else {
  165.             Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  166.             int i = 0;
  167.  
  168.             for (String s : targets) {
  169.                 Score score = scoreboard.getOrCreateScore(s, objective);
  170.  
  171.                 if (score.isLocked()) {
  172.                     score.setLocked(false);
  173.                     ++i;
  174.                 }
  175.             }
  176.  
  177.             if (i == 0) {
  178.                 throw ENABLE_TRIGGER_FAILED.create();
  179.             } else {
  180.                 if (targets.size() == 1) {
  181.                     source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.enable.success.single", new Object[] {objective.func_197890_e(), targets.iterator().next()}), true);
  182.                 } else {
  183.                     source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.enable.success.multiple", new Object[] {objective.func_197890_e(), targets.size()}), true);
  184.                 }
  185.  
  186.                 return i;
  187.             }
  188.         }
  189.     }
  190.  
  191.     private static int resetPlayerAllScores(CommandSource source, Collection<String> targets) {
  192.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  193.  
  194.         for (String s : targets) {
  195.             scoreboard.removeObjectiveFromEntity(s, (ScoreObjective)null);
  196.         }
  197.  
  198.         if (targets.size() == 1) {
  199.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.reset.all.single", new Object[] {targets.iterator().next()}), true);
  200.         } else {
  201.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.reset.all.multiple", new Object[] {targets.size()}), true);
  202.         }
  203.  
  204.         return targets.size();
  205.     }
  206.  
  207.     private static int resetPlayerScore(CommandSource source, Collection<String> targets, ScoreObjective objective) {
  208.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  209.  
  210.         for (String s : targets) {
  211.             scoreboard.removeObjectiveFromEntity(s, objective);
  212.         }
  213.  
  214.         if (targets.size() == 1) {
  215.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.reset.specific.single", new Object[] {objective.func_197890_e(), targets.iterator().next()}), true);
  216.         } else {
  217.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.reset.specific.multiple", new Object[] {objective.func_197890_e(), targets.size()}), true);
  218.         }
  219.  
  220.         return targets.size();
  221.     }
  222.  
  223.     private static int setPlayerScore(CommandSource source, Collection<String> targets, ScoreObjective objective, int newValue) {
  224.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  225.  
  226.         for (String s : targets) {
  227.             Score score = scoreboard.getOrCreateScore(s, objective);
  228.             score.setScorePoints(newValue);
  229.         }
  230.  
  231.         if (targets.size() == 1) {
  232.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.set.success.single", new Object[] {objective.func_197890_e(), targets.iterator().next(), newValue}), true);
  233.         } else {
  234.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.set.success.multiple", new Object[] {objective.func_197890_e(), targets.size(), newValue}), true);
  235.         }
  236.  
  237.         return newValue * targets.size();
  238.     }
  239.  
  240.     private static int addToPlayerScore(CommandSource source, Collection<String> targets, ScoreObjective objective, int amount) {
  241.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  242.         int i = 0;
  243.  
  244.         for (String s : targets) {
  245.             Score score = scoreboard.getOrCreateScore(s, objective);
  246.             score.setScorePoints(score.getScorePoints() + amount);
  247.             i += score.getScorePoints();
  248.         }
  249.  
  250.         if (targets.size() == 1) {
  251.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.add.success.single", new Object[] {amount, objective.func_197890_e(), targets.iterator().next(), i}), true);
  252.         } else {
  253.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.add.success.multiple", new Object[] {amount, objective.func_197890_e(), targets.size()}), true);
  254.         }
  255.  
  256.         return i;
  257.     }
  258.  
  259.     private static int removeFromPlayerScore(CommandSource source, Collection<String> targets, ScoreObjective objective, int amount) {
  260.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  261.         int i = 0;
  262.  
  263.         for (String s : targets) {
  264.             Score score = scoreboard.getOrCreateScore(s, objective);
  265.             score.setScorePoints(score.getScorePoints() - amount);
  266.             i += score.getScorePoints();
  267.         }
  268.  
  269.         if (targets.size() == 1) {
  270.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.remove.success.single", new Object[] {amount, objective.func_197890_e(), targets.iterator().next(), i}), true);
  271.         } else {
  272.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.remove.success.multiple", new Object[] {amount, objective.func_197890_e(), targets.size()}), true);
  273.         }
  274.  
  275.         return i;
  276.     }
  277.  
  278.     private static int listPlayers(CommandSource source) {
  279.         Collection<String> collection = source.getServer().getWorldScoreboard().getObjectiveNames();
  280.  
  281.         if (collection.isEmpty()) {
  282.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.list.empty", new Object[0]), false);
  283.         } else {
  284.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.list.success", new Object[] {collection.size(), TextComponentUtils.makeGreenSortedList(collection)}), false);
  285.         }
  286.  
  287.         return collection.size();
  288.     }
  289.  
  290.     private static int listPlayerScores(CommandSource source, String player) {
  291.         Map<ScoreObjective, Score> map = source.getServer().getWorldScoreboard().getObjectivesForEntity(player);
  292.  
  293.         if (map.isEmpty()) {
  294.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.list.entity.empty", new Object[] {player}), false);
  295.         } else {
  296.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.list.entity.success", new Object[] {player, map.size()}), false);
  297.  
  298.             for (Entry<ScoreObjective, Score> entry : map.entrySet()) {
  299.                 source.sendFeedback(new TextComponentTranslation("commands.scoreboard.players.list.entity.entry", new Object[] {((ScoreObjective)entry.getKey()).func_197890_e(), ((Score)entry.getValue()).getScorePoints()}), false);
  300.             }
  301.         }
  302.  
  303.         return map.size();
  304.     }
  305.  
  306.     private static int clearObjectiveDisplaySlot(CommandSource source, int slotId) throws CommandSyntaxException {
  307.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  308.  
  309.         if (scoreboard.getObjectiveInDisplaySlot(slotId) == null) {
  310.             throw DISPLAY_ALREADY_CLEAR_EXCEPTION.create();
  311.         } else {
  312.             scoreboard.setObjectiveInDisplaySlot(slotId, (ScoreObjective)null);
  313.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.display.cleared", new Object[] {Scoreboard.getDisplaySlotStrings()[slotId]}), true);
  314.             return 0;
  315.         }
  316.     }
  317.  
  318.     private static int setObjectiveDisplaySlot(CommandSource source, int slotId, ScoreObjective objective) throws CommandSyntaxException {
  319.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  320.  
  321.         if (scoreboard.getObjectiveInDisplaySlot(slotId) == objective) {
  322.             throw DISPLAY_ALREADY_SET_EXCEPTION.create();
  323.         } else {
  324.             scoreboard.setObjectiveInDisplaySlot(slotId, objective);
  325.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.display.set", new Object[] {Scoreboard.getDisplaySlotStrings()[slotId], objective.getDisplayName()}), true);
  326.             return 0;
  327.         }
  328.     }
  329.  
  330.     private static int setDisplayName(CommandSource source, ScoreObjective objective, ITextComponent displayName) {
  331.         if (!objective.getDisplayName().equals(displayName)) {
  332.             objective.func_199864_a(displayName);
  333.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.modify.displayname", new Object[] {objective.getName(), objective.func_197890_e()}), true);
  334.         }
  335.  
  336.         return 0;
  337.     }
  338.  
  339.     private static int setRenderType(CommandSource source, ScoreObjective objective, IScoreCriteria.EnumRenderType renderType) {
  340.         if (objective.func_199865_f() != renderType) {
  341.             objective.func_199866_a(renderType);
  342.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.modify.rendertype", new Object[] {objective.func_197890_e()}), true);
  343.         }
  344.  
  345.         return 0;
  346.     }
  347.  
  348.     private static int removeObjective(CommandSource source, ScoreObjective objective) {
  349.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  350.         scoreboard.removeObjective(objective);
  351.         source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.remove.success", new Object[] {objective.func_197890_e()}), true);
  352.         return scoreboard.getScoreObjectives().size();
  353.     }
  354.  
  355.     private static int addObjective(CommandSource source, String name, IScoreCriteria criteria, ITextComponent displayName) throws CommandSyntaxException {
  356.         Scoreboard scoreboard = source.getServer().getWorldScoreboard();
  357.  
  358.         if (scoreboard.getObjective(name) != null) {
  359.             throw OBJECTIVE_ALREADY_EXISTS_EXCEPTION.create();
  360.         } else if (name.length() > 16) {
  361.             throw ObjectiveArgument.field_200379_a.create(16);
  362.         } else {
  363.             scoreboard.addObjective(name, criteria, displayName, criteria.getRenderType());
  364.             ScoreObjective scoreobjective = scoreboard.getObjective(name);
  365.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.add.success", new Object[] {scoreobjective.func_197890_e()}), true);
  366.             return scoreboard.getScoreObjectives().size();
  367.         }
  368.     }
  369.  
  370.     private static int listObjectives(CommandSource source) {
  371.         Collection<ScoreObjective> collection = source.getServer().getWorldScoreboard().getScoreObjectives();
  372.  
  373.         if (collection.isEmpty()) {
  374.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.list.empty", new Object[0]), false);
  375.         } else {
  376.             source.sendFeedback(new TextComponentTranslation("commands.scoreboard.objectives.list.success", new Object[] {collection.size(), TextComponentUtils.makeList(collection, ScoreObjective::func_197890_e)}), false);
  377.         }
  378.  
  379.         return collection.size();
  380.     }
  381. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement