mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Adjust schema, fix commands and user data refactoring
This commit is contained in:
1 parent
ec1c0b744f
commit
ff2465ac85
12 files changed
+120
-105
No files matched your search
@@ -2,7 +2,6 @@ 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.util.Permission;
|
||||
import net.william278.huskhomes.util.RegexUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -33,16 +32,16 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso
|
||||
if (RegexUtil.OWNER_NAME_PATTERN.matcher(homeName).matches()) {
|
||||
final String ownerName = homeName.split("\\.")[0];
|
||||
final String ownersHomeName = homeName.split("\\.")[1];
|
||||
plugin.getDatabase().getUserByName(ownerName).thenAccept(optionalUserData -> optionalUserData
|
||||
plugin.getDatabase().getUserDataByName(ownerName).thenAccept(optionalUserData -> optionalUserData
|
||||
.ifPresentOrElse(userData -> {
|
||||
if (!userData.uuid.equals(onlineUser.uuid)) {
|
||||
if (!userData.getUserUuid().equals(onlineUser.uuid)) {
|
||||
if (!onlineUser.hasPermission(Permission.COMMAND_DELETE_HOME_OTHER.node)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
plugin.getSavedPositionManager().deleteHome(userData, ownersHomeName);
|
||||
plugin.getSavedPositionManager().deleteHome(userData.user(), ownersHomeName);
|
||||
},
|
||||
() -> plugin.getLocales().getLocale("error_home_invalid_other", ownerName, homeName)
|
||||
.ifPresent(onlineUser::sendMessage)));
|
||||
|
||||
@@ -37,8 +37,8 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
if (RegexUtil.OWNER_NAME_PATTERN.matcher(homeName).matches()) {
|
||||
final String ownerName = homeName.split("\\.")[0];
|
||||
final String ownersHomeName = homeName.split("\\.")[1];
|
||||
plugin.getDatabase().getUserByName(ownerName).thenAccept(optionalUserData -> optionalUserData
|
||||
.ifPresentOrElse(userData -> plugin.getTeleportManager().teleportToHome(onlineUser, userData, ownersHomeName),
|
||||
plugin.getDatabase().getUserDataByName(ownerName).thenAccept(optionalUserData -> optionalUserData
|
||||
.ifPresentOrElse(userData -> plugin.getTeleportManager().teleportToHome(onlineUser, userData.user(), ownersHomeName),
|
||||
() -> plugin.getLocales().getLocale("error_home_invalid_other", ownerName, homeName)
|
||||
.ifPresent(onlineUser::sendMessage)));
|
||||
} else {
|
||||
|
||||
@@ -52,23 +52,29 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
|
||||
return;
|
||||
}
|
||||
}
|
||||
plugin.getDatabase().getUserByName(homeOwner).thenAccept(optionalUser -> optionalUser.ifPresentOrElse(user -> {
|
||||
if (!user.uuid.equals(onlineUser.uuid)) {
|
||||
plugin.getLoggingAdapter().info("Getting home list for " + homeOwner);
|
||||
plugin.getDatabase().getUserDataByName(homeOwner).thenAccept(optionalUser -> optionalUser.ifPresentOrElse(userData -> {
|
||||
plugin.getLoggingAdapter().info("Got user!");
|
||||
if (!userData.getUserUuid().equals(onlineUser.uuid)) {
|
||||
if (!onlineUser.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
|
||||
plugin.getLocales().getLocale("error_no_permission").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
plugin.getDatabase().getHomes(user).thenAccept(homes -> {
|
||||
plugin.getLoggingAdapter().info("User has perms! Getting list...");
|
||||
plugin.getDatabase().getHomes(userData.user()).thenAccept(homes -> {
|
||||
plugin.getLoggingAdapter().info("Got home list!");
|
||||
if (homes.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
final PrivateHomeList homeList = new PrivateHomeList(homes, user, plugin);
|
||||
plugin.getCache().positionLists.put(user.uuid, homeList);
|
||||
plugin.getLoggingAdapter().info("Making list...");
|
||||
final PrivateHomeList homeList = new PrivateHomeList(homes, userData.user(), plugin);
|
||||
plugin.getCache().positionLists.put(userData.user().uuid, homeList);
|
||||
plugin.getLoggingAdapter().info("Showing list...");
|
||||
homeList.getDisplay(pageNumber).forEach(onlineUser::sendMessage);
|
||||
});
|
||||
}, () -> plugin.getLocales().getLocale("error_invalid_user").ifPresent(onlineUser::sendMessage)));
|
||||
}, () -> plugin.getLocales().getLocale("error_invalid_player").ifPresent(onlineUser::sendMessage)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.list.WarpList;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -16,11 +17,21 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
final String warpName = args[0];
|
||||
plugin.getTeleportManager().teleportToWarp(onlineUser, warpName);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/warp [name]")
|
||||
switch (args.length) {
|
||||
case 0 -> plugin.getDatabase().getWarps().thenAccept(warps -> {
|
||||
if (warps.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
final WarpList warpList = new WarpList(warps, plugin);
|
||||
plugin.getCache().positionLists.put(onlineUser.uuid, warpList);
|
||||
warpList.getDisplay(1).forEach(onlineUser::sendMessage);
|
||||
});
|
||||
case 1 -> {
|
||||
final String warpName = args[0];
|
||||
plugin.getTeleportManager().teleportToWarp(onlineUser, warpName);
|
||||
}
|
||||
default -> plugin.getLocales().getLocale("error_invalid_syntax", "/warp [name]")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user