HubThat/src/main/java/wtf/beatrice/hubthat/commands/WorldListCommand.java

86 lines
3.7 KiB
Java
Raw Normal View History

2022-05-31 20:09:36 +02:00
package wtf.beatrice.hubthat.commands;
2020-04-09 16:31:14 +02:00
2022-05-31 20:09:36 +02:00
import wtf.beatrice.hubthat.HubThat;
import org.bukkit.Difficulty;
2020-04-09 16:31:14 +02:00
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
2022-05-31 20:09:36 +02:00
import wtf.beatrice.hubthat.utils.*;
2020-04-09 16:31:14 +02:00
import java.util.logging.Level;
public class WorldListCommand implements CommandExecutor
{
// Initialize the debugger so I can debug the plugin.
2020-05-27 00:41:02 +02:00
private final Debugger debugger = new Debugger(getClass().getName());
2020-04-09 16:31:14 +02:00
// Initialize the plugin variable so we can access all of the plugin's data.
2020-05-27 00:41:02 +02:00
private final HubThat plugin;
2020-04-09 16:31:14 +02:00
// Constructor to actually give "plugin" a value.
public WorldListCommand(HubThat givenPlugin) { plugin = givenPlugin; }
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args)
{
// Log who is using the command.
debugger.sendDebugMessage(Level.INFO, "Sender is instance of: " + commandSender.getClass().getName());
// Check if player has permission to list worlds.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.WORLD_LIST))
{
// send the translated title.
2023-02-11 20:57:11 +01:00
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.INFO_WORLDS_LIST);
2020-04-09 16:31:14 +02:00
MessageUtils.sendColorizedMessage(commandSender, "&7---------");
// Iterate through all loaded worlds.
int i = 0;
for(World currentWorld : plugin.getServer().getWorlds())
{
i++;
// Store world type and difficulty.
String worldType = currentWorld.getWorldType().getName().toLowerCase();
Difficulty difficulty = currentWorld.getDifficulty();
String worldDifficulty = difficulty.name().toLowerCase();
if(difficulty == Difficulty.PEACEFUL) worldDifficulty = "&b" + worldDifficulty;
else if(difficulty == Difficulty.EASY) worldDifficulty = "&a" + worldDifficulty;
else if(difficulty == Difficulty.NORMAL) worldDifficulty = "&e" + worldDifficulty;
else if(difficulty == Difficulty.HARD) worldDifficulty = "&c" + worldDifficulty;
2020-04-09 16:31:14 +02:00
World.Environment environment = currentWorld.getEnvironment();
String worldEnvironment = environment.name().toLowerCase();
if(environment == World.Environment.NETHER) worldEnvironment = "&c" + worldEnvironment;
else if(environment == World.Environment.THE_END) worldEnvironment = "&dend";
2020-04-09 16:31:14 +02:00
else if(environment == World.Environment.NORMAL) worldEnvironment = "&a" + worldEnvironment;
// Store player numbers.
int playersNumber = currentWorld.getPlayers().size();
2020-04-09 16:31:14 +02:00
// Send the completed message.
MessageUtils.sendColorizedMessage(commandSender, "&3" + i + "&7: &b" + currentWorld.getName() +
"&7, type: &e" + worldType + //type (flat, normal, large biomes)
"&7, pl: &e" + playersNumber + //players
"&7, diff: &e" + worldDifficulty +//difficulty (peaceful, easy, normal, hard)
"&7, env: &e" + worldEnvironment); //environment (normal, nether, the_end)
2020-04-09 16:31:14 +02:00
}
MessageUtils.sendColorizedMessage(commandSender, "&7---------");
}
else // If player doesn't have permissions...
{
// Tell him.
2023-02-11 20:57:11 +01:00
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.WORLD_LIST.permission);
2020-04-09 16:31:14 +02:00
commandSender.sendMessage(errorMessage);
}
return true;
}
}