diff --git a/plugin/src/main/java/com/alttd/essentia/commands/admin/PlayerTimeCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/admin/PlayerTimeCommand.java new file mode 100644 index 0000000..a6b97f3 --- /dev/null +++ b/plugin/src/main/java/com/alttd/essentia/commands/admin/PlayerTimeCommand.java @@ -0,0 +1,94 @@ +package com.alttd.essentia.commands.admin; + +import com.alttd.essentia.commands.EssentiaCommand; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.tree.LiteralCommandNode; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +// TODO -- output messages +public class PlayerTimeCommand implements EssentiaCommand { + + static String commandName = "playertime"; + + @Override + public @NotNull LiteralCommandNode command() { + final LiteralArgumentBuilder builder = + Commands.literal(commandName) + .requires( + commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) && + commandSourceStack.getSender() instanceof Player + ) + .then( + Commands.literal("freeze") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, player.getPlayerTime()); + + return 1; + }) + ) + .then( + Commands.literal("unfreeze") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + reset(player); + + return 1; + }) + ) + .then( + Commands.literal("day") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 1000); + + return 1; + }) + ) + .then( + Commands.literal("noon") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 6000); + + return 1; + }) + ) + .then( + Commands.literal("night") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 13000); + + return 1; + }) + ) + .then( + Commands.literal("midnight") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 18000); + + return 1; + }) + ); + return builder.build(); + } + + void reset(Player player) { + player.resetPlayerTime(); + } + + void setTime(Player player, long time) { + player.setPlayerTime(time, false); + } + + public List aliases() { + return List.of("ptime"); + } +} diff --git a/plugin/src/main/java/com/alttd/essentia/commands/admin/PlayerWeatherCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/admin/PlayerWeatherCommand.java index 0e13931..67e5c42 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/admin/PlayerWeatherCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/admin/PlayerWeatherCommand.java @@ -1,7 +1,6 @@ package com.alttd.essentia.commands.admin; import com.alttd.essentia.commands.EssentiaCommand; -import com.alttd.essentia.commands.argumement.GameModeArgument; import com.alttd.essentia.commands.argumement.WeatherArgument; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.tree.LiteralCommandNode; @@ -9,14 +8,12 @@ import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.Commands; import io.papermc.paper.command.brigadier.argument.ArgumentTypes; import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver; -import org.bukkit.GameMode; import org.bukkit.WeatherType; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.Random; // TODO -- output messages public class PlayerWeatherCommand implements EssentiaCommand { diff --git a/plugin/src/main/java/com/alttd/essentia/commands/admin/TimeCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/admin/TimeCommand.java new file mode 100644 index 0000000..b483385 --- /dev/null +++ b/plugin/src/main/java/com/alttd/essentia/commands/admin/TimeCommand.java @@ -0,0 +1,90 @@ +package com.alttd.essentia.commands.admin; + +import com.alttd.essentia.commands.EssentiaCommand; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.tree.LiteralCommandNode; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; +import org.bukkit.GameRule; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +// TODO -- output messages +public class TimeCommand implements EssentiaCommand { + + static String commandName = "time"; + + @Override + public @NotNull LiteralCommandNode command() { + final LiteralArgumentBuilder builder = + Commands.literal(commandName) + .requires( + commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) && + commandSourceStack.getSender() instanceof Player + ) + .then( + Commands.literal("freeze") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + freeze(player, true); + + return 1; + }) + ) + .then( + Commands.literal("unfreeze") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + freeze(player, false); + + return 1; + }) + ) + .then( + Commands.literal("day") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 1000); + + return 1; + }) + ) + .then( + Commands.literal("noon") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 6000); + + return 1; + }) + ) + .then( + Commands.literal("night") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 13000); + + return 1; + }) + ) + .then( + Commands.literal("midnight") + .executes(commandContext -> { + if (commandContext.getSource().getSender() instanceof Player player) + setTime(player, 18000); + + return 1; + }) + ); + return builder.build(); + } + + void freeze(Player player, boolean value) { + player.getWorld().setGameRule(GameRule.DO_DAYLIGHT_CYCLE, value); + } + + void setTime(Player player, int time) { + player.getWorld().setTime(time); + } + +} diff --git a/plugin/src/main/java/com/alttd/essentia/configuration/Config.java b/plugin/src/main/java/com/alttd/essentia/configuration/Config.java index 3038b6e..f3b7889 100755 --- a/plugin/src/main/java/com/alttd/essentia/configuration/Config.java +++ b/plugin/src/main/java/com/alttd/essentia/configuration/Config.java @@ -2,7 +2,6 @@ package com.alttd.essentia.configuration; import com.alttd.essentia.EssentiaPlugin; import com.google.common.base.Throwables; -import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration;