Add fabric builds for older MC versions & add checkstyle (#449)

* Remove instance getters, improve command logic, register APi

* Publish multiple fabric builds, enforce checkstyle

* Bump guava

* Bump to 4.4.2
This commit is contained in:
William authored and GitHub committed 2023-07-02 13:26:12 +01:00
1 parent 51baf196b3
commit c9f5262292
219 files changed
+8032 -1392

No files matched your search

@@ -36,8 +36,8 @@ public class BackCommand extends InGameCommand {
protected BackCommand(@NotNull HuskHomes plugin) {
super("back", List.of(), "", plugin);
addAdditionalPermissions(Map.of(
"death", false,
"previous", false
"death", false,
"previous", false
));
}
@@ -32,7 +32,8 @@ public abstract class Command extends Node {
private final String usage;
private final Map<String, Boolean> additionalPermissions;
protected Command(@NotNull String name, @NotNull List<String> aliases, @NotNull String usage, @NotNull HuskHomes plugin) {
protected Command(@NotNull String name, @NotNull List<String> aliases, @NotNull String usage,
@NotNull HuskHomes plugin) {
super(name, aliases, plugin);
this.usage = usage;
this.additionalPermissions = new HashMap<>();
@@ -70,8 +71,8 @@ public abstract class Command extends Node {
return "/" + getName() + " " + getRawUsage();
}
public final void addAdditionalPermissions(@NotNull Map<String, Boolean> additionalPermissions) {
additionalPermissions.forEach((permission, value) -> this.additionalPermissions.put(getPermission(permission), value));
public final void addAdditionalPermissions(@NotNull Map<String, Boolean> permissions) {
permissions.forEach((permission, value) -> this.additionalPermissions.put(getPermission(permission), value));
}
@NotNull
@@ -44,7 +44,8 @@ public class DelHomeCommand extends SavedPositionCommand<Home> {
@Override
public void execute(@NotNull CommandUser executor, @NotNull Home home, @NotNull String[] args) {
if (executor instanceof OnlineUser user && !home.getOwner().equals(user) && !user.hasPermission(getOtherPermission())) {
if (executor instanceof OnlineUser user && !home.getOwner().equals(user)
&& !user.hasPermission(getOtherPermission())) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(user::sendMessage);
return;
@@ -72,10 +72,12 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
case "description" -> setHomeDescription(executor, home, ownerEditing, args);
case "relocate" -> setHomePosition(executor, home, ownerEditing);
case "privacy" -> setHomePrivacy(executor, home, ownerEditing, args);
default -> throw new IllegalStateException("Unexpected value: " + operation.get().toLowerCase());
}
}
private void setHomeName(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing, @NotNull String[] args) {
private void setHomeName(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing,
@NotNull String[] args) {
final String oldName = home.getName();
final Optional<String> optionalName = parseStringArg(args, 1);
if (optionalName.isEmpty()) {
@@ -106,7 +108,8 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
});
}
private void setHomeDescription(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing, @NotNull String[] args) {
private void setHomeDescription(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing,
@NotNull String[] args) {
final String oldDescription = home.getMeta().getDescription();
final Optional<String> optionalDescription = parseGreedyArguments(args);
if (optionalDescription.isEmpty()) {
@@ -127,7 +130,8 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
}
if (ownerEditing) {
plugin.getLocales().getLocale("edit_home_update_description", home.getName(), oldDescription, newDescription)
plugin.getLocales().getLocale("edit_home_update_description",
home.getName(), oldDescription, newDescription)
.ifPresent(executor::sendMessage);
} else {
plugin.getLocales().getLocale("edit_home_update_description_other", home.getOwner().getUsername(),
@@ -157,21 +161,24 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
plugin.getLocales().getLocale("edit_home_update_location", home.getName())
.ifPresent(executor::sendMessage);
} else {
plugin.getLocales().getLocale("edit_home_update_location_other", home.getOwner().getUsername(), home.getName())
plugin.getLocales().getLocale("edit_home_update_location_other",
home.getOwner().getUsername(), home.getName())
.ifPresent(executor::sendMessage);
}
});
}
private void setHomePrivacy(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing, @NotNull String[] args) {
private void setHomePrivacy(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing,
@NotNull String[] args) {
if (!executor.hasPermission(getPermission("privacy"))) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(executor::sendMessage);
return;
}
// Check against economy
if (executor instanceof OnlineUser user && !plugin.validateTransaction(user, TransactionResolver.Action.MAKE_HOME_PUBLIC)) {
// Check against the economy hook
if (executor instanceof OnlineUser user
&& !plugin.validateTransaction(user, TransactionResolver.Action.MAKE_HOME_PUBLIC)) {
return;
}
@@ -184,7 +191,8 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
try {
plugin.getManager().homes().setHomePrivacy(event.getHome(), home.isPublic());
} catch (ValidationException e) {
int maxHomes = plugin.getManager().homes().getMaxPublicHomes(executor instanceof OnlineUser user ? user : null);
int maxHomes = plugin.getManager().homes()
.getMaxPublicHomes(executor instanceof OnlineUser user ? user : null);
e.dispatchHomeError(executor, false, plugin, Integer.toString(maxHomes));
return;
}
@@ -208,7 +216,7 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
}
/**
* Get a formatted home editor chat window for a supplied {@link Home}
* Get a formatted home editor chat window for a supplied {@link Home}.
*
* @param home The home to display
* @param otherViewer If the viewer of the editor is not the homeowner
@@ -219,55 +227,61 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
@NotNull
private List<MineDown> getHomeEditorWindow(@NotNull Home home, boolean otherViewer,
boolean showTeleportButton, boolean showPrivacyToggleButton) {
return new ArrayList<>() {{
if (!otherViewer) {
plugin.getLocales().getLocale("edit_home_menu_title", home.getName())
.ifPresent(this::add);
} else {
plugin.getLocales().getLocale("edit_home_menu_title_other", home.getOwner().getUsername(), home.getName())
.ifPresent(this::add);
}
final List<MineDown> messages = new ArrayList<>();
if (!otherViewer) {
plugin.getLocales().getLocale("edit_home_menu_title", home.getName())
.ifPresent(messages::add);
} else {
plugin.getLocales().getLocale("edit_home_menu_title_other",
home.getOwner().getUsername(), home.getName())
.ifPresent(messages::add);
}
plugin.getLocales().getLocale("edit_home_menu_metadata_" + (!home.isPublic() ? "private" : "public"),
DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm")
.format(home.getMeta().getCreationTime().atZone(ZoneId.systemDefault())),
home.getUuid().toString().split(Pattern.quote("-"))[0],
home.getUuid().toString())
.ifPresent(this::add);
plugin.getLocales().getLocale("edit_home_menu_metadata_" + (!home.isPublic() ? "private" : "public"),
DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm")
.format(home.getMeta().getCreationTime().atZone(ZoneId.systemDefault())),
home.getUuid().toString().split(Pattern.quote("-"))[0],
home.getUuid().toString())
.ifPresent(messages::add);
if (home.getMeta().getDescription().length() > 0) {
plugin.getLocales().getLocale("edit_home_menu_description",
plugin.getLocales().truncateText(home.getMeta().getDescription(), 50),
plugin.getLocales().wrapText(home.getMeta().getDescription(), 40))
.ifPresent(this::add);
}
if (home.getMeta().getDescription().length() > 0) {
plugin.getLocales().getLocale("edit_home_menu_description",
plugin.getLocales().truncateText(home.getMeta().getDescription(), 50),
plugin.getLocales().wrapText(home.getMeta().getDescription(), 40))
.ifPresent(messages::add);
}
if (!plugin.getSettings().doCrossServer()) {
plugin.getLocales().getLocale("edit_home_menu_world", home.getWorld().getName())
.ifPresent(this::add);
} else {
plugin.getLocales().getLocale("edit_home_menu_world_server", home.getWorld().getName(), home.getServer())
.ifPresent(this::add);
}
if (!plugin.getSettings().doCrossServer()) {
plugin.getLocales().getLocale("edit_home_menu_world", home.getWorld().getName())
.ifPresent(messages::add);
} else {
plugin.getLocales().getLocale("edit_home_menu_world_server",
home.getWorld().getName(), home.getServer())
.ifPresent(messages::add);
}
plugin.getLocales().getLocale("edit_home_menu_coordinates",
String.format("%.1f", home.getX()), String.format("%.1f", home.getY()), String.format("%.1f", home.getZ()),
String.format("%.2f", home.getYaw()), String.format("%.2f", home.getPitch()))
.ifPresent(this::add);
plugin.getLocales().getLocale("edit_home_menu_coordinates",
String.format("%.1f", home.getX()),
String.format("%.1f", home.getY()),
String.format("%.1f", home.getZ()),
String.format("%.2f", home.getYaw()),
String.format("%.2f", home.getPitch()))
.ifPresent(messages::add);
if (showTeleportButton) {
plugin.getLocales().getLocale("edit_home_menu_use_buttons", home.getSafeIdentifier())
.ifPresent(this::add);
}
plugin.getLocales().getRawLocale("edit_home_menu_manage_buttons", home.getSafeIdentifier(),
showPrivacyToggleButton ? plugin.getLocales()
.getRawLocale("edit_home_menu_privacy_button_"
+ (home.isPublic() ? "private" : "public"), home.getSafeIdentifier())
.orElse("") : "")
.map(MineDown::new).ifPresent(this::add);
plugin.getLocales().getLocale("edit_home_menu_meta_edit_buttons", home.getSafeIdentifier())
.ifPresent(this::add);
}};
if (showTeleportButton) {
plugin.getLocales().getLocale("edit_home_menu_use_buttons", home.getSafeIdentifier())
.ifPresent(messages::add);
}
plugin.getLocales().getRawLocale("edit_home_menu_manage_buttons",
home.getSafeIdentifier(),
showPrivacyToggleButton ? plugin.getLocales()
.getRawLocale("edit_home_menu_privacy_button_"
+ (home.isPublic() ? "private" : "public"), home.getSafeIdentifier())
.orElse("") : "")
.map(MineDown::new).ifPresent(messages::add);
plugin.getLocales().getLocale("edit_home_menu_meta_edit_buttons", home.getSafeIdentifier())
.ifPresent(messages::add);
return messages;
}
}
@@ -61,6 +61,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
case "rename" -> setWarpName(executor, warp, args);
case "description" -> setWarpDescription(executor, warp, args);
case "relocate" -> setWarpPosition(executor, warp);
default -> throw new IllegalStateException("Unexpected value: " + operation.get().toLowerCase());
}
}
@@ -106,7 +107,8 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
return;
}
plugin.getLocales().getLocale("edit_warp_update_description", warp.getName(), warp.getMeta().getDescription())
plugin.getLocales().getLocale("edit_warp_update_description",
warp.getName(), warp.getMeta().getDescription())
.ifPresent(executor::sendMessage);
});
}
@@ -133,49 +135,54 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
}
/**
* Get a formatted warp editor chat window for a supplied {@link Warp}
* Get a formatted warp editor chat window for a supplied {@link Warp}.
*
* @param warp The warp to display
* @return List of {@link MineDown} messages to send to the editor that form the menu
*/
@NotNull
private List<MineDown> getWarpEditorWindow(@NotNull Warp warp) {
return new ArrayList<>() {{
plugin.getLocales().getLocale("edit_warp_menu_title", warp.getName())
.ifPresent(this::add);
final List<MineDown> messages = new ArrayList<>();
plugin.getLocales().getLocale("edit_warp_menu_title", warp.getName())
.ifPresent(messages::add);
plugin.getLocales().getLocale("edit_warp_menu_metadata",
DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm")
.format(warp.getMeta().getCreationTime().atZone(ZoneId.systemDefault())),
warp.getUuid().toString().split(Pattern.quote("-"))[0],
warp.getUuid().toString())
.ifPresent(this::add);
plugin.getLocales().getLocale("edit_warp_menu_metadata",
DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm")
.format(warp.getMeta().getCreationTime().atZone(ZoneId.systemDefault())),
warp.getUuid().toString().split(Pattern.quote("-"))[0],
warp.getUuid().toString())
.ifPresent(messages::add);
if (warp.getMeta().getDescription().length() > 0) {
plugin.getLocales().getLocale("edit_warp_menu_description",
plugin.getLocales().truncateText(warp.getMeta().getDescription(), 50),
plugin.getLocales().wrapText(warp.getMeta().getDescription(), 40))
.ifPresent(this::add);
}
if (warp.getMeta().getDescription().length() > 0) {
plugin.getLocales().getLocale("edit_warp_menu_description",
plugin.getLocales().truncateText(warp.getMeta().getDescription(), 50),
plugin.getLocales().wrapText(warp.getMeta().getDescription(), 40))
.ifPresent(messages::add);
}
if (!plugin.getSettings().doCrossServer()) {
plugin.getLocales().getLocale("edit_warp_menu_world", warp.getWorld().getName()).ifPresent(this::add);
} else {
plugin.getLocales().getLocale("edit_warp_menu_world_server", warp.getWorld().getName(), warp.getServer()).ifPresent(this::add);
}
if (!plugin.getSettings().doCrossServer()) {
plugin.getLocales().getLocale("edit_warp_menu_world",
warp.getWorld().getName()).ifPresent(messages::add);
} else {
plugin.getLocales().getLocale("edit_warp_menu_world_server",
warp.getWorld().getName(), warp.getServer()).ifPresent(messages::add);
}
plugin.getLocales().getLocale("edit_warp_menu_coordinates",
String.format("%.1f", warp.getX()), String.format("%.1f", warp.getY()), String.format("%.1f", warp.getZ()),
String.format("%.2f", warp.getYaw()), String.format("%.2f", warp.getPitch()))
.ifPresent(this::add);
plugin.getLocales().getLocale("edit_warp_menu_coordinates",
String.format("%.1f", warp.getX()),
String.format("%.1f", warp.getY()),
String.format("%.1f", warp.getZ()),
String.format("%.2f", warp.getYaw()),
String.format("%.2f", warp.getPitch()))
.ifPresent(messages::add);
plugin.getLocales().getLocale("edit_warp_menu_use_buttons", warp.getSafeIdentifier())
.ifPresent(this::add);
plugin.getLocales().getLocale("edit_warp_menu_manage_buttons", warp.getSafeIdentifier())
.ifPresent(this::add);
plugin.getLocales().getLocale("edit_warp_menu_meta_edit_buttons", warp.getSafeIdentifier())
.ifPresent(this::add);
}};
plugin.getLocales().getLocale("edit_warp_menu_use_buttons", warp.getSafeIdentifier())
.ifPresent(messages::add);
plugin.getLocales().getLocale("edit_warp_menu_manage_buttons", warp.getSafeIdentifier())
.ifPresent(messages::add);
plugin.getLocales().getLocale("edit_warp_menu_meta_edit_buttons", warp.getSafeIdentifier())
.ifPresent(messages::add);
return messages;
}
}
@@ -100,12 +100,15 @@ public class HuskHomesCommand extends Command implements TabProvider {
.getNearestValidPage(parseIntArg(args, 1).orElse(1)));
case "reload" -> {
if (!plugin.loadConfigs()) {
executor.sendMessage(new MineDown("[Error:](#ff3300) [Failed to reload the plugin. Check console for errors.](#ff7e5e)"));
executor.sendMessage(new MineDown(
"[Error:](#ff3300) [Failed to reload the plugin. Check console for errors.](#ff7e5e)"
));
return;
}
executor.sendMessage(new MineDown("""
[HuskHomes](#00fb9a bold) [| Reloaded config & message files.](#00fb9a)
[ℹ If you have modified the database or cross-server message broker settings, you need to restart your server for these changes to take effect.](gray)"""
executor.sendMessage(new MineDown(
"[HuskHomes](#00fb9a bold) [| Reloaded config & message files.](#00fb9a)\n"
+ "[ℹ If you have modified the database or cross-server message broker settings,"
+ " you need to restart your server for these changes to take effect.](gray)"
));
}
case "update" -> updateChecker.check().thenAccept(checked -> {
@@ -32,7 +32,8 @@ public abstract class ListCommand extends Command {
protected final Map<UUID, PaginatedList> cachedLists;
protected ListCommand(@NotNull String name, @NotNull List<String> aliases, @NotNull String usage, @NotNull HuskHomes plugin) {
protected ListCommand(@NotNull String name, @NotNull List<String> aliases, @NotNull String usage,
@NotNull HuskHomes plugin) {
super(name, aliases, usage, plugin);
this.cachedLists = new HashMap<>();
}
@@ -156,23 +156,23 @@ public abstract class Node implements Executable {
.orElse(Position.at(0, 0, 0, 0, 0, plugin.getWorlds().get(0), plugin.getServerName()));
}
protected Optional<Position> parsePositionArgs(@NotNull Position basePosition, @NotNull String[] args, int startIndex) {
protected Optional<Position> parsePositionArgs(@NotNull Position basePosition, @NotNull String[] args, int from) {
// Parse x, y, and z
final Optional<Double> x = parseCoordinateArg(args, startIndex, basePosition.getX());
final Optional<Double> y = parseCoordinateArg(args, startIndex + 1, basePosition.getY());
final Optional<Double> z = parseCoordinateArg(args, startIndex + 2, basePosition.getZ());
final Optional<Double> x = parseCoordinateArg(args, from, basePosition.getX());
final Optional<Double> y = parseCoordinateArg(args, from + 1, basePosition.getY());
final Optional<Double> z = parseCoordinateArg(args, from + 2, basePosition.getZ());
if (x.isEmpty() || y.isEmpty() || z.isEmpty()) {
return Optional.empty();
}
// Parse world and server name
final Optional<World> world = parseWorldArg(args, startIndex + 3);
final Optional<String> server = parseStringArg(args, startIndex + 4);
final Optional<World> world = parseWorldArg(args, from + 3);
final Optional<String> server = parseStringArg(args, from + 4);
// Parse yaw, pitch
int angleStartIndex = (world.isEmpty() ? 3 : server.isEmpty() ? 4 : 5);
final Optional<Float> yaw = parseFloatArg(args, startIndex + angleStartIndex);
final Optional<Float> pitch = parseFloatArg(args, startIndex + angleStartIndex + 1);
final Optional<Float> yaw = parseFloatArg(args, from + angleStartIndex);
final Optional<Float> pitch = parseFloatArg(args, from + angleStartIndex + 1);
return Optional.of(Position.at(x.get(), y.get(), z.get(),
yaw.orElse(basePosition.getYaw()), pitch.orElse(basePosition.getPitch()),
@@ -74,7 +74,7 @@ public class PrivateHomeListCommand extends ListCommand {
}
if (executor instanceof OnlineUser onlineUser && !user.getUuid().equals(onlineUser.getUuid())
&& !executor.hasPermission(getPermission("other"))) {
&& !executor.hasPermission(getPermission("other"))) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(executor::sendMessage);
return;
@@ -93,7 +93,8 @@ public class PrivateHomeListCommand extends ListCommand {
}));
}
private Optional<PaginatedList> generateList(@NotNull CommandUser executor, @NotNull User user, @NotNull List<Home> homes) {
private Optional<PaginatedList> generateList(@NotNull CommandUser executor, @NotNull User user,
@NotNull List<Home> homes) {
if (homes.isEmpty()) {
if (!executor.equals(user)) {
plugin.getLocales().getLocale("error_no_homes_set_other", user.getUsername())
@@ -109,7 +110,10 @@ public class PrivateHomeListCommand extends ListCommand {
plugin.getLocales()
.getRawLocale("home_list_item",
Locales.escapeText(home.getName()), home.getSafeIdentifier(),
Locales.escapeText(plugin.getLocales().wrapText(home.getMeta().getDescription(), 40)))
Locales.escapeText(plugin.getLocales().wrapText(
home.getMeta().getDescription(),
40
)))
.orElse(home.getName())).sorted().collect(Collectors.toList()),
plugin.getLocales()
.getBaseList(plugin.getSettings().getListItemsPerPage())
@@ -46,7 +46,7 @@ public class PublicHomeCommand extends HomeCommand implements TabProvider {
@NotNull
public List<String> suggest(@NotNull CommandUser executor, @NotNull String[] args) {
if (args.length <= 2) {
return filter(plugin.getManager().homes().getPublicHomeNames(), args);
return filter(plugin.getManager().homes().getPublicHomeIdentifiers(), args);
}
return List.of();
}
@@ -71,7 +71,10 @@ public class PublicHomeListCommand extends ListCommand {
.getRawLocale("public_home_list_item",
Locales.escapeText(home.getName()), home.getSafeIdentifier(),
Locales.escapeText(home.getOwner().getUsername()),
Locales.escapeText(plugin.getLocales().wrapText(home.getMeta().getDescription(), 40)))
Locales.escapeText(plugin.getLocales().wrapText(
home.getMeta().getDescription(),
40
)))
.orElse(home.getName())).sorted().collect(Collectors.toList()),
plugin.getLocales()
.getBaseList(plugin.getSettings().getListItemsPerPage())
@@ -80,14 +80,15 @@ public class RtpCommand extends Command implements UserListTabProvider {
}
/**
* Validates the RTP command, returning the world to randomly teleport in if successful
* Validates the RTP command, returning the world to randomly teleport in if successful.
*
* @param teleporter The user to teleport
* @param executor The user executing the command
* @param args The command arguments
* @return The world to randomly teleport in, if successful
*/
private Optional<World> validateRtp(@NotNull OnlineUser teleporter, @NotNull CommandUser executor, @NotNull String[] args) {
private Optional<World> validateRtp(@NotNull OnlineUser teleporter, @NotNull CommandUser executor,
@NotNull String[] args) {
// Check permissions if the user is being teleported by another player
if (!executor.equals(teleporter) && !executor.hasPermission(getPermission("other"))) {
plugin.getLocales().getLocale("error_no_permission")
@@ -127,7 +128,7 @@ public class RtpCommand extends Command implements UserListTabProvider {
}
/**
* Executes the random teleport
* Executes the random teleport.
*
* @param teleporter The player to teleport
* @param executor The player executing the command
@@ -45,7 +45,7 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
protected SavedPositionCommand(@NotNull String name, @NotNull List<String> aliases, @NotNull Class<T> positionType,
@NotNull List<String> arguments, @NotNull HuskHomes plugin) {
super(name, aliases, "<name>" + ((arguments.size() > 0) ? " [" + String.join("|", arguments) + "]" : ""), plugin);
super(name, aliases, "<name>" + formatUsage(arguments), plugin);
this.positionType = positionType;
this.arguments = arguments;
@@ -78,18 +78,18 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
private Optional<Home> resolveHome(@NotNull CommandUser executor, @NotNull String homeName) {
if (homeName.contains(Home.IDENTIFIER_DELIMITER)) {
final String ownerUsername = homeName.substring(0, homeName.indexOf(Home.IDENTIFIER_DELIMITER));
final String ownerHomeName = homeName.substring(homeName.indexOf(Home.IDENTIFIER_DELIMITER) + 1);
if (ownerUsername.isBlank() || ownerHomeName.isBlank()) {
final String ownerHome = homeName.substring(homeName.indexOf(Home.IDENTIFIER_DELIMITER) + 1);
if (ownerUsername.isBlank() || ownerHome.isBlank()) {
plugin.getLocales().getLocale("error_invalid_syntax", getUsage())
.ifPresent(executor::sendMessage);
return Optional.empty();
}
final Optional<Home> optionalHome = plugin.getDatabase().getUserDataByName(ownerUsername)
.flatMap(owner -> resolveHomeByName(owner.getUser(), ownerHomeName));
.flatMap(owner -> resolveHomeByName(owner.getUser(), ownerHome));
if (optionalHome.isEmpty()) {
plugin.getLocales().getLocale(executor.hasPermission(getOtherPermission())
? "error_home_invalid_other" : "error_public_home_invalid", ownerUsername, ownerHomeName)
? "error_home_invalid_other" : "error_public_home_invalid", ownerUsername, ownerHome)
.ifPresent(executor::sendMessage);
return Optional.empty();
}
@@ -97,7 +97,7 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
final Home home = optionalHome.get();
if (executor instanceof OnlineUser user && !home.isPublic() && !user.equals(home.getOwner())
&& !user.hasPermission(getOtherPermission())) {
plugin.getLocales().getLocale("error_public_home_invalid", ownerUsername, ownerHomeName)
plugin.getLocales().getLocale("error_public_home_invalid", ownerUsername, ownerHome)
.ifPresent(executor::sendMessage);
return Optional.empty();
}
@@ -138,7 +138,8 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
return Optional.empty();
}
if (executor instanceof OnlineUser user && plugin.getSettings().doPermissionRestrictWarps()
&& !user.hasPermission(Warp.getWildcardPermission()) && !user.hasPermission(Warp.getPermission(warpName))) {
&& !user.hasPermission(Warp.getWildcardPermission())
&& !user.hasPermission(Warp.getPermission(warpName))) {
plugin.getLocales().getLocale("error_warp_invalid", warpName)
.ifPresent(executor::sendMessage);
return Optional.empty();
@@ -180,6 +181,11 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
}
}
@NotNull
private static String formatUsage(List<String> arguments) {
return ((arguments.size() > 0) ? " [" + String.join("|", arguments) + "]" : "");
}
@Override
@NotNull
public List<String> suggest(@NotNull CommandUser executor, @NotNull String[] args) {
@@ -188,14 +194,14 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
case 0, 1 -> {
if (args.length == 1 && args[0].contains(Home.IDENTIFIER_DELIMITER)) {
if (executor.hasPermission(getOtherPermission())) {
yield filter(plugin.getManager().homes().getUserHomeNames(), args);
yield filter(plugin.getManager().homes().getUserHomeIdentifiers(), args);
}
yield filter(plugin.getManager().homes().getUserHomeNames(), args);
yield filter(plugin.getManager().homes().getUserHomeIdentifiers(), args);
}
if (executor instanceof OnlineUser user) {
yield filter(plugin.getManager().homes().getUserHomes().get(user.getUsername()), args);
}
yield filter(plugin.getManager().homes().getUserHomeNames(), args);
yield filter(plugin.getManager().homes().getUserHomeIdentifiers(), args);
}
case 2 -> filter(arguments.stream().toList(), args);
default -> List.of();
@@ -41,8 +41,9 @@ public class SetSpawnCommand extends InGameCommand {
if (plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalSpawn()) {
final String warpName = plugin.getSettings().getGlobalSpawnName();
plugin.getManager().warps().createWarp(warpName, position, true);
plugin.getLocales().getRawLocale("spawn_warp_default_description")
.ifPresent(description -> plugin.getManager().warps().setWarpDescription(warpName, description));
plugin.getLocales().getRawLocale("spawn_warp_default_description").ifPresent(
description -> plugin.getManager().warps().setWarpDescription(warpName, description)
);
} else {
plugin.setServerSpawn(position);
}
@@ -59,8 +59,8 @@ public class SpawnCommand extends Command {
this.teleportToSpawn(optionalTeleporter.get(), executor, spawn.get(), args);
}
public void teleportToSpawn(@NotNull Teleportable teleporter, @NotNull CommandUser executor, @NotNull Position spawn,
@NotNull String[] args) {
public void teleportToSpawn(@NotNull Teleportable teleporter, @NotNull CommandUser executor,
@NotNull Position spawn, @NotNull String[] args) {
if (!executor.equals(teleporter) && !executor.hasPermission(getPermission("other"))) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(executor::sendMessage);
@@ -115,16 +115,16 @@ public class TpCommand extends Command implements TabProvider {
@Override
@NotNull
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
final Position basePosition = getBasePosition(user);
final Position relative = getBasePosition(user);
final boolean serveCoordinateCompletions = user.hasPermission(getPermission("coordinates"));
switch (args.length) {
case 0, 1 -> {
final ArrayList<String> completions = new ArrayList<>();
completions.addAll(serveCoordinateCompletions
? List.of("~", "~ ~", "~ ~ ~",
Integer.toString((int) basePosition.getX()),
((int) basePosition.getX() + " " + (int) basePosition.getY()),
((int) basePosition.getX() + " " + (int) basePosition.getY() + " " + (int) basePosition.getZ()))
Integer.toString((int) relative.getX()),
((int) relative.getX() + " " + (int) relative.getY()),
((int) relative.getX() + " " + (int) relative.getY() + " " + (int) relative.getZ()))
: List.of());
completions.addAll(plugin.getPlayerList(false));
return completions.stream()
@@ -134,15 +134,17 @@ public class TpCommand extends Command implements TabProvider {
case 2 -> {
final ArrayList<String> completions = new ArrayList<>();
if (isCoordinate(args, 0)) {
completions.addAll(List.of("~", Integer.toString((int) basePosition.getY())));
completions.addAll(List.of("~ ~", (int) basePosition.getY() + " " + (int) basePosition.getZ()));
completions.addAll(List.of("~", Integer.toString((int) relative.getY())));
completions.addAll(List.of("~ ~", (int) relative.getY() + " " + (int) relative.getZ()));
} else {
completions.addAll(serveCoordinateCompletions
? List.of("~", "~ ~", "~ ~ ~",
Integer.toString((int) basePosition.getX()),
((int) basePosition.getX() + " " + (int) basePosition.getY()),
((int) basePosition.getX() + " " + (int) basePosition.getY() + " " + (int) basePosition.getZ()))
: List.of());
completions.addAll(
serveCoordinateCompletions
? List.of("~", "~ ~", "~ ~ ~",
Integer.toString((int) relative.getX()),
((int) relative.getX() + " " + (int) relative.getY()),
((int) relative.getX() + " " + (int) relative.getY() + " " + (int) relative.getZ()))
: List.of()
);
completions.addAll(plugin.getPlayerList(false));
}
return completions.stream()
@@ -155,13 +157,13 @@ public class TpCommand extends Command implements TabProvider {
if (!serveCoordinateCompletions) {
return completions;
}
completions.addAll(List.of("~", Integer.toString((int) basePosition.getZ())));
completions.addAll(List.of("~", Integer.toString((int) relative.getZ())));
} else if (isCoordinate(args, 1)) {
if (!serveCoordinateCompletions) {
return completions;
}
completions.addAll(List.of("~", Integer.toString((int) basePosition.getY())));
completions.addAll(List.of("~ ~", (int) basePosition.getY() + " " + (int) basePosition.getZ()));
completions.addAll(List.of("~", Integer.toString((int) relative.getY())));
completions.addAll(List.of("~ ~", (int) relative.getY() + " " + (int) relative.getZ()));
}
return completions.stream()
.filter(s -> s.toLowerCase().startsWith(args[2].toLowerCase()))
@@ -173,7 +175,7 @@ public class TpCommand extends Command implements TabProvider {
if (!serveCoordinateCompletions) {
return completions;
}
completions.addAll(List.of("~", Integer.toString((int) basePosition.getZ())));
completions.addAll(List.of("~", Integer.toString((int) relative.getZ())));
}
return completions.stream()
.filter(s -> s.toLowerCase().startsWith(args[3].toLowerCase()))
@@ -28,14 +28,19 @@ import java.util.Optional;
/**
* A command used for responding to tp requests - can either be a /tpaccept or /tpdecline command, controlled by the
* acceptRequestCommand flag
* acceptRequestCommand flag.
*/
public class TpRespondCommand extends InGameCommand implements UserListTabProvider {
private final boolean accept;
protected TpRespondCommand(@NotNull HuskHomes plugin, boolean accept) {
super(accept ? "tpaccept" : "tpdecline", accept ? List.of("tpyes") : List.of("tpno", "tpdeny"), "[player]", plugin);
super(
accept ? "tpaccept" : "tpdecline",
accept ? List.of("tpyes") : List.of("tpno", "tpdeny"),
"[player]",
plugin
);
this.accept = accept;
}
@@ -48,7 +48,8 @@ public class WarpCommand extends SavedPositionCommand<Warp> {
@Override
public void execute(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
if (plugin.getSettings().doPermissionRestrictWarps()) {
if (!executor.hasPermission(warp.getPermission()) && !executor.hasPermission(Warp.getWildcardPermission())) {
if (!executor.hasPermission(warp.getPermission())
&& !executor.hasPermission(Warp.getWildcardPermission())) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(executor::sendMessage);
return;
@@ -70,7 +70,10 @@ public class WarpListCommand extends ListCommand {
plugin.getLocales()
.getRawLocale("warp_list_item",
Locales.escapeText(warp.getName()), warp.getSafeIdentifier(),
Locales.escapeText(plugin.getLocales().wrapText(warp.getMeta().getDescription(), 40)))
Locales.escapeText(plugin.getLocales().wrapText(
warp.getMeta().getDescription(),
40
)))
.orElse(warp.getName())).sorted().collect(Collectors.toList()),
plugin.getLocales()
.getBaseList(plugin.getSettings().getListItemsPerPage())