Add TimeCommand

This commit is contained in:
Len 2024-08-15 21:06:56 +02:00
parent a8221a68af
commit aede22811a
4 changed files with 184 additions and 4 deletions

View File

@ -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<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> 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<String> aliases() {
return List.of("ptime");
}
}

View File

@ -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 {

View File

@ -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<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> 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);
}
}

View File

@ -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;