Networking rework, further refactoring

This commit is contained in:
William278 committed 2023-03-02 22:51:50 +00:00
1 parent 1cebdac9b8
commit 4c90e5498c
88 files changed
+1116 -1364

No files matched your search

@@ -1,8 +1,8 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TimedTeleport;
import net.william278.huskhomes.util.Permission;
@@ -19,7 +19,7 @@ public class BackCommand extends CommandBase {
plugin.getDatabase().getLastPosition(onlineUser).thenAccept(lastPosition ->
lastPosition.ifPresentOrElse(position -> Teleport.builder(plugin, onlineUser)
.setTarget(position)
.setEconomyActions(Settings.EconomyAction.BACK_COMMAND)
.setEconomyActions(EconomyHook.EconomyAction.BACK_COMMAND)
.toTimedTeleport()
.thenApply(TimedTeleport::execute),
() -> plugin.getLocales().getLocale("error_no_last_position").ifPresent(onlineUser::sendMessage)));
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.intellij.lang.annotations.Pattern;
import org.intellij.lang.annotations.Subst;
@@ -1,8 +1,8 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.User;
import net.william278.huskhomes.util.Permission;
import net.william278.huskhomes.util.RegexUtil;
import org.jetbrains.annotations.NotNull;
@@ -39,7 +39,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(homeIdentifier ->
plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()).thenAccept(
optionalUserData -> optionalUserData.ifPresentOrElse(userData -> {
if (!userData.getUserUuid().equals(onlineUser.uuid)) {
if (!userData.getUserUuid().equals(onlineUser.getUuid())) {
if (!onlineUser.hasPermission(Permission.COMMAND_DELETE_HOME_OTHER.node)) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(onlineUser::sendMessage);
@@ -81,14 +81,14 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(deleter::sendMessage);
} else {
if (deleted) {
plugin.getLocales().getLocale("home_deleted_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
plugin.getLocales().getLocale("home_deleted_other", homeOwner.getUsername(), homeName).ifPresent(deleter::sendMessage);
return;
}
if (homeName.equalsIgnoreCase("all")) {
deleteAllHomes(deleter, homeOwner, delHomeAllConfirm);
return;
}
plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.getUsername(), homeName).ifPresent(deleter::sendMessage);
}
});
}
@@ -126,7 +126,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
return Collections.emptyList();
}
return args.length > 1 ? Collections.emptyList() : plugin.getCache().getHomes()
.getOrDefault(user.uuid, new ArrayList<>())
.getOrDefault(user.getUuid(), new ArrayList<>())
.stream()
.filter(s -> s.startsWith(args.length == 1 ? args[0] : ""))
.sorted()
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -3,8 +3,8 @@ package net.william278.huskhomes.command;
import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.PositionMeta;
import net.william278.huskhomes.util.Permission;
@@ -37,7 +37,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(
homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName())
.thenAcceptAsync(optionalUserData -> optionalUserData.ifPresentOrElse(userData -> {
if (!userData.getUserUuid().equals(onlineUser.uuid)) {
if (!userData.getUserUuid().equals(onlineUser.getUuid())) {
if (!onlineUser.hasPermission(Permission.COMMAND_EDIT_HOME_OTHER.node)) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(onlineUser::sendMessage);
@@ -124,7 +124,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
oldHomeName, newHomeName);
} else {
yield plugin.getLocales().getLocale("edit_home_update_name_other",
home.getOwner().username, oldHomeName, newHomeName);
home.getOwner().getUsername(), oldHomeName, newHomeName);
}
}
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_home_name_taken");
@@ -149,7 +149,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
.getRawLocale("item_no_description").orElse("N/A") : newDescription);
} else {
yield plugin.getLocales().getLocale("edit_home_update_description_other",
home.getOwner().username,
home.getOwner().getUsername(),
home.getMeta().getName(),
oldHomeDescription.isBlank() ? plugin.getLocales()
.getRawLocale("item_no_description").orElse("N/A") : oldHomeDescription,
@@ -171,7 +171,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
home.getMeta().getName()).orElse(new MineDown("")));
} else {
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location_other",
home.getOwner().username, home.getMeta().getName()).orElse(new MineDown("")));
home.getOwner().getUsername(), home.getMeta().getName()).orElse(new MineDown("")));
}
// Show the menu if the menu flag is set
@@ -226,7 +226,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
}
// Check against economy
if (!plugin.validateEconomyCheck(editor, Settings.EconomyAction.MAKE_HOME_PUBLIC)) {
if (!plugin.validateEconomyCheck(editor, EconomyHook.EconomyAction.MAKE_HOME_PUBLIC)) {
return;
}
}
@@ -240,11 +240,11 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
} else {
editor.sendMessage(plugin.getLocales().getLocale(
"edit_home_privacy_" + privacyKeyedString + "_success_other",
home.getOwner().username, home.getMeta().getName()).orElse(new MineDown("")));
home.getOwner().getUsername(), home.getMeta().getName()).orElse(new MineDown("")));
}
// Perform necessary economy transaction
plugin.performEconomyTransaction(editor, Settings.EconomyAction.MAKE_HOME_PUBLIC);
plugin.performEconomyTransaction(editor, EconomyHook.EconomyAction.MAKE_HOME_PUBLIC);
// Show the menu if the menu flag is set
if (showMenuFlag.get()) {
@@ -293,7 +293,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
plugin.getLocales().getLocale("edit_home_menu_title", home.getMeta().getName())
.ifPresent(this::add);
} else {
plugin.getLocales().getLocale("edit_home_menu_title_other", home.getOwner().username, home.getMeta().getName())
plugin.getLocales().getLocale("edit_home_menu_title_other", home.getOwner().getUsername(), home.getMeta().getName())
.ifPresent(this::add);
}
}
@@ -326,7 +326,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
String.format("%.2f", home.getYaw()), String.format("%.2f", home.getPitch()))
.ifPresent(this::add);
final String formattedName = home.getOwner().username + "." + home.getMeta().getName();
final String formattedName = home.getOwner().getUsername() + "." + home.getMeta().getName();
if (showTeleportButton) {
plugin.getLocales().getLocale("edit_home_menu_use_buttons",
formattedName)
@@ -351,7 +351,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
return Collections.emptyList();
}
return switch (args.length) {
case 0, 1 -> plugin.getCache().getHomes().getOrDefault(user.uuid, new ArrayList<>())
case 0, 1 -> plugin.getCache().getHomes().getOrDefault(user.getUuid(), new ArrayList<>())
.stream()
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
.sorted()
@@ -2,7 +2,7 @@ package net.william278.huskhomes.command;
import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.position.PositionMeta;
import net.william278.huskhomes.util.Permission;
@@ -1,8 +1,8 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.User;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TimedTeleport;
@@ -74,7 +74,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
.thenAccept(TimedTeleport::execute);
}, () -> {
if (otherHome) {
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
plugin.getLocales().getLocale("error_home_invalid_other", owner.getUsername(), homeName)
.ifPresent(teleporter::sendMessage);
} else {
plugin.getLocales().getLocale("error_home_invalid", homeName)
@@ -100,7 +100,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
identifier -> matchedHome.set(plugin.getDatabase().getUserDataByName(identifier.ownerName()).join()
.flatMap(user -> plugin.getDatabase().getHome(user.user(), identifier.homeName()).join())
.orElse(null)),
() -> matchedHome.set(plugin.getDatabase().getUserDataByName(playerToTeleport.username).join()
() -> matchedHome.set(plugin.getDatabase().getUserDataByName(playerToTeleport.getUsername()).join()
.flatMap(user -> plugin.getDatabase().getHome(user.user(), args[1]).join())
.orElse(null)));
@@ -110,8 +110,8 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to "
+ home.getOwner().username + "." + home.getMeta().getName());
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to "
+ home.getOwner().getUsername() + "." + home.getMeta().getName());
Teleport.builder(plugin, playerToTeleport)
.setTarget(home)
.toTeleport()
@@ -125,7 +125,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
return Collections.emptyList();
}
return args.length > 1 ? Collections.emptyList() : plugin.getCache().getHomes()
.getOrDefault(user.uuid, new ArrayList<>())
.getOrDefault(user.getUuid(), new ArrayList<>())
.stream()
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
.sorted()
@@ -1,8 +1,8 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.UserData;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -22,11 +22,11 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
@Override
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
switch (args.length) {
case 0 -> showHomeList(onlineUser, onlineUser.username, 1);
case 0 -> showHomeList(onlineUser, onlineUser.getUsername(), 1);
case 1 -> {
try {
int pageNumber = Integer.parseInt(args[0]);
showHomeList(onlineUser, onlineUser.username, pageNumber);
showHomeList(onlineUser, onlineUser.getUsername(), pageNumber);
} catch (NumberFormatException e) {
showHomeList(onlineUser, args[0], 1);
}
@@ -58,7 +58,7 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
return;
}
plugin.getDatabase().getUserDataByName(homeOwner).thenAccept(optionalUser -> optionalUser.ifPresentOrElse(userData -> {
if (!userData.getUserUuid().equals(onlineUser.uuid)) {
if (!userData.getUserUuid().equals(onlineUser.getUuid())) {
if (!onlineUser.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
plugin.getLocales().getLocale("error_no_permission").ifPresent(onlineUser::sendMessage);
return;
@@ -98,7 +98,7 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
final List<Home> homes = plugin.getDatabase().getHomes(userData.get().user()).join();
StringJoiner rowJoiner = new StringJoiner("\t");
plugin.getLoggingAdapter().log(Level.INFO, "List of " + userData.get().user().username + "'s "
plugin.getLoggingAdapter().log(Level.INFO, "List of " + userData.get().user().getUsername() + "'s "
+ homes.size() + " homes:");
for (int i = 0; i < homes.size(); i++) {
final String home = homes.get(i).getMeta().getName();
@@ -4,7 +4,7 @@ import de.themoep.minedown.adventure.MineDown;
import net.william278.desertwell.AboutMenu;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.migrator.Migrator;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,7 +25,7 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
super("huskhomes", Permission.COMMAND_HUSKHOMES, implementor);
this.aboutMenu = AboutMenu.create("HuskHomes")
.withDescription("A powerful, intuitive and flexible teleportation suite")
.withVersion(implementor.getPluginVersion())
.withVersion(implementor.getVersion())
.addAttribution("Author",
AboutMenu.Credit.of("William278").withDescription("Click to visit website").withUrl("https://william278.net"))
.addAttribution("Contributors",
@@ -102,10 +102,10 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
newestVersion.ifPresentOrElse(
newVersion -> onlineUser.sendMessage(
new MineDown("[HuskHomes](#00fb9a bold) [| A new version of HuskHomes is available!"
+ " (v" + newVersion + " (Running: v" + plugin.getPluginVersion() + ")](#00fb9a)")),
+ " (v" + newVersion + " (Running: v" + plugin.getVersion() + ")](#00fb9a)")),
() -> onlineUser.sendMessage(
new MineDown("[HuskHomes](#00fb9a bold) [| HuskHomes is up-to-date."
+ " (Running: v" + plugin.getPluginVersion() + ")](#00fb9a)"))));
+ " (Running: v" + plugin.getVersion() + ")](#00fb9a)"))));
}
case "migrate" -> plugin.getLocales().getLocale("error_console_command_only")
.ifPresent(onlineUser::sendMessage);
@@ -143,10 +143,10 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
case "update" -> plugin.getLatestVersionIfOutdated().thenAccept(newestVersion ->
newestVersion.ifPresentOrElse(newVersion -> plugin.getLoggingAdapter().log(Level.WARNING,
"An update is available for HuskHomes, v" + newVersion
+ " (Running v" + plugin.getPluginVersion() + ")"),
+ " (Running v" + plugin.getVersion() + ")"),
() -> plugin.getLoggingAdapter().log(Level.INFO,
"HuskHomes is up to date" +
" (Running v" + plugin.getPluginVersion() + ")")));
" (Running v" + plugin.getVersion() + ")")));
case "migrate" -> {
if (args.length < 2) {
plugin.getLoggingAdapter().log(Level.INFO,
@@ -1,8 +1,8 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.User;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TimedTeleport;
@@ -86,7 +86,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
.thenAccept(TimedTeleport::execute);
}, () -> {
if (otherHome) {
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
plugin.getLocales().getLocale("error_home_invalid_other", owner.getUsername(), homeName)
.ifPresent(teleporter::sendMessage);
} else {
plugin.getLocales().getLocale("error_home_invalid", homeName)
@@ -124,8 +124,8 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to "
+ home.getOwner().username + "." + home.getMeta().getName());
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to "
+ home.getOwner().getUsername() + "." + home.getMeta().getName());
Teleport.builder(plugin, playerToTeleport)
.setTarget(home)
.toTeleport()
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -42,8 +42,8 @@ public class PublicHomeListCommand extends CommandBase implements ConsoleExecuta
* @param pageNumber page number to display
*/
private void showPublicHomeList(@NotNull OnlineUser onlineUser, int pageNumber) {
if (plugin.getCache().getPublicHomeLists().containsKey(onlineUser.uuid)) {
onlineUser.sendMessage(plugin.getCache().getPublicHomeLists().get(onlineUser.uuid).getNearestValidPage(pageNumber));
if (plugin.getCache().getPublicHomeLists().containsKey(onlineUser.getUuid())) {
onlineUser.sendMessage(plugin.getCache().getPublicHomeLists().get(onlineUser.getUuid()).getNearestValidPage(pageNumber));
return;
}
@@ -68,7 +68,7 @@ public class PublicHomeListCommand extends CommandBase implements ConsoleExecuta
plugin.getLoggingAdapter().log(Level.INFO, "List of " + homes.size() + " public homes:");
for (int i = 0; i < homes.size(); i++) {
final String ownerUsername = homes.get(i).getOwner().username;
final String ownerUsername = homes.get(i).getOwner().getUsername();
final String homeName = homes.get(i).getMeta().getName();
final String home = ownerUsername + "." + homeName;
int spacingSize = (16 - ownerUsername.length()) + 17;
@@ -1,9 +1,9 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.UserData;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportBuilder;
@@ -49,13 +49,13 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
}
// Perform economy check if necessary
if (!plugin.validateEconomyCheck(onlineUser, Settings.EconomyAction.RANDOM_TELEPORT)) {
if (!plugin.validateEconomyCheck(onlineUser, EconomyHook.EconomyAction.RANDOM_TELEPORT)) {
return;
}
final OnlineUser userToTeleport = target;
final boolean isExecutorTeleporting = userToTeleport.equals(onlineUser);
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> {
plugin.getDatabase().getUserData(onlineUser.getUuid()).thenAccept(userData -> {
// Check the user is not still on /rtp cooldown
if (userData.isEmpty()) {
return;
@@ -83,7 +83,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
final TeleportBuilder builder = Teleport.builder(plugin, userToTeleport)
.setTarget(position.get());
final CompletableFuture<? extends Teleport> teleportFuture = isExecutorTeleporting
? builder.setEconomyActions(Settings.EconomyAction.RANDOM_TELEPORT).toTimedTeleport()
? builder.setEconomyActions(EconomyHook.EconomyAction.RANDOM_TELEPORT).toTimedTeleport()
: builder.toTeleport();
teleportFuture.thenAccept(teleport -> teleport.execute()
@@ -110,10 +110,10 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Finding a random position for " + foundUser.get().username + "...");
plugin.getLoggingAdapter().log(Level.INFO, "Finding a random position for " + foundUser.get().getUsername() + "...");
plugin.getRandomTeleportEngine().getRandomPosition(foundUser.get().getPosition().getWorld(), ArrayUtils.subarray(args, 1, args.length)).thenAccept(position -> {
if (position.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + foundUser.get().username + " to a random position; randomization timed out!");
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + foundUser.get().getUsername() + " to a random position; randomization timed out!");
return;
}
Teleport.builder(plugin, foundUser.get())
@@ -121,9 +121,9 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful()) {
plugin.getLoggingAdapter().log(Level.INFO, "Teleported " + foundUser.get().username + " to a random position.");
plugin.getLoggingAdapter().log(Level.INFO, "Teleported " + foundUser.get().getUsername() + " to a random position.");
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport" + foundUser.get().username + " to a random position.");
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport" + foundUser.get().getUsername() + " to a random position.");
}
}));
});
@@ -1,9 +1,9 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.UserData;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.PositionMeta;
import net.william278.huskhomes.util.Permission;
@@ -63,7 +63,7 @@ public class SetHomeCommand extends CommandBase {
}
// Get their user data
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(fetchedData -> {
plugin.getDatabase().getUserData(onlineUser.getUuid()).thenAccept(fetchedData -> {
// Check against economy if needed
final AtomicBoolean newSlotNeeded = new AtomicBoolean(false);
final AtomicReference<UserData> userDataToUpdate = new AtomicReference<>(null);
@@ -71,7 +71,7 @@ public class SetHomeCommand extends CommandBase {
final int freeHomes = onlineUser.getFreeHomes(plugin.getSettings().getFreeHomeSlots(),
plugin.getSettings().doStackPermissionLimits());
if (fetchedData.isPresent()) {
final Settings.EconomyAction action = Settings.EconomyAction.ADDITIONAL_HOME_SLOT;
final EconomyHook.EconomyAction action = EconomyHook.EconomyAction.ADDITIONAL_HOME_SLOT;
newSlotNeeded.set((currentHomes.size() + 1) > (freeHomes + fetchedData.get().homeSlots()));
// If a new slot is needed, validate the user has enough funds to purchase one
@@ -105,7 +105,7 @@ public class SetHomeCommand extends CommandBase {
// If the user needed to buy a new slot, perform the transaction and update their data
if (newSlotNeeded.get()) {
plugin.performEconomyTransaction(onlineUser, Settings.EconomyAction.ADDITIONAL_HOME_SLOT);
plugin.performEconomyTransaction(onlineUser, EconomyHook.EconomyAction.ADDITIONAL_HOME_SLOT);
plugin.getDatabase().updateUserData(userDataToUpdate.get());
}
yield plugin.getLocales().getLocale("set_home_success", setResult.savedPosition().get().meta.name);
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.position.PositionMeta;
import net.william278.huskhomes.util.Permission;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.PositionMeta;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TimedTeleport;
@@ -1,6 +1,6 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.util.Permission;
@@ -26,7 +26,7 @@ public class TpAllCommand extends CommandBase {
// Determine players to teleport and teleport them
plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenAccept(fetchedPlayers -> {
final List<String> players = fetchedPlayers.stream()
.filter(userName -> !userName.equalsIgnoreCase(onlineUser.username)).toList();
.filter(userName -> !userName.equalsIgnoreCase(onlineUser.getUsername())).toList();
if (players.isEmpty()) {
plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage);
return;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.position.Server;
import net.william278.huskhomes.position.World;
@@ -34,19 +34,19 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
// Determine the player to teleport
final String targetPlayerToTeleport = ((teleportTarget.get() instanceof TargetPlayer) && args.length == 2)
? args[0] : ((teleportTarget.get() instanceof TargetPosition)
? args.length > 3 ? (isCoordinate(args[1]) && isCoordinate(args[2]) && isCoordinate(args[3]) ? args[0] : onlineUser.username)
: onlineUser.username : onlineUser.username);
? args.length > 3 ? (isCoordinate(args[1]) && isCoordinate(args[2]) && isCoordinate(args[3]) ? args[0] : onlineUser.getUsername())
: onlineUser.getUsername() : onlineUser.getUsername());
// Find the online user to teleport
plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenRun(() -> {
// Get the list of potential teleports, filtered against vanished players, but ensuring the executor is in the list
final Set<String> players = plugin.getCache().getPlayers();
players.add(onlineUser.username);
players.add(onlineUser.getUsername());
// Find the player to teleport
final String playerToTeleport = players.stream()
.filter(user -> user.equalsIgnoreCase(targetPlayerToTeleport)).findFirst()
.or(() -> Optional.ofNullable(targetPlayerToTeleport.equals("@s") ? onlineUser.username : null))
.or(() -> Optional.ofNullable(targetPlayerToTeleport.equals("@s") ? onlineUser.getUsername() : null))
.or(() -> plugin.getCache().getPlayers().stream().filter(user -> user.toLowerCase().startsWith(targetPlayerToTeleport)).findFirst())
.orElse(null);
@@ -58,7 +58,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
}
// Ensure the user has permission to teleport the player to teleport
if (!playerToTeleport.equals(onlineUser.username)) {
if (!playerToTeleport.equals(onlineUser.getUsername())) {
if (!onlineUser.hasPermission(Permission.COMMAND_TP_OTHER.node)) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(onlineUser::sendMessage);
@@ -77,7 +77,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
if (result.successful()) {
result.getTeleporter()
.flatMap(teleporter -> plugin.getLocales().getLocale("teleporting_other_complete",
teleporter.username, targetPlayer.playerName))
teleporter.getUsername(), targetPlayer.playerName))
.ifPresent(onlineUser::sendMessage);
} else {
plugin.getLocales().getLocale("error_player_not_found", targetPlayer.playerName)
@@ -97,13 +97,13 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
.setTarget(targetPosition.position)
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (!result.successful() || playerToTeleport.equalsIgnoreCase(onlineUser.username) || result.getDestination().isEmpty()) {
if (!result.successful() || playerToTeleport.equalsIgnoreCase(onlineUser.getUsername()) || result.getDestination().isEmpty()) {
return;
}
final Position destination = result.getDestination().get();
result.getTeleporter()
.flatMap(teleporter -> plugin.getLocales()
.getLocale("teleporting_other_complete_position", teleporter.username,
.getLocale("teleporting_other_complete_position", teleporter.getUsername(),
Integer.toString((int) destination.getX()),
Integer.toString((int) destination.getY()),
Integer.toString((int) destination.getZ())))
@@ -188,7 +188,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
// Execute the console teleport
final TeleportBuilder builder = Teleport.builder(plugin, playerToTeleport)
.setTeleporter(playerToTeleport.username);
.setTeleporter(playerToTeleport.getUsername());
if (teleportTarget instanceof TargetPlayer targetPlayer) {
builder.setTarget(targetPlayer.playerName);
} else {
@@ -196,9 +196,9 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
}
builder.toTeleport().thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful()) {
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.username);
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.getUsername());
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + playerToTeleport.username + " to " + teleportTarget);
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + playerToTeleport.getUsername() + " to " + teleportTarget);
}
}));
}
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -42,7 +42,7 @@ public class TpHereCommand extends CommandBase implements TabCompletable {
if (result.successful()) {
result.getTeleporter()
.flatMap(teleporter -> plugin.getLocales().getLocale("teleporting_other_complete",
teleporter.username, onlineUser.username))
teleporter.getUsername(), onlineUser.getUsername()))
.ifPresent(onlineUser::sendMessage);
}
}));
@@ -2,8 +2,8 @@ package net.william278.huskhomes.command;
import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.UserData;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -26,7 +26,7 @@ public class TpIgnoreCommand extends CommandBase {
plugin.getRequestManager().setIgnoringRequests(onlineUser, isIgnoringRequests);
// Update value on the database and send a message | todo: Clean this up
plugin.getDatabase().getUserData(onlineUser.uuid)
plugin.getDatabase().getUserData(onlineUser.getUuid())
.thenAcceptAsync(userData -> userData.ifPresent(data -> plugin.getDatabase()
.updateUserData(new UserData(onlineUser, data.homeSlots(), isIgnoringRequests, data.rtpCooldown()))
.thenRun(() -> plugin.getLocales().getRawLocale("tpignore_toggle_" + (isIgnoringRequests ? "on" : "off"),
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.request.TeleportRequest;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -34,7 +34,7 @@ public class TpaAllCommand extends CommandBase {
// Determine players to teleport and teleport them
plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenAccept(playerList -> {
final List<String> players = plugin.getCache().getPlayers().stream()
.filter(userName -> !userName.equalsIgnoreCase(onlineUser.username)).toList();
.filter(userName -> !userName.equalsIgnoreCase(onlineUser.getUsername())).toList();
if (players.isEmpty()) {
plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage);
return;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.request.TeleportRequest;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -30,7 +30,7 @@ public class TpaCommand extends CommandBase implements TabCompletable {
.sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA)
.thenAccept(sent -> {
if (sent.isEmpty()) {
if (args[0].equalsIgnoreCase(onlineUser.username)) {
if (args[0].equalsIgnoreCase(onlineUser.getUsername())) {
plugin.getLocales().getLocale("error_teleport_request_self")
.ifPresent(onlineUser::sendMessage);
return;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.request.TeleportRequest;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -30,7 +30,7 @@ public class TpaHereCommand extends CommandBase implements TabCompletable {
.sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA_HERE)
.thenAccept(sent -> {
if (sent.isEmpty()) {
if (args[0].equalsIgnoreCase(onlineUser.username)) {
if (args[0].equalsIgnoreCase(onlineUser.getUsername())) {
plugin.getLocales().getLocale("error_teleport_request_self")
.ifPresent(onlineUser::sendMessage);
return;
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TimedTeleport;
@@ -89,7 +89,7 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
}
final Warp warp = optionalWarp.get();
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to " + warp.getMeta().getName());
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to " + warp.getMeta().getName());
Teleport.builder(plugin, playerToTeleport)
.setTarget(warp)
.toTimedTeleport()
@@ -1,7 +1,7 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -40,8 +40,8 @@ public class WarpListCommand extends CommandBase implements ConsoleExecutable {
* @param pageNumber page number to display
*/
private void showWarpList(@NotNull OnlineUser onlineUser, int pageNumber) {
if (plugin.getCache().getWarpLists().containsKey(onlineUser.uuid)) {
onlineUser.sendMessage(plugin.getCache().getWarpLists().get(onlineUser.uuid).getNearestValidPage(pageNumber));
if (plugin.getCache().getWarpLists().containsKey(onlineUser.getUuid())) {
onlineUser.sendMessage(plugin.getCache().getWarpLists().get(onlineUser.getUuid()).getNearestValidPage(pageNumber));
return;
}