Cut down jar size, adjust shadings, fix message formatting, adjust home pattern matching

This commit is contained in:
William committed 2022-08-10 22:42:37 +01:00
1 parent ff2465ac85
commit 979d57e7b2
22 files changed
+160 -107

No files matched your search

@@ -17,7 +17,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso
@Override
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
switch (args.length) {
case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
if (homes.size() == 1) {
@@ -29,25 +29,21 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso
});
case 1 -> {
final String homeName = args[0];
if (RegexUtil.OWNER_NAME_PATTERN.matcher(homeName).matches()) {
final String ownerName = homeName.split("\\.")[0];
final String ownersHomeName = homeName.split("\\.")[1];
plugin.getDatabase().getUserDataByName(ownerName).thenAccept(optionalUserData -> optionalUserData
.ifPresentOrElse(userData -> {
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.user(), ownersHomeName);
},
() -> plugin.getLocales().getLocale("error_home_invalid_other", ownerName, homeName)
.ifPresent(onlineUser::sendMessage)));
} else {
plugin.getSavedPositionManager().deleteHome(onlineUser, homeName);
}
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(homeIdentifier ->
plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()).thenAccept(
optionalUserData -> optionalUserData.ifPresentOrElse(userData -> {
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.user(), homeIdentifier.homeName());
},
() -> plugin.getLocales().getLocale("error_home_invalid_other",
homeIdentifier.ownerName(), homeIdentifier.homeName()).ifPresent(onlineUser::sendMessage))),
() -> plugin.getSavedPositionManager().deleteHome(onlineUser, homeName));
}
default -> plugin.getLocales().getLocale("error_invalid_syntax", "/delhome <name>")
.ifPresent(onlineUser::sendMessage);
@@ -18,7 +18,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
@Override
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
switch (args.length) {
case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
switch (homes.size()) {
@@ -34,16 +34,13 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
});
case 1 -> {
final String homeName = args[0];
if (RegexUtil.OWNER_NAME_PATTERN.matcher(homeName).matches()) {
final String ownerName = homeName.split("\\.")[0];
final String ownersHomeName = homeName.split("\\.")[1];
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 {
plugin.getTeleportManager().teleportToHome(onlineUser, onlineUser, homeName);
}
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(
homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName())
.thenAccept(optionalUserData -> optionalUserData.ifPresentOrElse(
userData -> plugin.getTeleportManager().teleportToHome(onlineUser, userData.user(), homeIdentifier.ownerName()),
() -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName())
.ifPresent(onlineUser::sendMessage))),
() -> plugin.getTeleportManager().teleportToHome(onlineUser, onlineUser, homeName));
}
default -> plugin.getLocales().getLocale("error_invalid_syntax", "/home [name]")
.ifPresent(onlineUser::sendMessage);
@@ -52,26 +52,20 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
return;
}
}
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.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;
}
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_player").ifPresent(onlineUser::sendMessage)));
@@ -16,7 +16,6 @@ public class SetHomeCommand extends CommandBase {
@Override
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
switch (args.length) {
case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
if (homes.isEmpty()) {