From f90d2adfc8cadc637542a70d6ce8484c64d82403 Mon Sep 17 00:00:00 2001 From: Pedro270707 Date: Mon, 25 Sep 2023 21:06:30 -0300 Subject: [PATCH] Added /weather and /spawn --- .../net/pedroricardo/commander/Commander.java | 1 - .../content/CommanderClientCommandSource.java | 28 ++++++++ .../content/CommanderCommandManager.java | 4 +- .../content/CommanderCommandSource.java | 2 + .../CommanderConsoleCommandSource.java | 6 ++ .../content/CommanderServerCommandSource.java | 6 ++ .../arguments/WeatherArgumentType.java | 54 +++++++++++++++ .../content/commands/AchievementCommand.java | 6 +- .../content/commands/ClearCommand.java | 12 ++-- .../content/commands/GameModeCommand.java | 19 +++--- .../content/commands/KillCommand.java | 14 ++-- .../content/commands/MessageCommand.java | 11 ++- .../content/commands/SeedCommand.java | 3 +- .../content/commands/SetBlockCommand.java | 9 +-- .../content/commands/SetSpawnCommand.java | 9 +-- .../content/commands/SpawnCommand.java | 67 +++++++++++++++++++ .../content/commands/SummonCommand.java | 17 +++-- .../content/commands/TeleportCommand.java | 21 +++--- .../content/commands/TimeCommand.java | 27 +++++--- .../content/commands/WeatherCommand.java | 47 +++++++++++++ src/main/resources/lang/commander/en_US.lang | 6 ++ 21 files changed, 305 insertions(+), 64 deletions(-) create mode 100644 src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java create mode 100644 src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java create mode 100644 src/main/java/net/pedroricardo/commander/content/commands/WeatherCommand.java diff --git a/src/main/java/net/pedroricardo/commander/Commander.java b/src/main/java/net/pedroricardo/commander/Commander.java index ae10b74..b944600 100644 --- a/src/main/java/net/pedroricardo/commander/Commander.java +++ b/src/main/java/net/pedroricardo/commander/Commander.java @@ -8,7 +8,6 @@ // TODO: ChunkCoordinateArgumentType // TODO: ItemStackArgumentType // TODO: WorldFeatureArgumentType -// TODO: WeatherArgumentType public class Commander implements ModInitializer { public static final String MOD_ID = "commander"; diff --git a/src/main/java/net/pedroricardo/commander/content/CommanderClientCommandSource.java b/src/main/java/net/pedroricardo/commander/content/CommanderClientCommandSource.java index b8e9c01..eaf27c4 100644 --- a/src/main/java/net/pedroricardo/commander/content/CommanderClientCommandSource.java +++ b/src/main/java/net/pedroricardo/commander/content/CommanderClientCommandSource.java @@ -7,6 +7,7 @@ import net.minecraft.core.net.command.CommandHandler; import net.minecraft.core.net.command.CommandSender; import net.minecraft.core.util.phys.Vec3d; +import net.minecraft.core.world.Dimension; import net.minecraft.core.world.World; import net.pedroricardo.commander.Commander; import org.jetbrains.annotations.NotNull; @@ -94,6 +95,33 @@ public World getWorld(int dimension) { return this.mc.theWorld; } + public void movePlayerToDimension(EntityPlayer player, int dimension) { + Dimension lastDim = Dimension.getDimensionList().get(player.dimension); + Dimension newDim = Dimension.getDimensionList().get(dimension); + System.out.println("Switching to dimension \"" + newDim.getTranslatedName() + "\"!!"); + player.dimension = dimension; + this.mc.theWorld.setEntityDead(player); + this.mc.thePlayer.removed = false; + double x = player.x; + double y = player.y + 64; + double z = player.z; + player.moveTo(x *= Dimension.getCoordScale(lastDim, newDim), y, z *= Dimension.getCoordScale(lastDim, newDim), player.yRot, player.xRot); + if (player.isAlive()) { + this.mc.theWorld.updateEntityWithOptionalForce(player, false); + } + World world = new World(this.mc.theWorld, newDim); + if (newDim == lastDim.homeDim) { + this.mc.changeWorld(world, "Leaving " + lastDim.getTranslatedName(), player); + } else { + this.mc.changeWorld(world, "Entering " + newDim.getTranslatedName(), player); + } + player.world = this.mc.theWorld; + if (player.isAlive()) { + player.moveTo(x, y, z, player.yRot, player.xRot); + this.mc.theWorld.updateEntityWithOptionalForce(player, false); + } + } + @Override public @Deprecated CommandHandler getCommandHandler() { return this.mc.commandHandler; diff --git a/src/main/java/net/pedroricardo/commander/content/CommanderCommandManager.java b/src/main/java/net/pedroricardo/commander/content/CommanderCommandManager.java index 2cd7667..20f4067 100644 --- a/src/main/java/net/pedroricardo/commander/content/CommanderCommandManager.java +++ b/src/main/java/net/pedroricardo/commander/content/CommanderCommandManager.java @@ -29,10 +29,10 @@ public class CommanderCommandManager { SetSpawnCommand.register(DISPATCHER); TimeCommand.register(DISPATCHER); GameModeCommand.register(DISPATCHER); + WeatherCommand.register(DISPATCHER); + SpawnCommand.register(DISPATCHER); // GiveCommand.register(DISPATCHER); // HelpCommand.register(DISPATCHER); - // WeatherCommand.register(DISPATCHER); - // GamemodeCommand.register(DISPATCHER); // GenerateCommand.register(DISPATCHER); // ChunkCommand.register(DISPATCHER); diff --git a/src/main/java/net/pedroricardo/commander/content/CommanderCommandSource.java b/src/main/java/net/pedroricardo/commander/content/CommanderCommandSource.java index c322c19..88b1966 100644 --- a/src/main/java/net/pedroricardo/commander/content/CommanderCommandSource.java +++ b/src/main/java/net/pedroricardo/commander/content/CommanderCommandSource.java @@ -39,6 +39,8 @@ default Collection getEntitySuggestions() { World getWorld(int dimension); + void movePlayerToDimension(EntityPlayer player, int dimension); + @Deprecated CommandHandler getCommandHandler(); @Deprecated CommandSender getCommandSender(); diff --git a/src/main/java/net/pedroricardo/commander/content/CommanderConsoleCommandSource.java b/src/main/java/net/pedroricardo/commander/content/CommanderConsoleCommandSource.java index c9018bd..5a1b385 100644 --- a/src/main/java/net/pedroricardo/commander/content/CommanderConsoleCommandSource.java +++ b/src/main/java/net/pedroricardo/commander/content/CommanderConsoleCommandSource.java @@ -90,6 +90,12 @@ public World getWorld(int dimension) { return this.server.getWorldManager(dimension); } + @Override + public void movePlayerToDimension(EntityPlayer player, int dimension) { + if (player instanceof EntityPlayerMP) this.server.configManager.sendPlayerToOtherDimension((EntityPlayerMP) player, dimension); + throw new IllegalStateException("Player is not an instance of EntityPlayerMP"); + } + @Override public @Deprecated CommandHandler getCommandHandler() { return this.server.serverCommandHandler; diff --git a/src/main/java/net/pedroricardo/commander/content/CommanderServerCommandSource.java b/src/main/java/net/pedroricardo/commander/content/CommanderServerCommandSource.java index 18f630c..c119dc7 100644 --- a/src/main/java/net/pedroricardo/commander/content/CommanderServerCommandSource.java +++ b/src/main/java/net/pedroricardo/commander/content/CommanderServerCommandSource.java @@ -88,6 +88,12 @@ public World getWorld(int dimension) { return this.server.getWorldManager(dimension); } + @Override + public void movePlayerToDimension(EntityPlayer player, int dimension) { + if (player instanceof EntityPlayerMP) this.server.configManager.sendPlayerToOtherDimension((EntityPlayerMP) player, dimension); + throw new IllegalStateException("Player is not an instance of EntityPlayerMP"); + } + @Override public @Deprecated CommandHandler getCommandHandler() { return this.server.serverCommandHandler; diff --git a/src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java b/src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java new file mode 100644 index 0000000..abf7338 --- /dev/null +++ b/src/main/java/net/pedroricardo/commander/content/arguments/WeatherArgumentType.java @@ -0,0 +1,54 @@ +package net.pedroricardo.commander.content.arguments; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import net.minecraft.core.lang.I18n; +import net.minecraft.core.player.gamemode.Gamemode; +import net.minecraft.core.world.weather.Weather; +import net.pedroricardo.commander.CommanderHelper; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +public class WeatherArgumentType implements ArgumentType { + private static final Collection EXAMPLES = Arrays.asList(Weather.overworldClear.languageKey, Weather.overworldFog.languageKey); + + public static ArgumentType weather() { + return new WeatherArgumentType(); + } + + @Override + public Weather parse(StringReader reader) throws CommandSyntaxException { + final String string = reader.readString(); + + for (Weather weather : Weather.weatherList) { + if (weather == null) continue; + if (CommanderHelper.matchesKeyString(weather.languageKey, string)) { + return weather; + } + } + throw new CommandSyntaxException(CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument(), () -> I18n.getInstance().translateKey("argument_types.commander.weather.invalid_weather")); + } + + @Override + public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { + String remaining = builder.getRemainingLowerCase(); + for (Weather weather : Weather.weatherList) { + if (weather == null) continue; + Optional optional = CommanderHelper.getStringToSuggest(weather.languageKey, remaining); + optional.ifPresent(builder::suggest); + } + return builder.buildFuture(); + } + + @Override + public Collection getExamples() { + return EXAMPLES; + } +} 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 0988219..0ac77ad 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/AchievementCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/AchievementCommand.java @@ -32,6 +32,7 @@ public static void register(CommandDispatcher dispatcher .then(RequiredArgumentBuilder.argument("entities", EntityArgumentType.players()) .then(RequiredArgumentBuilder.argument("achievement", AchievementArgumentType.achievement()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); List entities = c.getArgument("entities", EntitySelector.class).get((CommanderCommandSource) c.getSource()); Achievement achievement = c.getArgument("achievement", Achievement.class); @@ -54,12 +55,13 @@ public static void register(CommandDispatcher dispatcher } } - sendContextualMessage((CommanderCommandSource) c.getSource(), entities, achievement); + sendContextualMessage(source, entities, achievement); return Command.SINGLE_SUCCESS; })) .then(LiteralArgumentBuilder.literal("*") .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); List entities = c.getArgument("entities", EntitySelector.class).get((CommanderCommandSource) c.getSource()); if (entities.size() == 0) { @@ -79,7 +81,7 @@ public static void register(CommandDispatcher dispatcher } } - sendWildcardContextualMessage(((CommanderCommandSource)c.getSource()), entities); + sendWildcardContextualMessage(source, entities); return Command.SINGLE_SUCCESS; })))))); 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 f75544e..31b6e68 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/ClearCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/ClearCommand.java @@ -25,19 +25,21 @@ public static void register(CommandDispatcher dispatcher dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("clear") .requires(source -> ((CommanderCommandSource)source).hasAdmin()) .executes(c -> { - if (((CommanderCommandSource)c.getSource()).getSender() == null) throw CommanderExceptions.notInWorld().create(); - + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); EntityPlayer sender = ((CommanderCommandSource)c.getSource()).getSender(); + if (sender == null) throw CommanderExceptions.notInWorld().create(); + int itemsCleared = clearItemsFromEntity(sender); - ((CommanderCommandSource) c.getSource()).sendMessage(getMessage(itemsCleared, Collections.singletonList(sender))); + source.sendMessage(getMessage(itemsCleared, Collections.singletonList(sender))); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("players", EntityArgumentType.players()) .executes(c -> { - List players = c.getArgument("players", EntitySelector.class).get(((CommanderCommandSource)c.getSource())); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + List players = c.getArgument("players", EntitySelector.class).get(source); int itemsCleared = 0; @@ -45,7 +47,7 @@ public static void register(CommandDispatcher dispatcher itemsCleared += clearItemsFromEntity((EntityPlayer)player); } - ((CommanderCommandSource) c.getSource()).sendMessage(getMessage(itemsCleared, players)); + source.sendMessage(getMessage(itemsCleared, players)); return Command.SINGLE_SUCCESS; }))); 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 f3c897d..935d827 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/GameModeCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/GameModeCommand.java @@ -24,17 +24,20 @@ public static void register(CommandDispatcher dispatcher .requires(source -> ((CommanderCommandSource)source).hasAdmin()) .then(RequiredArgumentBuilder.argument("gamemode", GameModeArgumentType.gameMode()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); Gamemode gameMode = c.getArgument("gamemode", Gamemode.class); - if (((CommanderCommandSource)c.getSource()).getSender() == null) { + if (source.getSender() == null) { throw CommanderExceptions.notInWorld().create(); } - ((CommanderCommandSource)c.getSource()).getSender().setGamemode(gameMode); - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.gamemode.success_self", I18n.getInstance().translateKey(gameMode.languageKey + ".name"))); + + source.getSender().setGamemode(gameMode); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.gamemode.success_self", I18n.getInstance().translateKey(gameMode.languageKey + ".name"))); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("targets", EntityArgumentType.players()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); Gamemode gameMode = c.getArgument("gamemode", Gamemode.class); EntitySelector entitySelector = c.getArgument("targets", EntitySelector.class); @@ -42,16 +45,16 @@ public static void register(CommandDispatcher dispatcher for (Entity entity : entities) { ((EntityPlayer)entity).setGamemode(gameMode); - if (entity != ((CommanderCommandSource)c.getSource()).getSender()) { - ((CommanderCommandSource) c.getSource()).sendMessageToPlayer((EntityPlayer) entity, I18n.getInstance().translateKey("commands.commander.gamemode.success_receiver")); + if (entity != source.getSender()) { + source.sendMessageToPlayer((EntityPlayer) entity, I18n.getInstance().translateKey("commands.commander.gamemode.success_receiver")); } } if (entities.size() == 1) { - if (entities.get(0) == ((CommanderCommandSource)c.getSource()).getSender()) { - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.gamemode.success_self", I18n.getInstance().translateKey(gameMode.languageKey + ".name"))); + if (entities.get(0) == source.getSender()) { + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.gamemode.success_self", I18n.getInstance().translateKey(gameMode.languageKey + ".name"))); } else { - ((CommanderCommandSource) c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.gamemode.success_other", CommanderHelper.getEntityName(entities.get(0)), I18n.getInstance().translateKey(gameMode.languageKey + ".name"))); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.gamemode.success_other", CommanderHelper.getEntityName(entities.get(0)), I18n.getInstance().translateKey(gameMode.languageKey + ".name"))); } } return Command.SINGLE_SUCCESS; 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 eadaffe..ca330b0 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/KillCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/KillCommand.java @@ -22,26 +22,28 @@ public static void register(CommandDispatcher dispatcher dispatcher.register((LiteralArgumentBuilder)LiteralArgumentBuilder.literal("kill") .requires(source -> ((CommanderCommandSource)source).hasAdmin()) .executes(c -> { - EntityPlayer sender = ((CommanderCommandSource)c.getSource()).getSender(); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + EntityPlayer sender = source.getSender(); if (sender == null) throw CommanderExceptions.notInWorld().create(); sender.killPlayer(); - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.kill.single_entity", sender.getDisplayName())); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.kill.single_entity", sender.getDisplayName())); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("entities", EntityArgumentType.entities()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); EntitySelector entitySelector = c.getArgument("entities", EntitySelector.class); - CopyOnWriteArrayList entities = new CopyOnWriteArrayList<>(entitySelector.get((CommanderCommandSource)c.getSource())); + CopyOnWriteArrayList entities = new CopyOnWriteArrayList<>(entitySelector.get(source)); int entityCount = entities.size(); - if (entityCount == 0) ((CommanderCommandSource)c.getSource()).sendMessage("§e" + I18n.getInstance().translateKey("commands.commander.kill.failure")); - else if (entityCount == 1) ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.kill.single_entity", CommanderHelper.getEntityName(entities.get(0)))); - else ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.kill.multiple_entities", entityCount)); + if (entityCount == 0) source.sendMessage("§e" + I18n.getInstance().translateKey("commands.commander.kill.failure")); + else if (entityCount == 1) source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.kill.single_entity", CommanderHelper.getEntityName(entities.get(0)))); + else source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.kill.multiple_entities", entityCount)); for (Entity entity : entities) { if (entity instanceof EntityPlayer) { 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 ff464eb..4c137f1 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/MessageCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/MessageCommand.java @@ -23,16 +23,17 @@ public static void register(CommandDispatcher dispatcher .then(RequiredArgumentBuilder.argument("targets", EntityArgumentType.players()) .then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); EntitySelector entitySelector = c.getArgument("targets", EntitySelector.class); String message = c.getArgument("message", String.class); - String senderName = ((CommanderCommandSource)c.getSource()).getSender() == null ? "Server" : LogPrintStream.removeColorCodes(((CommanderCommandSource)c.getSource()).getSender().getDisplayName()); + String senderName = source.getSender() == null ? "Server" : LogPrintStream.removeColorCodes(source.getSender().getDisplayName()); - List players = entitySelector.get((CommanderCommandSource) c.getSource()); + List players = entitySelector.get(source); for (Entity player : players) { - ((CommanderCommandSource)c.getSource()).sendMessage("§8§o" + I18n.getInstance().translateKeyAndFormat("commands.commander.message.outgoing", LogPrintStream.removeColorCodes(((EntityPlayer)player).getDisplayName()), message)); - ((CommanderCommandSource)c.getSource()).sendMessageToPlayer((EntityPlayer)player, "§8§o" + I18n.getInstance().translateKeyAndFormat("commands.commander.message.incoming", senderName, message)); + source.sendMessage("§8§o" + I18n.getInstance().translateKeyAndFormat("commands.commander.message.outgoing", LogPrintStream.removeColorCodes(((EntityPlayer)player).getDisplayName()), message)); + source.sendMessageToPlayer((EntityPlayer)player, "§8§o" + I18n.getInstance().translateKeyAndFormat("commands.commander.message.incoming", senderName, message)); } return Command.SINGLE_SUCCESS; @@ -41,8 +42,6 @@ public static void register(CommandDispatcher dispatcher .redirect(command)); dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("whisper") .redirect(command)); - dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("w") - .redirect(command)); dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("tell") .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 d2e715f..01e5d34 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SeedCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SeedCommand.java @@ -12,7 +12,8 @@ public static void register(CommandDispatcher dispatcher dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("seed") .requires(source -> ((CommanderCommandSource)source).hasAdmin()) .executes(c -> { - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.seed.success", ((CommanderCommandSource)c.getSource()).getWorld().getRandomSeed())); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("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 0c60f69..5584e9d 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SetBlockCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SetBlockCommand.java @@ -19,14 +19,15 @@ public static void register(CommandDispatcher dispatcher .then(RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) .then(RequiredArgumentBuilder.argument("block", BlockArgumentType.block()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); IntegerCoordinates coordinates = c.getArgument("position", IntegerCoordinates.class); Pair pair = c.getArgument("block", Pair.class); - if (!((CommanderCommandSource)c.getSource()).getWorld().isBlockLoaded(coordinates.getX((CommanderCommandSource)c.getSource()), coordinates.getY((CommanderCommandSource)c.getSource(), true), coordinates.getZ((CommanderCommandSource)c.getSource()))) { - ((CommanderCommandSource)c.getSource()).sendMessage("§e" + I18n.getInstance().translateKey("commands.commander.setblock.failure")); + if (!source.getWorld().isBlockLoaded(coordinates.getX(source), coordinates.getY(source, true), coordinates.getZ(source))) { + source.sendMessage("§e" + I18n.getInstance().translateKey("commands.commander.setblock.failure")); } else { - ((CommanderCommandSource)c.getSource()).getWorld().setBlockAndMetadataWithNotify(coordinates.getX((CommanderCommandSource)c.getSource()), coordinates.getY((CommanderCommandSource)c.getSource(), true), coordinates.getZ((CommanderCommandSource)c.getSource()), pair.getLeft().id, pair.getRight()); - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.setblock.success", coordinates.getX((CommanderCommandSource)c.getSource()), coordinates.getY((CommanderCommandSource)c.getSource(), true), coordinates.getZ((CommanderCommandSource)c.getSource()))); + source.getWorld().setBlockAndMetadataWithNotify(coordinates.getX(source), coordinates.getY(source, true), coordinates.getZ(source), pair.getLeft().id, pair.getRight()); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.setblock.success", coordinates.getX(source), coordinates.getY(source, true), coordinates.getZ(source))); } return Command.SINGLE_SUCCESS; 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 fbbbea8..b49b29b 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SetSpawnCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SetSpawnCommand.java @@ -17,13 +17,14 @@ public static void register(CommandDispatcher dispatcher .requires(source -> ((CommanderCommandSource)source).hasAdmin()) .then(RequiredArgumentBuilder.argument("position", IntegerCoordinatesArgumentType.intCoordinates()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); IntegerCoordinates coordinates = c.getArgument("position", IntegerCoordinates.class); - int x = coordinates.getX((CommanderCommandSource) c.getSource()); - int y = coordinates.getY((CommanderCommandSource) c.getSource(), true); - int z = coordinates.getZ((CommanderCommandSource) c.getSource()); + int x = coordinates.getX(source); + int y = coordinates.getY(source, true); + int z = coordinates.getZ(source); - ((CommanderCommandSource)c.getSource()).getWorld().setSpawnPoint(new ChunkCoordinates(x, y, z)); + source.getWorld().setSpawnPoint(new ChunkCoordinates(x, y, z)); return Command.SINGLE_SUCCESS; }))); diff --git a/src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java b/src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java new file mode 100644 index 0000000..7373067 --- /dev/null +++ b/src/main/java/net/pedroricardo/commander/content/commands/SpawnCommand.java @@ -0,0 +1,67 @@ +package net.pedroricardo.commander.content.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.lang.I18n; +import net.minecraft.core.world.World; +import net.minecraft.core.world.chunk.ChunkCoordinates; +import net.pedroricardo.commander.CommanderHelper; +import net.pedroricardo.commander.content.CommanderCommandSource; +import net.pedroricardo.commander.content.arguments.EntityArgumentType; +import net.pedroricardo.commander.content.exceptions.CommanderExceptions; +import net.pedroricardo.commander.content.helpers.EntitySelector; + +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()) + .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + EntityPlayer sender = source.getSender(); + World world = source.getWorld(0); + ChunkCoordinates spawnCoordinates = world.getSpawnPoint(); + + if (sender == null) throw CommanderExceptions.notInWorld().create(); + + if (sender.dimension != 0) source.movePlayerToDimension(sender, 0); + sender.absMoveTo(spawnCoordinates.x + 0.5, spawnCoordinates.y, spawnCoordinates.z + 0.5, sender.yRot, sender.xRot); + source.sendMessage(I18n.getInstance().translateKey("commands.commander.spawn.success_self")); + return Command.SINGLE_SUCCESS; + }) + .then(RequiredArgumentBuilder.argument("players", EntityArgumentType.players()) + .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + EntityPlayer sender = source.getSender(); + World world = source.getWorld(0); + ChunkCoordinates spawnCoordinates = world.getSpawnPoint(); + EntitySelector entitySelector = c.getArgument("players", EntitySelector.class); + List players = entitySelector.get(source); + + for (Entity entity : players) { + if (((EntityPlayer)entity).dimension != 0) source.movePlayerToDimension((EntityPlayer) entity, 0); + entity.absMoveTo(spawnCoordinates.x + 0.5, spawnCoordinates.y, spawnCoordinates.z + 0.5, entity.yRot, entity.xRot); + if (entity == sender) { + source.sendMessageToPlayer((EntityPlayer) entity, I18n.getInstance().translateKey("commands.commander.spawn.success_self")); + } else { + source.sendMessageToPlayer((EntityPlayer) entity, I18n.getInstance().translateKey("commands.commander.spawn.success_receiver")); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.spawn.success_other", CommanderHelper.getEntityName(entity))); + } + } + return Command.SINGLE_SUCCESS; + })) + .then(LiteralArgumentBuilder.literal("get") + .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) 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 f75e826..51b1963 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/SummonCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/SummonCommand.java @@ -24,35 +24,38 @@ public static void register(CommandDispatcher dispatcher .requires(source -> ((CommanderCommandSource)source).hasAdmin()) .then(RequiredArgumentBuilder.argument("entity", EntitySummonArgumentType.entity()) .executes(c -> { - Vec3d coordinates = ((CommanderCommandSource)c.getSource()).getCoordinates(false); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + Vec3d coordinates = source.getCoordinates(false); if (coordinates == null) throw CommanderExceptions.notInWorld().create(); - Entity entity = summonEntityAt(c, coordinates.xCoord, coordinates.yCoord - ((CommanderCommandSource)c.getSource()).getSender().heightOffset, coordinates.zCoord, 0.0f, 0.0f); + Entity entity = summonEntityAt(c, coordinates.xCoord, coordinates.yCoord - source.getSender().heightOffset, coordinates.zCoord, 0.0f, 0.0f); - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.summon.success_single_entity", CommanderHelper.getEntityName(entity))); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.summon.success_single_entity", CommanderHelper.getEntityName(entity))); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); DoubleCoordinates coordinates = c.getArgument("position", DoubleCoordinates.class); - Entity entity = summonEntityAt(c, coordinates.getX(((CommanderCommandSource)c.getSource())), coordinates.getY(((CommanderCommandSource)c.getSource()), true), coordinates.getZ(((CommanderCommandSource)c.getSource())), 0.0f, 0.0f); + Entity entity = summonEntityAt(c, coordinates.getX(source), coordinates.getY(source, true), coordinates.getZ(source), 0.0f, 0.0f); - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.summon.success_single_entity", CommanderHelper.getEntityName(entity))); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.summon.success_single_entity", CommanderHelper.getEntityName(entity))); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("amount", IntegerArgumentType.integer(1, 255)) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); DoubleCoordinates coordinates = c.getArgument("position", DoubleCoordinates.class); int amount = c.getArgument("amount", Integer.class); for (int i = 0; i < amount; i++) { - summonEntityAt(c, coordinates.getX(((CommanderCommandSource) c.getSource())), coordinates.getY(((CommanderCommandSource) c.getSource()), true), coordinates.getZ(((CommanderCommandSource) c.getSource())), 0.0f, 0.0f); + summonEntityAt(c, coordinates.getX(source), coordinates.getY(source, true), coordinates.getZ(source), 0.0f, 0.0f); } - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.summon.success_multiple_entities", amount)); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.summon.success_multiple_entities", amount)); return Command.SINGLE_SUCCESS; }))))); 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 212fea0..a9b3bc9 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/TeleportCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/TeleportCommand.java @@ -24,11 +24,12 @@ public static void register(CommandDispatcher dispatcher .requires(source -> ((CommanderCommandSource)source).hasAdmin()) .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); DoubleCoordinates targetCoordinates = c.getArgument("position", DoubleCoordinates.class); - if (((CommanderCommandSource)c.getSource()).getSender() != null) { - ((CommanderCommandSource)c.getSource()).getSender().moveTo(targetCoordinates.getX((CommanderCommandSource)c.getSource()), targetCoordinates.getY(((CommanderCommandSource) c.getSource()), true), targetCoordinates.getZ((CommanderCommandSource)c.getSource()), ((CommanderCommandSource) c.getSource()).getSender().yRot, ((CommanderCommandSource) c.getSource()).getSender().xRot); - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.location.success_single_entity", ((CommanderCommandSource)c.getSource()).getSender().getDisplayName(), targetCoordinates.getX((CommanderCommandSource)c.getSource()), targetCoordinates.getY(((CommanderCommandSource) c.getSource()), true), targetCoordinates.getZ((CommanderCommandSource)c.getSource()))); + if (source.getSender() != null) { + source.getSender().moveTo(targetCoordinates.getX(source), targetCoordinates.getY(source, true), targetCoordinates.getZ(source), source.getSender().yRot, source.getSender().xRot); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.location.success_single_entity", source.getSender().getDisplayName(), targetCoordinates.getX(source), targetCoordinates.getY(source, true), targetCoordinates.getZ(source))); } else { throw CommanderExceptions.notInWorld().create(); } @@ -38,21 +39,23 @@ public static void register(CommandDispatcher dispatcher .then(RequiredArgumentBuilder.argument("entity", EntityArgumentType.entities()) .then(RequiredArgumentBuilder.argument("position", Vec3dArgumentType.vec3d()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); EntitySelector entitySelector = c.getArgument("entity", EntitySelector.class); DoubleCoordinates targetCoordinates = c.getArgument("position", DoubleCoordinates.class); - List entities = entitySelector.get((CommanderCommandSource) c.getSource()); + List entities = entitySelector.get(source); for (Entity entity : entities) { - entity.moveTo(targetCoordinates.getX((CommanderCommandSource)c.getSource()), targetCoordinates.getY(((CommanderCommandSource) c.getSource()), true), targetCoordinates.getZ((CommanderCommandSource)c.getSource()), entity.yRot, entity.xRot); + entity.moveTo(targetCoordinates.getX(source), targetCoordinates.getY(source, true), targetCoordinates.getZ(source), entity.yRot, entity.xRot); } - if (entities.size() == 1) ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.location.success_single_entity", CommanderHelper.getEntityName(entities.get(0)), targetCoordinates.getX((CommanderCommandSource)c.getSource()), targetCoordinates.getY(((CommanderCommandSource) c.getSource()), true), targetCoordinates.getZ((CommanderCommandSource)c.getSource()))); - else if (entities.size() > 1) ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.location.success_multiple_entities", entities.size(), targetCoordinates.getX((CommanderCommandSource)c.getSource()), targetCoordinates.getY(((CommanderCommandSource) c.getSource()), true), targetCoordinates.getZ((CommanderCommandSource)c.getSource()))); + if (entities.size() == 1) source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.location.success_single_entity", CommanderHelper.getEntityName(entities.get(0)), targetCoordinates.getX(source), targetCoordinates.getY(source, true), targetCoordinates.getZ(source))); + else if (entities.size() > 1) source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.location.success_multiple_entities", entities.size(), targetCoordinates.getX(source), targetCoordinates.getY(source, true), targetCoordinates.getZ(source))); return Command.SINGLE_SUCCESS; })) .then(RequiredArgumentBuilder.argument("target", EntityArgumentType.entity()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) 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); @@ -62,8 +65,8 @@ public static void register(CommandDispatcher dispatcher entity.moveTo(targetEntity.x, targetEntity.y - targetEntity.heightOffset, targetEntity.z, entity.yRot, entity.xRot); } - if (entities.size() == 1) ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.entity.success_single_entity", CommanderHelper.getEntityName(entities.get(0)), CommanderHelper.getEntityName(targetEntity))); - else if (entities.size() > 1) ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.entity.success_multiple_entities", entities.size(), CommanderHelper.getEntityName(targetEntity))); + if (entities.size() == 1) source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.entity.success_single_entity", CommanderHelper.getEntityName(entities.get(0)), CommanderHelper.getEntityName(targetEntity))); + else if (entities.size() > 1) source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.teleport.entity.success_multiple_entities", entities.size(), CommanderHelper.getEntityName(targetEntity))); return Command.SINGLE_SUCCESS; })))); 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 7aa357c..a04cb71 100644 --- a/src/main/java/net/pedroricardo/commander/content/commands/TimeCommand.java +++ b/src/main/java/net/pedroricardo/commander/content/commands/TimeCommand.java @@ -18,54 +18,63 @@ public static void register(CommandDispatcher dispatcher .then(LiteralArgumentBuilder.literal("query") .then(LiteralArgumentBuilder.literal("daytime") .executes(c -> { - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.time.query", ((CommanderCommandSource)c.getSource()).getWorld().getWorldTime() % 24000L)); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.time.query", ((CommanderCommandSource)c.getSource()).getWorld().getWorldTime() % 24000L)); return Command.SINGLE_SUCCESS; })) .then(LiteralArgumentBuilder.literal("gametime") .executes(c -> { - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.time.query", ((CommanderCommandSource)c.getSource()).getWorld().getWorldTime() % Integer.MAX_VALUE)); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.time.query", source.getWorld().getWorldTime() % Integer.MAX_VALUE)); return Command.SINGLE_SUCCESS; })) .then(LiteralArgumentBuilder.literal("day") .executes(c -> { - ((CommanderCommandSource)c.getSource()).sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.time.query", (int) Math.floor(((CommanderCommandSource)c.getSource()).getWorld().getWorldTime() / 24000L % Integer.MAX_VALUE))); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.time.query", (int) Math.floor(source.getWorld().getWorldTime() / 24000L % Integer.MAX_VALUE))); return Command.SINGLE_SUCCESS; }))) .then(LiteralArgumentBuilder.literal("set") .then(RequiredArgumentBuilder.argument("time", TimeArgumentType.time()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); int time = c.getArgument("time", Integer.class); - setWorldTime((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), time); + setWorldTime(source, source.getWorld(), time); return Command.SINGLE_SUCCESS; })) .then(LiteralArgumentBuilder.literal("day") .executes(c -> { - setDayTime((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), 1000); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + setDayTime(source, source.getWorld(), 1000); return Command.SINGLE_SUCCESS; })) .then(LiteralArgumentBuilder.literal("noon") .executes(c -> { - setDayTime((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), 6000); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + setDayTime(source, source.getWorld(), 6000); return Command.SINGLE_SUCCESS; })) .then(LiteralArgumentBuilder.literal("night") .executes(c -> { - setDayTime((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), 13000); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + setDayTime(source, source.getWorld(), 13000); return Command.SINGLE_SUCCESS; })) .then(LiteralArgumentBuilder.literal("midnight") .executes(c -> { - setDayTime((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), 18000); + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + setDayTime(source, source.getWorld(), 18000); return Command.SINGLE_SUCCESS; }))) .then(LiteralArgumentBuilder.literal("add") .then(RequiredArgumentBuilder.argument("time", TimeArgumentType.time()) .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); int time = c.getArgument("time", Integer.class); - addWorldTime((CommanderCommandSource)c.getSource(), ((CommanderCommandSource)c.getSource()).getWorld(), time); + 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 new file mode 100644 index 0000000..d08af3a --- /dev/null +++ b/src/main/java/net/pedroricardo/commander/content/commands/WeatherCommand.java @@ -0,0 +1,47 @@ +package net.pedroricardo.commander.content.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.tree.CommandNode; +import net.minecraft.core.lang.I18n; +import net.minecraft.core.world.World; +import net.minecraft.core.world.weather.Weather; +import net.pedroricardo.commander.content.CommanderCommandSource; +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()) + .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + World world = source.getWorld(); + Weather weather = c.getArgument("weather", Weather.class); + + world.newWeather = weather; + world.weatherDuration = world.getRandomWeatherDuration(); + world.weatherIntensity = 0; + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.weather.success", weather.getTranslatedName())); + return Command.SINGLE_SUCCESS; + }) + .then(RequiredArgumentBuilder.argument("duration", TimeArgumentType.time()) + .executes(c -> { + CommanderCommandSource source = (CommanderCommandSource) c.getSource(); + World world = source.getWorld(); + Weather weather = c.getArgument("weather", Weather.class); + + world.newWeather = weather; + world.weatherDuration = c.getArgument("duration", Integer.class); + world.weatherIntensity = 0; + source.sendMessage(I18n.getInstance().translateKeyAndFormat("commands.commander.weather.success", weather.getTranslatedName())); + return Command.SINGLE_SUCCESS; + })))); + dispatcher.register((LiteralArgumentBuilder) LiteralArgumentBuilder.literal("w") + .redirect(command)); + } +} diff --git a/src/main/resources/lang/commander/en_US.lang b/src/main/resources/lang/commander/en_US.lang index cc5f033..36d3c25 100644 --- a/src/main/resources/lang/commander/en_US.lang +++ b/src/main/resources/lang/commander/en_US.lang @@ -38,6 +38,7 @@ argument_types.commander.range.swapped=Min cannot be bigger than max argument_types.commander.time.invalid_unit=Invalid unit argument_types.commander.time.tick_count_too_low=Tick count must not be less than %s, found %s argument_types.commander.game_mode.invalid_game_mode=Invalid game mode +argument_types.commander.weather.invalid_weather=Invalid weather commands.commander.time.query=The time is %s commands.commander.time.set=Set the time to %s commands.commander.achievement.grant.exception_already_has_achievement=Player already has achievement @@ -67,5 +68,10 @@ commands.commander.message.outgoing=You whisper to %s: %s commands.commander.gamemode.success_self=Set own game mode to %s commands.commander.gamemode.success_other=Set %s's game mode to %s commands.commander.gamemode.success_receiver=Your game mode has been updated +commands.commander.weather.success=Set the weather to %s +commands.commander.spawn.success_self=Teleported yourself to spawn +commands.commander.spawn.success_other=Teleported %s to spawn +commands.commander.spawn.success_receiver=You were teleported to spawn +commands.commander.spawn.get=The world's spawn point is located at %s, %s, %s argument_types.commander.incomplete=Incomplete argument argument_types.commander.not_in_world=Argument requires sender to be in world, but they are not present \ No newline at end of file