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

@@ -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;
}
}