Plex/server/src/main/java/dev/plex/command/impl/ToggleCMD.java

82 lines
3.1 KiB
Java
Raw Normal View History

2022-05-19 21:11:45 +00:00
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.menu.ToggleMenu;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component;
2022-05-19 21:32:31 +00:00
import net.kyori.adventure.text.format.NamedTextColor;
2022-05-19 21:11:45 +00:00
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles")
2022-05-19 21:11:45 +00:00
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggle", source = RequiredCommandSource.ANY)
public class ToggleCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (isConsole(sender) || playerSender == null)
{
2022-05-19 21:32:31 +00:00
if (args.length == 0)
{
sender.sendMessage(PlexUtils.mmDeserialize("<gray>Available toggles:"));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Explosions" + status("explosions")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops")));
2022-06-05 03:48:18 +00:00
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Redstone" + status("redstone")));
2022-05-19 21:32:31 +00:00
return null;
}
2022-05-19 21:11:45 +00:00
switch (args[0].toLowerCase())
{
2022-05-19 21:32:31 +00:00
case "explosions" ->
{
return toggle("explosions");
2022-05-19 21:32:31 +00:00
}
case "fluidspread" ->
2022-05-19 21:11:45 +00:00
{
return toggle("fluidspread");
2022-05-19 21:11:45 +00:00
}
2022-05-19 21:32:31 +00:00
case "drops" ->
2022-05-19 21:11:45 +00:00
{
return toggle("drops");
2022-05-19 21:11:45 +00:00
}
2022-06-05 03:48:18 +00:00
case "redstone" ->
{
return toggle("redstone");
}
2022-05-19 21:32:31 +00:00
default ->
2022-05-19 21:11:45 +00:00
{
2022-05-19 21:32:31 +00:00
return messageComponent("invalidToggle");
2022-05-19 21:11:45 +00:00
}
}
}
new ToggleMenu().openInv(playerSender, 0);
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
private String status(String toggle)
{
2022-05-19 21:32:31 +00:00
return plugin.toggles.getBoolean(toggle) ? " (enabled)" : " (disabled)";
2022-05-19 21:11:45 +00:00
}
private Component toggle(String toggle)
2022-05-19 21:11:45 +00:00
{
plugin.toggles.set(toggle, !plugin.getToggles().getBoolean(toggle));
2022-05-19 21:32:31 +00:00
return Component.text("Toggled " + toggle + status(toggle)).color(NamedTextColor.GRAY);
2022-05-19 21:11:45 +00:00
}
}