Rename main package

This commit is contained in:
Lorenzo Dellacà
2022-05-31 20:09:36 +02:00
parent ff8f52720d
commit 96f8ef153f
32 changed files with 112 additions and 113 deletions
@@ -0,0 +1,154 @@
package wtf.beatrice.hubthat.commands;
import wtf.beatrice.hubthat.HubThat;
import wtf.beatrice.hubthat.utils.*;
import wtf.beatrice.hubthat.utils.files.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.logging.Level;
public class HubCommand implements CommandExecutor
{
// Initialize the debugger so I can debug the plugin.
private static final Debugger debugger = new Debugger(HubCommand.class.getName());
// Initialize the plugin variable so we can access all of the plugin's data.
private final HubThat plugin;
// Constructor to actually give "plugin" a value.
public HubCommand(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());
// Store the commandSender name for easy access.
String username = commandSender.getName();
if(args.length > 0)
{
// Check if the player has permission to teleport to the hub.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.HUB_TELEPORT_OTHERS))
{
String teleportingPlayerName = args[0];
Player teleportingPlayer = plugin.getServer().getPlayer(teleportingPlayerName);
if(teleportingPlayer == null)
{
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_PLAYER_OFFLINE, true).replace("%player%", teleportingPlayerName);
commandSender.sendMessage(errorMessage);
return true;
}
else
{
teleportToHub(commandSender, teleportingPlayer);
return true;
}
}
else
{
// Warn the player he doesn't have permissions to teleport others to the hub.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_TELEPORT_OTHERS.permission);
commandSender.sendMessage(errorMessage);
return true;
}
}
// If the command comes from Console, stop it and give a warning.
boolean senderIsConsole = !(commandSender instanceof Player);
if(senderIsConsole)
{
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED);
return true;
}
// Check if the player has permission to teleport to the hub.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.HUB_TELEPORT))
{
// Check if the player has permission to skip the teleport delay.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.NO_HUB_DELAY))
{
teleportToHub(commandSender, (Player)commandSender);
return true;
}
// If the player doesn't have permission to skip the teleport delay...
else
{
// Check if he's not already teleporting.
if(!PluginCache.teleporting.contains(username))
{
// Put the player in the ArrayList of players waiting to be teleported.
PluginCache.teleporting.add(username);
// Load the teleportation delay.
int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntries.HUB_DELAY.path);
// Warn the player about the delay.
String delayMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_TELEPORT_DELAY, false);
delayMessage = delayMessage.replace("%delay%", delay + "");
MessageUtils.sendColorizedMessage(commandSender, delayMessage);
// Start a timer.
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
{
@Override
public void run()
{
if(!PluginCache.cancelRunnable.contains(username) && PluginCache.teleporting.contains(username))
{
teleportToHub(commandSender, (Player)commandSender);
}
PluginCache.cancelRunnable.remove(username);
}
}, delay * 20); // Convert seconds to ticks.
return true;
}
// If it's already teleporting...
else
{
// Send a message to the player stating it, and do nothing.
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_ALREADY_TELEPORTING);
return true;
}
}
}
else
{
// Warn the player he doesn't have permissions to go to the hub.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_TELEPORT.permission);
commandSender.sendMessage(errorMessage);
return true;
}
}
public static void teleportToHub(CommandSender actor, Player player, boolean sendMessage)
{
String username = player.getName();
// Teleport the player to the destination.
TeleportUtils.teleportPlayer(actor, player, FileUtils.FileType.HUB_YAML, sendMessage);
// Remove it from the "teleporting" list - so it won't get teleported if it's waiting the spawn delay.
PluginCache.teleporting.remove(username);
}
// Method to teleport the player to the hub.
public static void teleportToHub(CommandSender actor, Player player)
{
teleportToHub(actor, player, true);
}
}
@@ -0,0 +1,70 @@
package wtf.beatrice.hubthat.commands;
import wtf.beatrice.hubthat.HubThat;
import wtf.beatrice.hubthat.commands.hubthatcommands.HelpCommand;
import wtf.beatrice.hubthat.commands.hubthatcommands.ReloadCommand;
import wtf.beatrice.hubthat.utils.Debugger;
import wtf.beatrice.hubthat.utils.MessageUtils;
import wtf.beatrice.hubthat.utils.PluginCache;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.util.logging.Level;
public class HubThatCommand implements CommandExecutor
{
// Initialize the plugin variable so we can access all of the plugin's data.
private final HubThat plugin;
// Initialize the debugger so I can debug the plugin.
private final Debugger debugger = new Debugger(getClass().getName());
// Constructor to actually give "plugin" a value.
public HubThatCommand(HubThat givenPlugin)
{
plugin = givenPlugin;
}
// Override the default command. Set the instructions for this particular command (registered in the main class).
@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());
// If the command comes from Console, give a warning.
// We need no warning because this command is not player reliant.
/*boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole)
{
MessageUtils.sendLocalizedMessage(commandSender.getName(), LocalizedMessages.WARNING_CONSOLE_ACCESS);
}*/
// Check if there are any args.
if(args.length == 0)
{
MessageUtils.sendColorizedMessage(commandSender, "&6" + plugin.getName() +"&7 version &6" + plugin.getDescription().getVersion() + "&7 for &6SpigotMC/CraftBukkit &6" + PluginCache.minSupportedVersion + "&7-&6" + PluginCache.maxSupportedVersion + "&7.");
MessageUtils.sendColorizedMessage(commandSender, "&7Coded by &6" + debugger.authorName + "&7, all rights reserved (&6Copyright © '20&7).");
commandSender.sendMessage("");
MessageUtils.sendColorizedMessage(commandSender, "&7Write &6/"+ plugin.getName().toLowerCase() + " help&7 to see plugin commands.");
}
// Check if there is a single argument after the command itself.
else if (args.length == 1)
{
if(args[0].equalsIgnoreCase("help"))
{
HelpCommand.infoCommand(commandSender, plugin);
}
// Check if the args are "reload" and in case, do it.
else if(args[0].equalsIgnoreCase("reload"))
{
ReloadCommand.reloadCommand(commandSender, plugin);
}
}
return true;
}
}
@@ -0,0 +1,78 @@
package wtf.beatrice.hubthat.commands;
import wtf.beatrice.hubthat.utils.*;
import wtf.beatrice.hubthat.utils.files.FileUtils;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import java.util.logging.Level;
public class SetHubCommand implements CommandExecutor
{
// Initialize the debugger so I can debug the plugin.
private final Debugger debugger = new Debugger(getClass().getName());
@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());
// If the command comes from Console, stop it and give a warning.
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole)
{
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED);
return true;
}
// Check if the player has permission to set the hub.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.HUB_SET))
{
// Cast player to commandSender so we can get its position.
Player player = (Player)commandSender;
// Load the player's position.
Location playerLocation = player.getLocation();
double x, y, z, yaw, pitch;
String worldName;
x = playerLocation.getX();
y = playerLocation.getY();
z = playerLocation.getZ();
yaw = playerLocation.getYaw();
pitch = playerLocation.getPitch();
worldName = playerLocation.getWorld().getName();
// Set the location to the Yaml file.
FileUtils.FileType.HUB_YAML.yaml.set("hub.x", x);
FileUtils.FileType.HUB_YAML.yaml.set("hub.y", y);
FileUtils.FileType.HUB_YAML.yaml.set("hub.z", z);
FileUtils.FileType.HUB_YAML.yaml.set("hub.yaw", yaw);
FileUtils.FileType.HUB_YAML.yaml.set("hub.pitch", pitch);
FileUtils.FileType.HUB_YAML.yaml.set("hub.world", worldName);
// Save the file to the disk. We don't need to reload the Yaml file because we already set the values in the RAM.
FileUtils.saveExistingYaml(FileUtils.FileType.HUB_YAML);
// Tell the player he set the hub successfully.
String hubSetMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_HUB_SET, false);
hubSetMessage = hubSetMessage.replace("%w%", worldName);
hubSetMessage = hubSetMessage.replace("%x%", (int)x + "");
hubSetMessage = hubSetMessage.replace("%y%", (int)y + "");
hubSetMessage = hubSetMessage.replace("%z%", (int)z + "");
MessageUtils.sendColorizedMessage(commandSender, hubSetMessage);
}
else
{
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_SET.permission);
commandSender.sendMessage(errorMessage);
}
return true;
}
}
@@ -0,0 +1,127 @@
package wtf.beatrice.hubthat.commands;
import wtf.beatrice.hubthat.HubThat;
import wtf.beatrice.hubthat.utils.*;
import wtf.beatrice.hubthat.utils.files.FileUtils;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import java.util.Objects;
import java.util.logging.Level;
public class SetSpawnCommand implements CommandExecutor
{
// Initialize the debugger so I can debug the plugin.
private final Debugger debugger = new Debugger(getClass().getName());
// Initialize the plugin variable so we can access all of the plugin's data.
private final HubThat plugin;
// Constructor to actually give "plugin" a value.
public SetSpawnCommand(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());
// If the command comes from Console, stop it and give a warning.
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole)
{
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED);
return true;
}
// Check if the player has permission to set the hub.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.SPAWN_SET))
{
// Cast player to commandSender so we can get its position.
Player player = (Player)commandSender;
// Load the player's position.
Location playerLocation = player.getLocation();
double x, y, z, yaw, pitch;
String currentWorldName, worldYouAreSettingTheSpawnOf;
x = playerLocation.getX();
y = playerLocation.getY();
z = playerLocation.getZ();
yaw = playerLocation.getYaw();
pitch = playerLocation.getPitch();
// We need the world name to be non null.
currentWorldName = Objects.requireNonNull(playerLocation.getWorld()).getName();
// Check if there are any args and if they are different from the actual world.
if(args.length > 0 && !args[0].equalsIgnoreCase(currentWorldName))
{
// We need to set the world you're setting the spawn of to args[0] so we can differentiate between it and it's new spawn destination.
worldYouAreSettingTheSpawnOf = args[0];
}
// If there are no args, we are going to use the current player's world as the one with the new spawn.
else
{
worldYouAreSettingTheSpawnOf = currentWorldName;
Objects.requireNonNull(plugin.getServer().getWorld(worldYouAreSettingTheSpawnOf)).setSpawnLocation((int)x, (int)y, (int)z);
}
// If the world does not exist...
World world = plugin.getServer().getWorld(worldYouAreSettingTheSpawnOf);
if(world == null)
{
// Warn the player and stop.
// Tell the player that the world does not exist.
String errorWorldNotExistingMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, false);
errorWorldNotExistingMessage = errorWorldNotExistingMessage.replace("%w%", worldYouAreSettingTheSpawnOf);
MessageUtils.sendColorizedMessage(commandSender, errorWorldNotExistingMessage);
return true;
}
// Set the location to the Yaml file.
FileUtils.FileType.SPAWN_YAML.yaml.set("spawn.world." + worldYouAreSettingTheSpawnOf, currentWorldName);
FileUtils.FileType.SPAWN_YAML.yaml.set("spawn.x." + worldYouAreSettingTheSpawnOf, x);
FileUtils.FileType.SPAWN_YAML.yaml.set("spawn.y." + worldYouAreSettingTheSpawnOf, y);
FileUtils.FileType.SPAWN_YAML.yaml.set("spawn.z." + worldYouAreSettingTheSpawnOf, z);
FileUtils.FileType.SPAWN_YAML.yaml.set("spawn.yaw." + worldYouAreSettingTheSpawnOf, yaw);
FileUtils.FileType.SPAWN_YAML.yaml.set("spawn.pitch." + worldYouAreSettingTheSpawnOf, pitch);
// Edit the vanilla world's spawnpoint.
//world.setSpawnLocation(new Location(world, x, y, z, (float)yaw, (float)pitch));
// Save the file to the disk. We don't need to reload the Yaml file because we already set the values in the RAM.
FileUtils.saveExistingYaml(FileUtils.FileType.SPAWN_YAML);
// Tell the player he set the spawn successfully.
String spawnSetMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_SPAWN_SET, false)
.replace("%dw%", worldYouAreSettingTheSpawnOf)
.replace("%cw%", currentWorldName)
.replace("%x%", (int)x + "")
.replace("%y%", (int)y + "")
.replace("%z%", (int)z + "");
MessageUtils.sendColorizedMessage(commandSender, spawnSetMessage);
}
else
{
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_SET.permission);
commandSender.sendMessage(errorMessage);
}
return true;
}
}
@@ -0,0 +1,206 @@
package wtf.beatrice.hubthat.commands;
import wtf.beatrice.hubthat.HubThat;
import wtf.beatrice.hubthat.utils.*;
import wtf.beatrice.hubthat.utils.files.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import java.util.logging.Level;
public class SpawnCommand implements CommandExecutor
{
// Initialize the debugger so I can debug the plugin.
private static final Debugger debugger = new Debugger(SpawnCommand.class.getName());
// Initialize the plugin variable so we can access all of the plugin's data.
private final HubThat plugin;
// Constructor to actually give "plugin" a value.
public SpawnCommand(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());
// Store the commandSender name for easy access.
String username = commandSender.getName();
// If the command comes from Console, stop it and give a warning.
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole)
{
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED);
return true;
}
if(args.length > 1)
{
if(PermissionUtils.playerHasPermission(commandSender, Permissions.SPAWN_TELEPORT_OTHERS))
{
String teleportingPlayerName = args[1];
String worldName = args[0];
Player teleportPlayer = plugin.getServer().getPlayer(teleportingPlayerName);
if(teleportPlayer == null)
{
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_PLAYER_OFFLINE, true).replace("%player%", teleportingPlayerName);
commandSender.sendMessage(errorMessage);
return true;
}
if(plugin.getServer().getWorld(worldName) == null)
{
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_SPAWN_NOT_SET);
return true;
}
teleportToSpawn(commandSender, teleportPlayer, worldName);
return true;
}
else
{
// Warn the player he doesn't have permissions to teleport others to the hub.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT_OTHERS.permission);
commandSender.sendMessage(errorMessage);
return true;
}
}
// Check if the player has permission to teleport to the spawn.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.SPAWN_TELEPORT))
{
// Check if the player has permission to skip the teleport delay.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.NO_SPAWN_DELAY))
{
// Run method to check if there are any args and teleport the player accordingly.
checkArgsAndTeleport(args, commandSender);
return true;
}
else
{
// Check if he's not already teleporting.
if(!PluginCache.teleporting.contains(username))
{
if(args.length > 0)
{
if(!PermissionUtils.playerHasPermission(commandSender, Permissions.SPAWN_TELEPORT_ANOTHER_WORLD))
{
// Tell the player he has no permission to teleport to another world's spawn.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT_ANOTHER_WORLD.permission);
commandSender.sendMessage(errorMessage);
return true;
}
if(plugin.getServer().getWorld(args[0]) == null)
{
String erroMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, true).replace("%w%", args[0]);
commandSender.sendMessage(erroMessage);
return true;
}
}
// Load the teleportation delay.
int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntries.SPAWN_DELAY.path);
// Warn the player about the delay.
String delayMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_TELEPORT_DELAY, false);
delayMessage = delayMessage.replace("%delay%", delay + "");
MessageUtils.sendColorizedMessage(commandSender, delayMessage);
// Put the player in the ArrayList of players waiting to be teleported.
PluginCache.teleporting.add(username);
// Start a timer.
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,() ->
{
if(!PluginCache.cancelRunnable.contains(username) && PluginCache.teleporting.contains(username))
{
// Run method to check if there are any args and teleport the player accordingly.
checkArgsAndTeleport(args, commandSender);
}
PluginCache.cancelRunnable.remove(username);
}, delay * 20); // Convert seconds to ticks.
return true;
}
// If it's already teleporting...
else
{
// Send a message to the player stating it, and do nothing.
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_ALREADY_TELEPORTING);
return true;
}
}
}
else
{
// Warn the player he doesn't have permissions to go to the spawn.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT.permission);
commandSender.sendMessage(errorMessage);
}
return true;
}
private void checkArgsAndTeleport(String[] args, CommandSender commandSender)
{
// Make a variable for the world name.
String worldName;
// Cast player to commandSender so we can get its position.
Player player = (Player)commandSender;
String username = commandSender.getName();
// Check if there are any args.
if(args.length > 0)
{
// Set world name as args[0].
worldName = args[0];
}
else // If there are no args...
{
// Set world name as current world.
worldName = player.getWorld().getName();
}
// Teleport the player to the spawn.
teleportToSpawn(player, player, worldName);
}
// Method to teleport the player to the hub.
public static void teleportToSpawn(CommandSender sender, Player player, String worldName)
{
String username = player.getName();
// No need to check if the world is null: TeleportUtils will already handle that.
debugger.sendDebugMessage(Level.INFO, "Player name: " + username + "; World name: " + worldName);
// Teleport the player to the destination.
TeleportUtils.teleportPlayer(sender, player, FileUtils.FileType.SPAWN_YAML, worldName);
// Remove the player from the teleporting list, since it's not teleporting anymore.
// Also remove it from the "teleporting" list - so it won't get teleported if it's waiting the hub delay.
PluginCache.teleporting.remove(username);
}
}
@@ -0,0 +1,25 @@
package wtf.beatrice.hubthat.commands;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class WorldCreatorCommand implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args)
{
WorldCreator worldCreator = new WorldCreator("worldName");
worldCreator.type(WorldType.FLAT);
worldCreator.environment(World.Environment.NETHER);
worldCreator.createWorld();
return true;
}
}
@@ -0,0 +1,85 @@
package wtf.beatrice.hubthat.commands;
import wtf.beatrice.hubthat.HubThat;
import org.bukkit.Difficulty;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import wtf.beatrice.hubthat.utils.*;
import java.util.logging.Level;
public class WorldListCommand implements CommandExecutor
{
// Initialize the debugger so I can debug the plugin.
private final Debugger debugger = new Debugger(getClass().getName());
// Initialize the plugin variable so we can access all of the plugin's data.
private final HubThat plugin;
// 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.
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.INFO_WORLDS_LIST);
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;
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";
else if(environment == World.Environment.NORMAL) worldEnvironment = "&a" + worldEnvironment;
// Store player numbers.
int playersNumber = currentWorld.getPlayers().size();
// 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)
}
MessageUtils.sendColorizedMessage(commandSender, "&7---------");
}
else // If player doesn't have permissions...
{
// Tell him.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.WORLD_LIST.permission);
commandSender.sendMessage(errorMessage);
}
return true;
}
}
@@ -0,0 +1,87 @@
package wtf.beatrice.hubthat.commands;
import wtf.beatrice.hubthat.HubThat;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import wtf.beatrice.hubthat.utils.*;
import java.util.logging.Level;
import static wtf.beatrice.hubthat.utils.TeleportUtils.fixInvisibilityAfter;
import static wtf.beatrice.hubthat.utils.TeleportUtils.fixInvisibilityBefore;
public class WorldTpCommand implements CommandExecutor
{
// Initialize the debugger so I can debug the plugin.
private final Debugger debugger = new Debugger(getClass().getName());
// Initialize the plugin variable so we can access all of the plugin's data.
private final HubThat plugin;
// Constructor to actually give "plugin" a value.
public WorldTpCommand(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());
// If the command comes from Console, stop it and give a warning.
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole)
{
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED);
return true;
}
// Check if the player has permission to teleport to any world.
if(PermissionUtils.playerHasPermission(commandSender, Permissions.TELEPORT_TO_WORLD))
{
// Check if there is the correct number of args.
if(args.length != 1)
{
// Warn the player in case it's wrong.
String wrongUsageMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WRONG_USAGE, false).replace("%usage%", "/worldtp <world>");
MessageUtils.sendColorizedMessage(commandSender, wrongUsageMessage);
return true;
}
// Load the world's name from args and then the world.
String destinationWorldName = args[0];
World destinationWorld = plugin.getServer().getWorld(destinationWorldName);
// If the world does not exist, warn the player.
if(destinationWorld == null)
{
String worldDoesNotExistMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, false);
worldDoesNotExistMessage = worldDoesNotExistMessage.replace("%w%", destinationWorldName);
MessageUtils.sendColorizedMessage(commandSender, worldDoesNotExistMessage);
return true;
}
// Load the spawnpoint. This is going to be different from HubThat's spawnpoint because it could be in another world!
Location destinationLocation = new Location(destinationWorld, destinationWorld.getSpawnLocation().getX(), destinationWorld.getSpawnLocation().getY(), destinationWorld.getSpawnLocation().getZ(), destinationWorld.getSpawnLocation().getYaw(), destinationWorld.getSpawnLocation().getPitch());
// Cast Player to commandSender so we can teleport it.
Player player = (Player)commandSender;
// Teleport the Player.
fixInvisibilityBefore(destinationLocation);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.teleport(destinationLocation), 1);
fixInvisibilityAfter(player);
// Tell the player he has been teleported.
String teleportedMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_WORLDTP_TELEPORTED, false);
teleportedMessage = teleportedMessage.replace("%world%", destinationWorldName).replace("%w%", destinationWorldName);
MessageUtils.sendColorizedMessage(commandSender, teleportedMessage);
}
return true;
}
}
@@ -0,0 +1,33 @@
package wtf.beatrice.hubthat.commands.hubthatcommands;
import wtf.beatrice.hubthat.utils.LocalizedMessages;
import wtf.beatrice.hubthat.utils.MessageUtils;
import wtf.beatrice.hubthat.utils.PermissionUtils;
import wtf.beatrice.hubthat.utils.Permissions;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
public class HelpCommand
{
public static void infoCommand(CommandSender commandSender, Plugin plugin)
{
if(!PermissionUtils.playerHasPermission(commandSender, Permissions.HELP_MESSAGE))
{
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HELP_MESSAGE.permission);
commandSender.sendMessage(errorMessage);
return;
}
MessageUtils.sendColorizedMessage(commandSender, "&8---------&0[&6HubThat Help Page&0]&8---------");
MessageUtils.sendColorizedMessage(commandSender, "&6/hubthat&7: show HubThat Info");
MessageUtils.sendColorizedMessage(commandSender, "&6/hubthat help&7: show this page - &8hubthat.help");
MessageUtils.sendColorizedMessage(commandSender, "&6/hubthat reload&7: reload the config - &8hubthat.reloadconfig");
MessageUtils.sendColorizedMessage(commandSender, "&6/hub&8 [player]&7: teleport to the Hub - &8hubthat.hub");
MessageUtils.sendColorizedMessage(commandSender, "&6/spawn &8[world] [player]&7: teleport to current/another world's spawn - &8hubthat.spawn");
MessageUtils.sendColorizedMessage(commandSender, "&6/sethub&7: set the server Hub - &8hubthat.sethub");
MessageUtils.sendColorizedMessage(commandSender, "&6/setspawn &8[world]&7: set current/another world's Spawn - &8hubthat.setspawn");
MessageUtils.sendColorizedMessage(commandSender, "&6/worldlist&7: list all the worlds - &8hubthat.listworlds");
MessageUtils.sendColorizedMessage(commandSender, "&6/worldtp <world>&7: teleport to a world - &8hubthat.gotoworld");
}
}
@@ -0,0 +1,37 @@
package wtf.beatrice.hubthat.commands.hubthatcommands;
import wtf.beatrice.hubthat.HubThat;
import wtf.beatrice.hubthat.utils.*;
import wtf.beatrice.hubthat.utils.files.FileUtils;
import org.bukkit.command.CommandSender;
import java.util.logging.Level;
public class ReloadCommand
{
private static final Debugger debugger = new Debugger(ReloadCommand.class.getName());
public static void reloadCommand(CommandSender commandSender, HubThat plugin)
{
if(PermissionUtils.playerHasPermission(commandSender, Permissions.RELOAD_CONFIG))
{
debugger.sendDebugMessage(Level.INFO, "Reloading YAMLS...");
MessageUtils.sendColorizedMessage(commandSender, "&7Reloading &e" + plugin.getName() + "&7 v&e" + plugin.getDescription().getVersion() + "&7...");
FileUtils.checkFiles();
FileUtils.reloadYamls();
MessageUtils.sendColorizedMessage(commandSender, "&eReloaded!");
debugger.sendDebugMessage(Level.INFO, "Reloaded YAMLs!");
// This method checks if player has permissions, checks error codes, and acts accordingly.
plugin.updateChecker.playerMessage(commandSender);
}
else
{
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.RELOAD_CONFIG.permission);
commandSender.sendMessage(errorMessage);
}
}
}