diff --git a/output/production/commander-bta.main/net/pedroricardo/commander/content/arguments/ChunkCoordinatesArgumentType.class b/output/production/commander-bta.main/net/pedroricardo/commander/content/arguments/ChunkCoordinatesArgumentType.class index ac64a86..3a72bfd 100644 Binary files a/output/production/commander-bta.main/net/pedroricardo/commander/content/arguments/ChunkCoordinatesArgumentType.class and b/output/production/commander-bta.main/net/pedroricardo/commander/content/arguments/ChunkCoordinatesArgumentType.class differ diff --git a/output/production/commander-bta.main/net/pedroricardo/commander/content/commands/ChunkCommand.class b/output/production/commander-bta.main/net/pedroricardo/commander/content/commands/ChunkCommand.class index d0fdb3c..a96a677 100644 Binary files a/output/production/commander-bta.main/net/pedroricardo/commander/content/commands/ChunkCommand.class and b/output/production/commander-bta.main/net/pedroricardo/commander/content/commands/ChunkCommand.class differ diff --git a/output/production/commander-bta.main/net/pedroricardo/commander/content/helpers/ChunkCoordinates.class b/output/production/commander-bta.main/net/pedroricardo/commander/content/helpers/ChunkCoordinates.class deleted file mode 100644 index b938e59..0000000 Binary files a/output/production/commander-bta.main/net/pedroricardo/commander/content/helpers/ChunkCoordinates.class and /dev/null differ diff --git a/src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java b/src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java index abf7338..e4fcf15 100644 --- a/src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java +++ b/src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java @@ -19,7 +19,7 @@ public class WeatherArgumentType implements ArgumentType { private static final Collection EXAMPLES = Arrays.asList(Weather.overworldClear.languageKey, Weather.overworldFog.languageKey); - public static ArgumentType weather() { + public static WeatherArgumentType weather() { return new WeatherArgumentType(); } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/AchievementCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/AchievementCommand.java index ce4f560..e520210 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/AchievementCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/AchievementCommand.java @@ -19,18 +19,17 @@ import java.util.ArrayList; import java.util.List; -@SuppressWarnings("unchecked") public class AchievementCommand { private static final SimpleCommandExceptionType PLAYER_ALREADY_HAS_ACHIEVEMENT = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.achievement.grant.exception_already_has_achievement")); public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)(((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("achievement")) - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("grant")) - .then(RequiredArgumentBuilder.argument("entities", EntityArgumentType.players()) - .then(RequiredArgumentBuilder.argument("achievement", AchievementArgumentType.achievement()) + dispatcher.register(((LiteralArgumentBuilder.literal("achievement")) + .requires(CommanderCommandSource::hasAdmin) + .then((LiteralArgumentBuilder.literal("grant")) + .then(RequiredArgumentBuilder.argument("entities", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("achievement", AchievementArgumentType.achievement()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); List entities = c.getArgument("entities", EntitySelector.class).get(source); Achievement achievement = c.getArgument("achievement", Achievement.class); @@ -54,9 +53,9 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("*") + .then(LiteralArgumentBuilder.literal("*") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); List entities = c.getArgument("entities", EntitySelector.class).get(source); for (Achievement achievement : AchievementList.achievementList) { diff --git a/src/main/java/net/pedroricardo/commander/content/commands/BiomeCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/BiomeCommand.java index 2c3e7c8..6080340 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/BiomeCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/BiomeCommand.java @@ -13,13 +13,8 @@ import net.pedroricardo.commander.content.arguments.BiomeArgumentType; import net.pedroricardo.commander.content.arguments.IntegerCoordinatesArgumentType; import net.pedroricardo.commander.content.helpers.Coordinates2D; -import net.pedroricardo.commander.content.helpers.IntegerCoordinate; import net.pedroricardo.commander.content.helpers.IntegerCoordinates; -import java.util.ArrayDeque; -import java.util.Queue; - -@SuppressWarnings("unchecked") public class BiomeCommand { private static final DynamicCommandExceptionType FAILURE = new DynamicCommandExceptionType(arg -> () -> I18n.getInstance().translateKeyAndFormat("commands.commander.biome.locate.exception_failure", arg)); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/ChunkCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/ChunkCommand.java index 0c37de7..a1b59a2 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/ChunkCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/ChunkCommand.java @@ -10,7 +10,6 @@ import net.pedroricardo.commander.content.arguments.ChunkCoordinatesArgumentType; import net.pedroricardo.commander.content.helpers.Coordinates2D; -@SuppressWarnings("unchecked") public class ChunkCommand { public static void register(CommandDispatcher dispatcher) { dispatcher.register(LiteralArgumentBuilder.literal("chunk") diff --git a/src/main/java/net/pedroricardo/commander/content/commands/ClearCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/ClearCommand.java index 792d045..6e34d9b 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/ClearCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/ClearCommand.java @@ -20,16 +20,15 @@ import java.util.*; -@SuppressWarnings("unchecked") public class ClearCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.clear.exception_failure")); public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("clear") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("clear") + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); - EntityPlayer sender = ((CommanderCommandSource)c.getSource()).getSender(); + CommanderCommandSource source = c.getSource(); + EntityPlayer sender = source.getSender(); if (sender == null) throw CommanderExceptions.notInWorld().create(); @@ -40,9 +39,9 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("players", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("players", EntityArgumentType.players()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); List players = c.getArgument("players", EntitySelector.class).get(source); int itemsCleared = 0; @@ -56,9 +55,9 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("item", ItemStackArgumentType.itemStack()) + .then(RequiredArgumentBuilder.argument("item", ItemStackArgumentType.itemStack()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); List players = c.getArgument("players", EntitySelector.class).get(source); ItemStack itemStack = c.getArgument("item", ItemStack.class); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/CloneCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/CloneCommand.java index ce8ed1b..1e2b530 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/CloneCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/CloneCommand.java @@ -26,148 +26,33 @@ import java.util.HashMap; import java.util.Map; -@SuppressWarnings("unchecked") public class CloneCommand { private static final SimpleCommandExceptionType INSIDE_CLONED_AREA = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.clone.exception_inside_cloned_area")); private static final SimpleCommandExceptionType DESTINATION_NOT_LOADED = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.clone.exception_destination_not_loaded")); private static final SimpleCommandExceptionType SOURCE_NOT_LOADED = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.clone.exception_source_not_loaded")); private static final SimpleCommandExceptionType NOWHERE_LOADED = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.clone.exception_nowhere_loaded")); -// public static void register(CommandDispatcher dispatcher) { -// dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("clone") -// .then(LiteralArgumentBuilder.literal("from") -// .then(RequiredArgumentBuilder.argument("sourceDimension", DimensionArgumentType.dimension()) -// .then(RequiredArgumentBuilder.argument("begin", IntegerCoordinatesArgumentType.intCoordinates()) -// .then(RequiredArgumentBuilder.argument("end", IntegerCoordinatesArgumentType.intCoordinates()) -// .then(RequiredArgumentBuilder.argument("destination", IntegerCoordinatesArgumentType.intCoordinates()) -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// Dimension sourceDimension = c.getArgument("sourceDimension", Dimension.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(sourceDimension.id), ((CommanderCommandSource) c.getSource()).getWorld(), begin, end, destination, CloneMode.NORMAL); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }) -// .then(LiteralArgumentBuilder.literal("filtered") -// .then(RequiredArgumentBuilder.argument("filter", BlockArgumentType.block()) -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// Dimension sourceDimension = c.getArgument("sourceDimension", Dimension.class); -// BlockInput filter = c.getArgument("filter", BlockInput.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(sourceDimension.id), ((CommanderCommandSource) c.getSource()).getWorld(), begin, end, destination, CloneMode.NORMAL, filter); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }))) -// .then(LiteralArgumentBuilder.literal("masked") -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(), ((CommanderCommandSource) c.getSource()).getWorld(), begin, end, destination, CloneMode.NORMAL, new BlockInput(null, 0, new CompoundTag())); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }))) -// .then(LiteralArgumentBuilder.literal("to") -// .then(RequiredArgumentBuilder.argument("targetDimension", DimensionArgumentType.dimension()) -// .then(RequiredArgumentBuilder.argument("destination", IntegerCoordinatesArgumentType.intCoordinates()) -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// Dimension sourceDimension = c.getArgument("sourceDimension", Dimension.class); -// Dimension targetDimension = c.getArgument("targetDimension", Dimension.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(sourceDimension.id), ((CommanderCommandSource) c.getSource()).getWorld(targetDimension.id), begin, end, destination, CloneMode.NORMAL); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }) -// .then(LiteralArgumentBuilder.literal("filtered") -// .then(RequiredArgumentBuilder.argument("filter", BlockArgumentType.block()) -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// Dimension sourceDimension = c.getArgument("sourceDimension", Dimension.class); -// Dimension targetDimension = c.getArgument("targetDimension", Dimension.class); -// BlockInput filter = c.getArgument("filter", BlockInput.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(sourceDimension.id), ((CommanderCommandSource) c.getSource()).getWorld(targetDimension.id), begin, end, destination, CloneMode.NORMAL, filter); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }))) -// .then(LiteralArgumentBuilder.literal("masked") -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(), ((CommanderCommandSource) c.getSource()).getWorld(), begin, end, destination, CloneMode.NORMAL, new BlockInput(null, 0, new CompoundTag())); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }))))))))) -// .then(RequiredArgumentBuilder.argument("begin", IntegerCoordinatesArgumentType.intCoordinates()) -// .then(RequiredArgumentBuilder.argument("end", IntegerCoordinatesArgumentType.intCoordinates()) -// .then(RequiredArgumentBuilder.argument("destination", IntegerCoordinatesArgumentType.intCoordinates()) -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(), ((CommanderCommandSource) c.getSource()).getWorld(), begin, end, destination, CloneMode.NORMAL); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }) -// .then(LiteralArgumentBuilder.literal("filtered") -// .then(RequiredArgumentBuilder.argument("filter", BlockArgumentType.block()) -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// BlockInput filter = c.getArgument("filter", BlockInput.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(), ((CommanderCommandSource) c.getSource()).getWorld(), begin, end, destination, CloneMode.NORMAL, filter); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// }))) -// .then(LiteralArgumentBuilder.literal("masked") -// .executes(c -> { -// IntegerCoordinates begin = c.getArgument("begin", IntegerCoordinates.class); -// IntegerCoordinates end = c.getArgument("end", IntegerCoordinates.class); -// IntegerCoordinates destination = c.getArgument("destination", IntegerCoordinates.class); -// if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), begin, end) > 32768) throw CommanderExceptions.volumeTooLarge().create(); -// int clonedBlocks = clone((CommanderCommandSource) c.getSource(), ((CommanderCommandSource) c.getSource()).getWorld(), ((CommanderCommandSource) c.getSource()).getWorld(), begin, end, destination, CloneMode.NORMAL, new BlockInput(null, 0, new CompoundTag())); -// ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(clonedBlocks == 1 ? "commands.commander.clone.success_single" : "commands.commander.clone.success_multiple", clonedBlocks); -// return clonedBlocks; -// })))))); -// } - public static void register(CommandDispatcher commandDispatcher) { - commandDispatcher.register((LiteralArgumentBuilder)(((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("clone") - .requires((source) -> ((CommanderCommandSource)source).hasAdmin())) + commandDispatcher.register(LiteralArgumentBuilder.literal("clone") + .requires(CommanderCommandSource::hasAdmin) .then(beginEndDestinationAndModeSuffix(c -> { return c.getSource().getWorld(); - }))) - .then(LiteralArgumentBuilder.literal("from") - .then(((RequiredArgumentBuilder)RequiredArgumentBuilder.argument("sourceDimension", DimensionArgumentType.dimension())) + })) + .then(LiteralArgumentBuilder.literal("from") + .then((RequiredArgumentBuilder.argument("sourceDimension", DimensionArgumentType.dimension())) .then(beginEndDestinationAndModeSuffix(c -> { return c.getSource().getWorld(c.getArgument("sourceDimension", Dimension.class).id); }))))); } private static ArgumentBuilder beginEndDestinationAndModeSuffix(CommandFunction, World> commandFunction) { - return RequiredArgumentBuilder.argument("begin", IntegerCoordinatesArgumentType.intCoordinates()) - .then((((RequiredArgumentBuilder)RequiredArgumentBuilder.argument("end", IntegerCoordinatesArgumentType.intCoordinates())) + return RequiredArgumentBuilder.argument("begin", IntegerCoordinatesArgumentType.intCoordinates()) + .then(RequiredArgumentBuilder.argument("end", IntegerCoordinatesArgumentType.intCoordinates()) .then(destinationAndModeSuffix(commandFunction, c -> { return c.getSource().getWorld(); - }))) - .then(LiteralArgumentBuilder.literal("to") - .then(((RequiredArgumentBuilder)RequiredArgumentBuilder.argument("targetDimension", DimensionArgumentType.dimension())) + })) + .then(LiteralArgumentBuilder.literal("to") + .then((RequiredArgumentBuilder.argument("targetDimension", DimensionArgumentType.dimension())) .then(destinationAndModeSuffix(commandFunction, c -> { return c.getSource().getWorld(c.getArgument("targetDimension", Dimension.class).id); }))))); @@ -179,42 +64,42 @@ private static WorldAndPosition getWorldAndPosition(CommandContext destinationAndModeSuffix(CommandFunction, World> commandFunction, CommandFunction, World> commandFunction2) { - CommandFunction commandFunction3 = c -> getWorldAndPosition(c, commandFunction.apply(c), "begin"); - CommandFunction commandFunction4 = c -> getWorldAndPosition(c, commandFunction.apply(c), "end"); - CommandFunction commandFunction5 = c -> getWorldAndPosition(c, commandFunction2.apply(c), "destination"); - return ((((RequiredArgumentBuilder)RequiredArgumentBuilder.argument("destination", IntegerCoordinatesArgumentType.intCoordinates()) + CommandFunction, WorldAndPosition> commandFunction3 = c -> getWorldAndPosition(c, commandFunction.apply(c), "begin"); + CommandFunction, WorldAndPosition> commandFunction4 = c -> getWorldAndPosition(c, commandFunction.apply(c), "end"); + CommandFunction, WorldAndPosition> commandFunction5 = c -> getWorldAndPosition(c, commandFunction2.apply(c), "destination"); + return RequiredArgumentBuilder.argument("destination", IntegerCoordinatesArgumentType.intCoordinates()) .executes(c -> { - return clone((CommanderCommandSource)c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), null, CloneMode.NORMAL); - })) - .then(wrapWithCloneMode(commandFunction3, commandFunction4, commandFunction5, (commandContext) -> null, ((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("replace")) + return clone(c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), null, CloneMode.NORMAL); + }) + .then(wrapWithCloneMode(commandFunction3, commandFunction4, commandFunction5, (commandContext) -> null, LiteralArgumentBuilder.literal("replace") .executes(c -> { - return clone((CommanderCommandSource)c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), null, CloneMode.NORMAL); - })))) - .then(wrapWithCloneMode(commandFunction3, commandFunction4, commandFunction5, commandContext -> new BlockInput(null, 0, new CompoundTag()), ((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("masked")) + return clone(c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), null, CloneMode.NORMAL); + }))) + .then(wrapWithCloneMode(commandFunction3, commandFunction4, commandFunction5, commandContext -> new BlockInput(null, 0, new CompoundTag()), LiteralArgumentBuilder.literal("masked") .executes(c -> { - return clone((CommanderCommandSource)c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), new BlockInput(null, 0, new CompoundTag()), CloneMode.NORMAL); - })))) - .then(((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("filtered")) + return clone(c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), new BlockInput(null, 0, new CompoundTag()), CloneMode.NORMAL); + }))) + .then(LiteralArgumentBuilder.literal("filtered") .then(wrapWithCloneMode(commandFunction3, commandFunction4, commandFunction5, c -> { - return (BlockInput) c.getArgument("filter", BlockInput.class); - }, RequiredArgumentBuilder.argument("filter", BlockArgumentType.block()) + return c.getArgument("filter", BlockInput.class); + }, RequiredArgumentBuilder.argument("filter", BlockArgumentType.block()) .executes(c -> { - return clone((CommanderCommandSource)c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), c.getArgument("filter", BlockInput.class), CloneMode.NORMAL); + return clone(c.getSource(), commandFunction3.apply(c), commandFunction4.apply(c), commandFunction5.apply(c), c.getArgument("filter", BlockInput.class), CloneMode.NORMAL); })))); } - private static ArgumentBuilder wrapWithCloneMode(CommandFunction commandFunction, CommandFunction commandFunction2, CommandFunction commandFunction3, CommandFunction commandFunction4, ArgumentBuilder argumentBuilder) { - return argumentBuilder.then(LiteralArgumentBuilder.literal("force") + private static ArgumentBuilder wrapWithCloneMode(CommandFunction, WorldAndPosition> commandFunction, CommandFunction, WorldAndPosition> commandFunction2, CommandFunction, WorldAndPosition> commandFunction3, CommandFunction, BlockInput> commandFunction4, ArgumentBuilder argumentBuilder) { + return argumentBuilder.then(LiteralArgumentBuilder.literal("force") .executes(c -> { - return clone((CommanderCommandSource)c.getSource(), commandFunction.apply(c), commandFunction2.apply(c), commandFunction3.apply(c), commandFunction4.apply(c), CloneMode.FORCE); + return clone(c.getSource(), commandFunction.apply(c), commandFunction2.apply(c), commandFunction3.apply(c), commandFunction4.apply(c), CloneMode.FORCE); })) - .then(LiteralArgumentBuilder.literal("move") + .then(LiteralArgumentBuilder.literal("move") .executes(c -> { - return clone((CommanderCommandSource)c.getSource(), commandFunction.apply(c), commandFunction2.apply(c), commandFunction3.apply(c), commandFunction4.apply(c), CloneMode.MOVE); + return clone(c.getSource(), commandFunction.apply(c), commandFunction2.apply(c), commandFunction3.apply(c), commandFunction4.apply(c), CloneMode.MOVE); })) - .then(LiteralArgumentBuilder.literal("normal") + .then(LiteralArgumentBuilder.literal("normal") .executes(c -> { - return clone((CommanderCommandSource)c.getSource(), commandFunction.apply(c), commandFunction2.apply(c), commandFunction3.apply(c), commandFunction4.apply(c), CloneMode.NORMAL); + return clone(c.getSource(), commandFunction.apply(c), commandFunction2.apply(c), commandFunction3.apply(c), commandFunction4.apply(c), CloneMode.NORMAL); })); } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/FillCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/FillCommand.java index 1db763f..3274e9e 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/FillCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/FillCommand.java @@ -16,82 +16,81 @@ import net.pedroricardo.commander.content.helpers.IntegerCoordinates; import org.jetbrains.annotations.Nullable; -@SuppressWarnings("unchecked") public class FillCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("fill") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("first", IntegerCoordinatesArgumentType.intCoordinates()) - .then(RequiredArgumentBuilder.argument("second", IntegerCoordinatesArgumentType.intCoordinates()) - .then(RequiredArgumentBuilder.argument("block", BlockArgumentType.block()) + dispatcher.register(LiteralArgumentBuilder.literal("fill") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("first", IntegerCoordinatesArgumentType.intCoordinates()) + .then(RequiredArgumentBuilder.argument("second", IntegerCoordinatesArgumentType.intCoordinates()) + .then(RequiredArgumentBuilder.argument("block", BlockArgumentType.block()) .executes(c -> { IntegerCoordinates first = c.getArgument("first", IntegerCoordinates.class); IntegerCoordinates second = c.getArgument("second", IntegerCoordinates.class); BlockInput block = c.getArgument("block", BlockInput.class); - if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); - int blocksFilled = fillReplace((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), first, second, block); - ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); + if (CommanderHelper.getVolume(c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); + int blocksFilled = fillReplace(c.getSource(), c.getSource().getWorld(), first, second, block); + c.getSource().sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); return blocksFilled; }) - .then(LiteralArgumentBuilder.literal("replace") + .then(LiteralArgumentBuilder.literal("replace") .executes(c -> { IntegerCoordinates first = c.getArgument("first", IntegerCoordinates.class); IntegerCoordinates second = c.getArgument("second", IntegerCoordinates.class); BlockInput block = c.getArgument("block", BlockInput.class); - if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); - int blocksFilled = fillReplace((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), first, second, block); - ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); + if (CommanderHelper.getVolume(c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); + int blocksFilled = fillReplace(c.getSource(), c.getSource().getWorld(), first, second, block); + c.getSource().sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); return blocksFilled; }) - .then(RequiredArgumentBuilder.argument("filter", BlockArgumentType.block()) + .then(RequiredArgumentBuilder.argument("filter", BlockArgumentType.block()) .executes(c -> { IntegerCoordinates first = c.getArgument("first", IntegerCoordinates.class); IntegerCoordinates second = c.getArgument("second", IntegerCoordinates.class); BlockInput block = c.getArgument("block", BlockInput.class); BlockInput filter = c.getArgument("filter", BlockInput.class); - if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); - int blocksFilled = fillReplace((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), first, second, block, filter); - ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); + if (CommanderHelper.getVolume(c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); + int blocksFilled = fillReplace(c.getSource(), c.getSource().getWorld(), first, second, block, filter); + c.getSource().sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); return blocksFilled; }))) - .then(LiteralArgumentBuilder.literal("hollow") + .then(LiteralArgumentBuilder.literal("hollow") .executes(c -> { IntegerCoordinates first = c.getArgument("first", IntegerCoordinates.class); IntegerCoordinates second = c.getArgument("second", IntegerCoordinates.class); BlockInput block = c.getArgument("block", BlockInput.class); - if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); - int blocksFilled = fillHollow((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), first, second, block); - ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); + if (CommanderHelper.getVolume(c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); + int blocksFilled = fillHollow(c.getSource(), c.getSource().getWorld(), first, second, block); + c.getSource().sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); return blocksFilled; })) - .then(LiteralArgumentBuilder.literal("outline") + .then(LiteralArgumentBuilder.literal("outline") .executes(c -> { IntegerCoordinates first = c.getArgument("first", IntegerCoordinates.class); IntegerCoordinates second = c.getArgument("second", IntegerCoordinates.class); BlockInput block = c.getArgument("block", BlockInput.class); - if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); - int blocksFilled = fillOutline((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), first, second, block); - ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); + if (CommanderHelper.getVolume(c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); + int blocksFilled = fillOutline(c.getSource(), c.getSource().getWorld(), first, second, block); + c.getSource().sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); return blocksFilled; })) - .then(LiteralArgumentBuilder.literal("keep") + .then(LiteralArgumentBuilder.literal("keep") .executes(c -> { IntegerCoordinates first = c.getArgument("first", IntegerCoordinates.class); IntegerCoordinates second = c.getArgument("second", IntegerCoordinates.class); BlockInput block = c.getArgument("block", BlockInput.class); - if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); - int blocksFilled = fillKeep((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), first, second, block); - ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); + if (CommanderHelper.getVolume(c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); + int blocksFilled = fillKeep(c.getSource(), c.getSource().getWorld(), first, second, block); + c.getSource().sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); return blocksFilled; })) - .then(LiteralArgumentBuilder.literal("destroy") + .then(LiteralArgumentBuilder.literal("destroy") .executes(c -> { IntegerCoordinates first = c.getArgument("first", IntegerCoordinates.class); IntegerCoordinates second = c.getArgument("second", IntegerCoordinates.class); BlockInput block = c.getArgument("block", BlockInput.class); - if (CommanderHelper.getVolume((CommanderCommandSource)c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); - int blocksFilled = fillDestroy((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), first, second, block); - ((CommanderCommandSource)c.getSource()).sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); + if (CommanderHelper.getVolume(c.getSource(), first, second) > 32768) throw CommanderExceptions.volumeTooLarge().create(); + int blocksFilled = fillDestroy(c.getSource(), c.getSource().getWorld(), first, second, block); + c.getSource().sendTranslatableMessage(blocksFilled == 1 ? "commands.commander.fill.success_single" : "commands.commander.fill.success_multiple", blocksFilled); return blocksFilled; })))))); } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/GameModeCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/GameModeCommand.java index a1fd549..4bb0589 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/GameModeCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/GameModeCommand.java @@ -14,17 +14,17 @@ import net.pedroricardo.commander.content.arguments.GameModeArgumentType; import net.pedroricardo.commander.content.exceptions.CommanderExceptions; import net.pedroricardo.commander.content.helpers.EntitySelector; +import net.pedroricardo.commander.content.helpers.IntegerCoordinates; import java.util.List; -@SuppressWarnings("unchecked") public class GameModeCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("gamemode") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("gamemode", GameModeArgumentType.gameMode()) + dispatcher.register(LiteralArgumentBuilder.literal("gamemode") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("gamemode", GameModeArgumentType.gameMode()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); Gamemode gameMode = c.getArgument("gamemode", Gamemode.class); if (source.getSender() == null) { @@ -35,13 +35,13 @@ public static void register(CommandDispatcher dispatcher source.sendTranslatableMessage("commands.commander.gamemode.success_self", I18n.getInstance().translateKey(gameMode.getLanguageKey() + ".name")); return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("targets", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("targets", EntityArgumentType.players()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); Gamemode gameMode = c.getArgument("gamemode", Gamemode.class); EntitySelector entitySelector = c.getArgument("targets", EntitySelector.class); - List entities = entitySelector.get((CommanderCommandSource)c.getSource()); + List entities = entitySelector.get(c.getSource()); for (Entity entity : entities) { ((EntityPlayer)entity).setGamemode(gameMode); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/GameRuleCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/GameRuleCommand.java index 3aedb1a..ea88875 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/GameRuleCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/GameRuleCommand.java @@ -12,10 +12,9 @@ import net.pedroricardo.commander.content.CommanderCommandSource; import net.pedroricardo.commander.content.arguments.GenericGameRuleArgumentType; -@SuppressWarnings("unchecked") public class GameRuleCommand { public static void register(CommandDispatcher dispatcher) { - final LiteralArgumentBuilder argumentBuilder = (LiteralArgumentBuilder) LiteralArgumentBuilder.literal("gamerule").requires(source -> ((CommanderCommandSource)source).hasAdmin()); + final LiteralArgumentBuilder argumentBuilder = LiteralArgumentBuilder.literal("gamerule").requires(CommanderCommandSource::hasAdmin); for (final GameRule gameRule : Registries.GAME_RULES) { RequiredArgumentBuilder gameRuleValueArgument; if (gameRule instanceof GameRuleBoolean) { @@ -41,9 +40,9 @@ public static void register(CommandDispatcher dispatcher }) .then(gameRuleValueArgument)); } - CommandNode commandNode = dispatcher.register(argumentBuilder); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("gr") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + CommandNode commandNode = dispatcher.register(argumentBuilder); + dispatcher.register(LiteralArgumentBuilder.literal("gr") + .requires(CommanderCommandSource::hasAdmin) .redirect(commandNode)); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/GiveCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/GiveCommand.java index fd9c991..8625ef6 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/GiveCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/GiveCommand.java @@ -16,15 +16,14 @@ import java.util.List; -@SuppressWarnings("unchecked") public class GiveCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("give") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) - .then(RequiredArgumentBuilder.argument("item", ItemStackArgumentType.itemStack()) + dispatcher.register(LiteralArgumentBuilder.literal("give") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("item", ItemStackArgumentType.itemStack()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); ItemStack itemStack = c.getArgument("item", ItemStack.class); int amount = itemStack.stackSize; EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); @@ -45,9 +44,9 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("amount", IntegerArgumentType.integer(1, 6400)) + .then(RequiredArgumentBuilder.argument("amount", IntegerArgumentType.integer(1, 6400)) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); ItemStack itemStack = c.getArgument("item", ItemStack.class); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/HelpCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/HelpCommand.java index d081de1..126d315 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/HelpCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/HelpCommand.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.Map; -@SuppressWarnings("unchecked") public class HelpCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.help.exception_failure")); @@ -33,28 +32,31 @@ public class HelpCommand { ); public static void register(CommandDispatcher commandDispatcher) { - commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("help").executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); - Map, String> map = commandDispatcher.getSmartUsage(commandDispatcher.getRoot(), source); - if (!source.messageMayBeMultiline()) { - int index = source.getWorld().rand.nextInt(FUN.size()); - source.sendMessage("pr_ib says: " + FUN.get(index)); - return 0; - } - for (String string : map.values()) { - source.sendMessage("/" + string); - } - return map.size(); - })).then(RequiredArgumentBuilder.argument("command", StringArgumentType.greedyString()).executes(commandContext -> { - ParseResults parseResults = commandDispatcher.parse(StringArgumentType.getString(commandContext, "command"), (CommanderCommandSource)commandContext.getSource()); - if (parseResults.getContext().getNodes().isEmpty()) { - throw FAILURE.create(); - } - Map, String> map = commandDispatcher.getSmartUsage(Iterables.getLast(parseResults.getContext().getNodes()).getNode(), (CommanderCommandSource)commandContext.getSource()); - for (String string : map.values()) { - ((CommanderCommandSource)commandContext.getSource()).sendMessage("/" + parseResults.getReader().getString() + " " + string); - } - return map.size(); - }))); + commandDispatcher.register(LiteralArgumentBuilder.literal("help") + .executes(c -> { + CommanderCommandSource source = c.getSource(); + Map, String> map = commandDispatcher.getSmartUsage(commandDispatcher.getRoot(), source); + if (!source.messageMayBeMultiline()) { + int index = source.getWorld().rand.nextInt(FUN.size()); + source.sendMessage("pr_ib says: " + FUN.get(index)); + return 0; + } + for (String string : map.values()) { + source.sendMessage("/" + string); + } + return map.size(); + }) + .then(RequiredArgumentBuilder.argument("command", StringArgumentType.greedyString()) + .executes(commandContext -> { + ParseResults parseResults = commandDispatcher.parse(StringArgumentType.getString(commandContext, "command"), commandContext.getSource()); + if (parseResults.getContext().getNodes().isEmpty()) { + throw FAILURE.create(); + } + Map, String> map = commandDispatcher.getSmartUsage(Iterables.getLast(parseResults.getContext().getNodes()).getNode(), commandContext.getSource()); + for (String string : map.values()) { + commandContext.getSource().sendMessage("/" + parseResults.getReader().getString() + " " + string); + } + return map.size(); + }))); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/KillCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/KillCommand.java index a889b23..8e321ba 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/KillCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/KillCommand.java @@ -17,15 +17,14 @@ import java.util.concurrent.CopyOnWriteArrayList; -@SuppressWarnings("unchecked") public class KillCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.kill.exception_failure")); public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("kill") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("kill") + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntityPlayer sender = source.getSender(); if (sender == null) throw CommanderExceptions.notInWorld().create(); @@ -36,9 +35,9 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("entities", EntityArgumentType.entities()) + .then(RequiredArgumentBuilder.argument("entities", EntityArgumentType.entities()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("entities", EntitySelector.class); CopyOnWriteArrayList entities = new CopyOnWriteArrayList<>(entitySelector.get(source)); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/MessageCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/MessageCommand.java index 6b139ba..d58eb0a 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/MessageCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/MessageCommand.java @@ -18,14 +18,13 @@ import java.util.List; -@SuppressWarnings("unchecked") public class MessageCommand { public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("message") - .then(RequiredArgumentBuilder.argument("targets", EntityArgumentType.players()) - .then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()) + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("message") + .then(RequiredArgumentBuilder.argument("targets", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("targets", EntitySelector.class); String message = c.getArgument("message", String.class); @@ -40,11 +39,11 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; })))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("msg") + dispatcher.register(LiteralArgumentBuilder.literal("msg") .redirect(command)); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("whisper") + dispatcher.register(LiteralArgumentBuilder.literal("whisper") .redirect(command)); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("tell") + dispatcher.register(LiteralArgumentBuilder.literal("tell") .redirect(command)); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/PlaceCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/PlaceCommand.java index 9b08a7c..924365b 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/PlaceCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/PlaceCommand.java @@ -16,17 +16,16 @@ import net.pedroricardo.commander.content.exceptions.CommanderExceptions; import net.pedroricardo.commander.content.helpers.IntegerCoordinates; -@SuppressWarnings("unchecked") public class PlaceCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.place.exception_failure")); public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("place") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then((RequiredArgumentBuilder) RequiredArgumentBuilder.argument("feature", WorldFeatureArgumentType.worldFeature()) - .then((RequiredArgumentBuilder) RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("place") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("feature", WorldFeatureArgumentType.worldFeature()) + .then(RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); WorldFeature feature = c.getArgument("feature", WorldFeature.class); IntegerCoordinates coordinates = c.getArgument("position", IntegerCoordinates.class); World world = source.getWorld(); @@ -48,11 +47,11 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("generate") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("generate") + .requires(CommanderCommandSource::hasAdmin) .redirect(command)); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("gen") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("gen") + .requires(CommanderCommandSource::hasAdmin) .redirect(command)); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/SeedCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/SeedCommand.java index 87bbf78..47cc22b 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SeedCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SeedCommand.java @@ -5,13 +5,12 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.pedroricardo.commander.content.CommanderCommandSource; -@SuppressWarnings("unchecked") public class SeedCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("seed") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("seed") + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); source.sendTranslatableMessage("commands.commander.seed.success", source.getWorld().getRandomSeed()); return Command.SINGLE_SUCCESS; }) diff --git a/src/main/java/net/pedroricardo/commander/content/commands/SetBlockCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/SetBlockCommand.java index d1adfdc..3bfdcff 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SetBlockCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SetBlockCommand.java @@ -17,17 +17,16 @@ import java.util.Map; -@SuppressWarnings("unchecked") public class SetBlockCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.setblock.exception_failure")); public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("setblock") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) - .then(RequiredArgumentBuilder.argument("block", BlockArgumentType.block()) + dispatcher.register(LiteralArgumentBuilder.literal("setblock") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) + .then(RequiredArgumentBuilder.argument("block", BlockArgumentType.block()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); IntegerCoordinates coordinates = c.getArgument("position", IntegerCoordinates.class); BlockInput blockInput = c.getArgument("block", BlockInput.class); World world = source.getWorld(); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/SetSpawnCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/SetSpawnCommand.java index 2d63df1..1a0d12f 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SetSpawnCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SetSpawnCommand.java @@ -10,14 +10,13 @@ import net.pedroricardo.commander.content.arguments.IntegerCoordinatesArgumentType; import net.pedroricardo.commander.content.helpers.IntegerCoordinates; -@SuppressWarnings("unchecked") public class SetSpawnCommand { public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("setworldspawn") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("setworldspawn") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); IntegerCoordinates coordinates = c.getArgument("position", IntegerCoordinates.class); int x = coordinates.getX(source); @@ -29,8 +28,8 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("setspawn") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("setspawn") + .requires(CommanderCommandSource::hasAdmin) .redirect(command)); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java index 203b7c4..e82645f 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java @@ -17,13 +17,12 @@ import java.util.List; -@SuppressWarnings("unchecked") public class SpawnCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("spawn") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("spawn") + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntityPlayer sender = source.getSender(); World world = source.getWorld(0); ChunkCoordinates spawnCoordinates = world.getSpawnPoint(); @@ -35,9 +34,9 @@ public static void register(CommandDispatcher dispatcher source.sendTranslatableMessage("commands.commander.spawn.success"); return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("players", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("players", EntityArgumentType.players()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntityPlayer sender = source.getSender(); World world = source.getWorld(0); ChunkCoordinates spawnCoordinates = world.getSpawnPoint(); @@ -56,9 +55,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("get") + .then(LiteralArgumentBuilder.literal("get") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); ChunkCoordinates spawnCoordinates = source.getWorld(0).getSpawnPoint(); source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.spawn.get", spawnCoordinates.x, spawnCoordinates.y, spawnCoordinates.z)); return Command.SINGLE_SUCCESS; diff --git a/src/main/java/net/pedroricardo/commander/content/commands/SummonCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/SummonCommand.java index 888e65f..44c5e8a 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SummonCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SummonCommand.java @@ -16,16 +16,15 @@ import net.pedroricardo.commander.content.exceptions.CommanderExceptions; import net.pedroricardo.commander.content.helpers.DoubleCoordinates; -@SuppressWarnings("unchecked") public class SummonCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("summon") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("entity", EntitySummonArgumentType.entity()) + dispatcher.register(LiteralArgumentBuilder.literal("summon") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.>argument("entity", EntitySummonArgumentType.entity()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); Vec3d coordinates = source.getCoordinates(false); - if (coordinates == null) throw CommanderExceptions.notInWorld().create(); + if (source.getSender() == null || coordinates == null) throw CommanderExceptions.notInWorld().create(); Entity entity = summonEntityAt(c, coordinates.xCoord, coordinates.yCoord - source.getSender().heightOffset, coordinates.zCoord, 0.0f, 0.0f); @@ -33,9 +32,9 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) + .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); DoubleCoordinates coordinates = c.getArgument("position", DoubleCoordinates.class); Entity entity = summonEntityAt(c, coordinates.getX(source), coordinates.getY(source, true), coordinates.getZ(source), 0.0f, 0.0f); @@ -44,9 +43,9 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("amount", IntegerArgumentType.integer(1, 255)) + .then(RequiredArgumentBuilder.argument("amount", IntegerArgumentType.integer(1, 255)) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); DoubleCoordinates coordinates = c.getArgument("position", DoubleCoordinates.class); int amount = c.getArgument("amount", Integer.class); @@ -60,17 +59,18 @@ public static void register(CommandDispatcher dispatcher }))))); } - private static Entity summonEntityAt(CommandContext c, double x, double y, double z, float yaw, float pitch) { + @SuppressWarnings({"SameParameterValue", "unchecked"}) + private static Entity summonEntityAt(CommandContext c, double x, double y, double z, float yaw, float pitch) { Class entityClass = c.getArgument("entity", Class.class); Entity entity; try { - entity = entityClass.getConstructor(World.class).newInstance(((CommanderCommandSource)c.getSource()).getWorld()); + entity = entityClass.getConstructor(World.class).newInstance(c.getSource().getWorld()); } catch (Exception e) { throw new RuntimeException(e); } entity.spawnInit(); entity.moveTo(x, y, z, yaw, pitch); - ((CommanderCommandSource)c.getSource()).getWorld().entityJoinedWorld(entity); + c.getSource().getWorld().entityJoinedWorld(entity); return entity; } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/TeleportCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/TeleportCommand.java index da12744..80ad5f6 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/TeleportCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/TeleportCommand.java @@ -16,14 +16,13 @@ import java.util.List; -@SuppressWarnings("unchecked") public class TeleportCommand { public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("teleport") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("teleport") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); DoubleCoordinates targetCoordinates = c.getArgument("position", DoubleCoordinates.class); if (source.getSender() != null) { @@ -35,10 +34,10 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; })) - .then(RequiredArgumentBuilder.argument("entity", EntityArgumentType.entities()) - .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) + .then(RequiredArgumentBuilder.argument("entity", EntityArgumentType.entities()) + .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("entity", EntitySelector.class); DoubleCoordinates targetCoordinates = c.getArgument("position", DoubleCoordinates.class); @@ -56,14 +55,14 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; })) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.entity()) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.entity()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("entity", EntitySelector.class); EntitySelector targetEntitySelector = c.getArgument("target", EntitySelector.class); - Entity targetEntity = targetEntitySelector.get((CommanderCommandSource) c.getSource()).get(0); + Entity targetEntity = targetEntitySelector.get(c.getSource()).get(0); - List entities = entitySelector.get((CommanderCommandSource) c.getSource()); + List entities = entitySelector.get(c.getSource()); for (Entity entity : entities) { entity.moveTo(targetEntity.x, targetEntity.y - targetEntity.heightOffset, targetEntity.z, entity.yRot, entity.xRot); } @@ -73,8 +72,8 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; })))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("tp") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("tp") + .requires(CommanderCommandSource::hasAdmin) .redirect(command)); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/TimeCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/TimeCommand.java index e075a58..dcb8143 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/TimeCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/TimeCommand.java @@ -9,69 +9,68 @@ import net.pedroricardo.commander.content.CommanderCommandSource; import net.pedroricardo.commander.content.arguments.TimeArgumentType; -@SuppressWarnings("unchecked") public class TimeCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("time") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(LiteralArgumentBuilder.literal("query") - .then(LiteralArgumentBuilder.literal("daytime") + dispatcher.register(LiteralArgumentBuilder.literal("time") + .requires(CommanderCommandSource::hasAdmin) + .then(LiteralArgumentBuilder.literal("query") + .then(LiteralArgumentBuilder.literal("daytime") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); - source.sendTranslatableMessage("commands.commander.time.query", ((CommanderCommandSource)c.getSource()).getWorld().getWorldTime() % 24000L); + CommanderCommandSource source = c.getSource(); + source.sendTranslatableMessage("commands.commander.time.query", c.getSource().getWorld().getWorldTime() % 24000L); return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("gametime") + .then(LiteralArgumentBuilder.literal("gametime") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); source.sendTranslatableMessage("commands.commander.time.query", source.getWorld().getWorldTime() % Integer.MAX_VALUE); return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("day") + .then(LiteralArgumentBuilder.literal("day") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); - source.sendTranslatableMessage("commands.commander.time.query", (int) Math.floor(source.getWorld().getWorldTime() / 24000L % Integer.MAX_VALUE)); + CommanderCommandSource source = c.getSource(); + source.sendTranslatableMessage("commands.commander.time.query", source.getWorld().getWorldTime() / 24000L % Integer.MAX_VALUE); return Command.SINGLE_SUCCESS; }))) - .then(LiteralArgumentBuilder.literal("set") - .then(RequiredArgumentBuilder.argument("time", TimeArgumentType.time()) + .then(LiteralArgumentBuilder.literal("set") + .then(RequiredArgumentBuilder.argument("time", TimeArgumentType.time()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); int time = c.getArgument("time", Integer.class); setWorldTime(source, source.getWorld(), time); return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("day") + .then(LiteralArgumentBuilder.literal("day") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); setDayTime(source, source.getWorld(), 1000); return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("noon") + .then(LiteralArgumentBuilder.literal("noon") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); setDayTime(source, source.getWorld(), 6000); return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("night") + .then(LiteralArgumentBuilder.literal("night") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); setDayTime(source, source.getWorld(), 13000); return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("midnight") + .then(LiteralArgumentBuilder.literal("midnight") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); setDayTime(source, source.getWorld(), 18000); return Command.SINGLE_SUCCESS; }))) - .then(LiteralArgumentBuilder.literal("add") - .then(RequiredArgumentBuilder.argument("time", TimeArgumentType.time()) + .then(LiteralArgumentBuilder.literal("add") + .then(RequiredArgumentBuilder.argument("time", TimeArgumentType.time()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); int time = c.getArgument("time", Integer.class); addWorldTime(source, source.getWorld(), time); return Command.SINGLE_SUCCESS; diff --git a/src/main/java/net/pedroricardo/commander/content/commands/WeatherCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/WeatherCommand.java index ce799ca..0a4e042 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/WeatherCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/WeatherCommand.java @@ -12,14 +12,13 @@ import net.pedroricardo.commander.content.arguments.TimeArgumentType; import net.pedroricardo.commander.content.arguments.WeatherArgumentType; -@SuppressWarnings("unchecked") public class WeatherCommand { public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("weather") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("weather", WeatherArgumentType.weather()) + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("weather") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("weather", WeatherArgumentType.weather()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); World world = source.getWorld(); Weather weather = c.getArgument("weather", Weather.class); @@ -27,9 +26,9 @@ public static void register(CommandDispatcher dispatcher source.sendTranslatableMessage("commands.commander.weather.success", weather.getTranslatedName()); return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("duration", TimeArgumentType.time()) + .then(RequiredArgumentBuilder.argument("duration", TimeArgumentType.time()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); World world = source.getWorld(); Weather weather = c.getArgument("weather", Weather.class); @@ -37,9 +36,9 @@ public static void register(CommandDispatcher dispatcher source.sendTranslatableMessage("commands.commander.weather.success", weather.getTranslatedName()); return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("power", FloatArgumentType.floatArg()) + .then(RequiredArgumentBuilder.argument("power", FloatArgumentType.floatArg()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); World world = source.getWorld(); Weather weather = c.getArgument("weather", Weather.class); @@ -47,8 +46,8 @@ public static void register(CommandDispatcher dispatcher source.sendTranslatableMessage("commands.commander.weather.success", weather.getTranslatedName()); return Command.SINGLE_SUCCESS; }))))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("w") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("w") + .requires(CommanderCommandSource::hasAdmin) .redirect(command)); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/ColorCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/ColorCommand.java index 33fe4bf..45fdf8f 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/ColorCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/ColorCommand.java @@ -19,13 +19,12 @@ import java.util.List; -@SuppressWarnings("unchecked") public class ColorCommand { public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("color") - .then(LiteralArgumentBuilder.literal("get") + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("color") + .then(LiteralArgumentBuilder.literal("get") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); EntityPlayerMP player = (EntityPlayerMP) source.getSender(); @@ -35,9 +34,9 @@ public static void register(CommandDispatcher dispatcher source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.color.get.success", color + color.getNames()[0])); return Command.SINGLE_SUCCESS; }) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); @@ -47,92 +46,92 @@ public static void register(CommandDispatcher dispatcher source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.color.get.success_other", color + color.getNames()[0])); return Command.SINGLE_SUCCESS; }))) - .then(LiteralArgumentBuilder.literal("set") - .then(LiteralArgumentBuilder.literal("white") + .then(LiteralArgumentBuilder.literal("set") + .then(LiteralArgumentBuilder.literal("white") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 0); })) - .then(LiteralArgumentBuilder.literal("orange") + .then(LiteralArgumentBuilder.literal("orange") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 1); })) - .then(LiteralArgumentBuilder.literal("magenta") + .then(LiteralArgumentBuilder.literal("magenta") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 2); })) - .then(LiteralArgumentBuilder.literal("light_blue") + .then(LiteralArgumentBuilder.literal("light_blue") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 3); })) - .then(LiteralArgumentBuilder.literal("yellow") + .then(LiteralArgumentBuilder.literal("yellow") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 4); })) - .then(LiteralArgumentBuilder.literal("lime") + .then(LiteralArgumentBuilder.literal("lime") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 5); })) - .then(LiteralArgumentBuilder.literal("pink") + .then(LiteralArgumentBuilder.literal("pink") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 6); })) - .then(LiteralArgumentBuilder.literal("gray") + .then(LiteralArgumentBuilder.literal("gray") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 7); })) - .then(LiteralArgumentBuilder.literal("light_gray") + .then(LiteralArgumentBuilder.literal("light_gray") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 8); })) - .then(LiteralArgumentBuilder.literal("cyan") + .then(LiteralArgumentBuilder.literal("cyan") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 9); })) - .then(LiteralArgumentBuilder.literal("purple") + .then(LiteralArgumentBuilder.literal("purple") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 10); })) - .then(LiteralArgumentBuilder.literal("blue") + .then(LiteralArgumentBuilder.literal("blue") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 11); })) - .then(LiteralArgumentBuilder.literal("brown") + .then(LiteralArgumentBuilder.literal("brown") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 12); })) - .then(LiteralArgumentBuilder.literal("green") + .then(LiteralArgumentBuilder.literal("green") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 13); })) - .then(LiteralArgumentBuilder.literal("red") + .then(LiteralArgumentBuilder.literal("red") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 14); })) - .then(LiteralArgumentBuilder.literal("black") + .then(LiteralArgumentBuilder.literal("black") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setColor((EntityPlayerMP) source.getSender(), source, (byte) 15); })) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(LiteralArgumentBuilder.literal("white") + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) + .requires(CommanderCommandSource::hasAdmin) + .then(LiteralArgumentBuilder.literal("white") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -140,9 +139,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("orange") + .then(LiteralArgumentBuilder.literal("orange") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -150,9 +149,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("magenta") + .then(LiteralArgumentBuilder.literal("magenta") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -160,9 +159,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("light_blue") + .then(LiteralArgumentBuilder.literal("light_blue") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -170,9 +169,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("yellow") + .then(LiteralArgumentBuilder.literal("yellow") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -180,9 +179,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("lime") + .then(LiteralArgumentBuilder.literal("lime") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -190,9 +189,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("pink") + .then(LiteralArgumentBuilder.literal("pink") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -200,9 +199,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("gray") + .then(LiteralArgumentBuilder.literal("gray") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -210,9 +209,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("light_gray") + .then(LiteralArgumentBuilder.literal("light_gray") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -220,9 +219,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("cyan") + .then(LiteralArgumentBuilder.literal("cyan") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -230,9 +229,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("purple") + .then(LiteralArgumentBuilder.literal("purple") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -240,9 +239,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("blue") + .then(LiteralArgumentBuilder.literal("blue") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -250,9 +249,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("brown") + .then(LiteralArgumentBuilder.literal("brown") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -260,9 +259,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("green") + .then(LiteralArgumentBuilder.literal("green") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -270,9 +269,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("red") + .then(LiteralArgumentBuilder.literal("red") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -280,9 +279,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; })) - .then(LiteralArgumentBuilder.literal("black") + .then(LiteralArgumentBuilder.literal("black") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); for (Entity entity : entities) { @@ -290,7 +289,7 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; }))))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("colour") + dispatcher.register(LiteralArgumentBuilder.literal("colour") .redirect(command)); } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/DeopCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/DeopCommand.java index 3352ffc..7301793 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/DeopCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/DeopCommand.java @@ -18,16 +18,15 @@ import java.util.List; -@SuppressWarnings("unchecked") public class DeopCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.deop.exception_failure")); public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("deop") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) + dispatcher.register(LiteralArgumentBuilder.literal("deop") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/DifficultyCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/DifficultyCommand.java index d6b5d71..aabacb6 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/DifficultyCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/DifficultyCommand.java @@ -14,13 +14,12 @@ import java.util.Arrays; import java.util.List; -@SuppressWarnings("unchecked") public class DifficultyCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("difficulty") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("difficulty") + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); switch (source.getWorld().difficultySetting) { case 0: source.sendTranslatableMessage("commands.commander.difficulty.query.success", I18n.getInstance().translateKey("options.difficulty.peaceful")); @@ -40,24 +39,24 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; }) - .then(LiteralArgumentBuilder.literal("peaceful") + .then(LiteralArgumentBuilder.literal("peaceful") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setDifficulty(source, 0); })) - .then(LiteralArgumentBuilder.literal("easy") + .then(LiteralArgumentBuilder.literal("easy") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setDifficulty(source, 1); })) - .then(LiteralArgumentBuilder.literal("normal") + .then(LiteralArgumentBuilder.literal("normal") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setDifficulty(source, 2); })) - .then(LiteralArgumentBuilder.literal("hard") + .then(LiteralArgumentBuilder.literal("hard") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); return setDifficulty(source, 3); }))); } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/EmotesCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/EmotesCommand.java index 668fa24..51aaa40 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/EmotesCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/EmotesCommand.java @@ -1,26 +1,19 @@ package net.pedroricardo.commander.content.commands.server; -import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; import net.minecraft.core.net.command.TextFormatting; import net.minecraft.server.net.ChatEmotes; import net.pedroricardo.commander.content.CommanderCommandSource; -import net.pedroricardo.commander.content.IServerCommandSource; -import net.pedroricardo.commander.content.exceptions.CommanderExceptions; import java.util.ArrayList; import java.util.Map; -@SuppressWarnings("unchecked") public class EmotesCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("emotes") + dispatcher.register(LiteralArgumentBuilder.literal("emotes") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); source.sendTranslatableMessage("commands.commander.emotes.success"); ArrayList> entryList = new ArrayList>(ChatEmotes.getEmotes().entrySet()); entryList.sort(Map.Entry.comparingByKey()); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/ListCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/ListCommand.java index 4d10615..be08849 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/ListCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/ListCommand.java @@ -11,14 +11,13 @@ import net.pedroricardo.commander.content.IServerCommandSource; import net.pedroricardo.commander.content.exceptions.CommanderExceptions; -@SuppressWarnings("unchecked") public class ListCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.list.exception_failure")); public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("list") + dispatcher.register(LiteralArgumentBuilder.literal("list") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); MinecraftServer server = ((IServerCommandSource)source).getServer(); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/MeCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/MeCommand.java index 6bed9bd..759ac43 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/MeCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/MeCommand.java @@ -11,14 +11,13 @@ import net.pedroricardo.commander.content.IServerCommandSource; import net.pedroricardo.commander.content.exceptions.CommanderExceptions; -@SuppressWarnings("unchecked") public class MeCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("me") - .then(RequiredArgumentBuilder.argument("asterisk", BoolArgumentType.bool()) - .then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()) + dispatcher.register(LiteralArgumentBuilder.literal("me") + .then(RequiredArgumentBuilder.argument("asterisk", BoolArgumentType.bool()) + .then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); String message = StringArgumentType.getString(c, "message"); boolean asterisk = BoolArgumentType.getBool(c, "asterisk"); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); @@ -26,9 +25,9 @@ public static void register(CommandDispatcher dispatcher ((IServerCommandSource) source).getServer().playerList.sendEncryptedChatToAllPlayers((asterisk ? "* " : "") + senderName + message); return Command.SINGLE_SUCCESS; }))) - .then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()) + .then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); String message = StringArgumentType.getString(c, "message"); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); String senderName = source.getSender() == null ? "Server" : CommanderHelper.getEntityName(source.getSender()); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/NicknameCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/NicknameCommand.java index e2008d9..fb61c06 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/NicknameCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/NicknameCommand.java @@ -18,19 +18,18 @@ import java.util.List; -@SuppressWarnings("unchecked") public class NicknameCommand { private static final SimpleCommandExceptionType NICKNAME_TOO_LARGE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.nickname.exception_too_large")); private static final SimpleCommandExceptionType NICKNAME_TOO_SMALL = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.nickname.exception_too_small")); public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("nickname") - .then(LiteralArgumentBuilder.literal("set") - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("nickname", StringArgumentType.greedyString()) + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("nickname") + .then(LiteralArgumentBuilder.literal("set") + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("nickname", StringArgumentType.greedyString()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); String nickname = c.getArgument("nickname", String.class); if (nickname.length() > 16) throw NICKNAME_TOO_LARGE.create(); @@ -50,9 +49,9 @@ public static void register(CommandDispatcher dispatcher } return Command.SINGLE_SUCCESS; }))) - .then(RequiredArgumentBuilder.argument("nickname", StringArgumentType.greedyString()) + .then(RequiredArgumentBuilder.argument("nickname", StringArgumentType.greedyString()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); String nickname = c.getArgument("nickname", String.class); if (nickname.length() > 16) throw NICKNAME_TOO_LARGE.create(); if (nickname.isEmpty()) throw NICKNAME_TOO_SMALL.create(); @@ -69,10 +68,10 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }))) - .then(LiteralArgumentBuilder.literal("get") - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) + .then(LiteralArgumentBuilder.literal("get") + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); EntityPlayerMP player = (EntityPlayerMP) entities.get(0); @@ -80,11 +79,11 @@ public static void register(CommandDispatcher dispatcher source.sendTranslatableMessage("commands.commander.nickname.get.success", player.username, player.nickname); return Command.SINGLE_SUCCESS; }))) - .then(LiteralArgumentBuilder.literal("reset") - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + .then(LiteralArgumentBuilder.literal("reset") + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); @@ -102,7 +101,7 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; })) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntityPlayerMP player = (EntityPlayerMP) source.getSender(); @@ -116,7 +115,7 @@ public static void register(CommandDispatcher dispatcher return Command.SINGLE_SUCCESS; }))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("nick") + dispatcher.register(LiteralArgumentBuilder.literal("nick") .redirect(command)); } } diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/OpCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/OpCommand.java index 933eeed..1fe4c82 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/OpCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/OpCommand.java @@ -18,16 +18,15 @@ import java.util.List; -@SuppressWarnings("unchecked") public class OpCommand { private static final SimpleCommandExceptionType FAILURE = new SimpleCommandExceptionType(() -> I18n.getInstance().translateKey("commands.commander.op.exception_failure")); public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("op") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) + dispatcher.register(LiteralArgumentBuilder.literal("op") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/ScoreCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/ScoreCommand.java index f184bf1..702efdc 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/ScoreCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/ScoreCommand.java @@ -19,22 +19,21 @@ import java.util.List; -@SuppressWarnings("unchecked") public class ScoreCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("score") - .then(LiteralArgumentBuilder.literal("get") + dispatcher.register(LiteralArgumentBuilder.literal("score") + .then(LiteralArgumentBuilder.literal("get") .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntityPlayer player = source.getSender(); if (player == null) throw CommanderExceptions.notInWorld().create(); source.sendTranslatableMessage("commands.commander.score.get.success", player.score); return player.score; }) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); EntityPlayer player = (EntityPlayer) entitySelector.get(source).get(0); if (player == source.getSender()) { @@ -44,12 +43,12 @@ public static void register(CommandDispatcher dispatcher } return player.score; }))) - .then(LiteralArgumentBuilder.literal("set") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) - .then(RequiredArgumentBuilder.argument("score", IntegerArgumentType.integer(0, Integer.MAX_VALUE)) + .then(LiteralArgumentBuilder.literal("set") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("score", IntegerArgumentType.integer(0, Integer.MAX_VALUE)) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); int score = c.getArgument("score", Integer.class); @@ -58,12 +57,12 @@ public static void register(CommandDispatcher dispatcher } return score; })))) - .then(LiteralArgumentBuilder.literal("add") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) - .then(RequiredArgumentBuilder.argument("score", IntegerArgumentType.integer(0, Integer.MAX_VALUE)) + .then(LiteralArgumentBuilder.literal("add") + .requires(CommanderCommandSource::hasAdmin) + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.players()) + .then(RequiredArgumentBuilder.argument("score", IntegerArgumentType.integer(0, Integer.MAX_VALUE)) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); List entities = entitySelector.get(source); int score = c.getArgument("score", Integer.class); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/StopCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/StopCommand.java index e10eb92..96c0ffe 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/StopCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/StopCommand.java @@ -8,13 +8,12 @@ import net.pedroricardo.commander.content.IServerCommandSource; import net.pedroricardo.commander.content.exceptions.CommanderExceptions; -@SuppressWarnings("unchecked") public class StopCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("stop") - .requires(source -> ((CommanderCommandSource)source).hasAdmin()) + dispatcher.register(LiteralArgumentBuilder.literal("stop") + .requires(CommanderCommandSource::hasAdmin) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); if (!(source instanceof IServerCommandSource)) throw CommanderExceptions.multiplayerWorldOnly().create(); MinecraftServer server = ((IServerCommandSource)source).getServer(); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/server/WhoIsCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/server/WhoIsCommand.java index bc0df3b..2b68d81 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/server/WhoIsCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/server/WhoIsCommand.java @@ -11,20 +11,19 @@ import net.pedroricardo.commander.content.arguments.EntityArgumentType; import net.pedroricardo.commander.content.helpers.EntitySelector; -@SuppressWarnings("unchecked") public class WhoIsCommand { public static void register(CommandDispatcher dispatcher) { - CommandNode command = dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("whois") - .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) + CommandNode command = dispatcher.register(LiteralArgumentBuilder.literal("whois") + .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.player()) .executes(c -> { - CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + CommanderCommandSource source = c.getSource(); EntitySelector entitySelector = c.getArgument("target", EntitySelector.class); EntityPlayer player = (EntityPlayer) entitySelector.get(source).get(0); source.sendTranslatableMessage("commands.commander.whois.success", CommanderHelper.getEntityName(player), player.username); return Command.SINGLE_SUCCESS; }))); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("realname") + dispatcher.register(LiteralArgumentBuilder.literal("realname") .redirect(command)); } }