Merge remote-tracking branch 'origin/master'

This commit is contained in:
William committed 2023-03-25 17:24:54 +00:00
commit f7c70e9994
25 files changed
+51 -54

No files matched your search

+3
View File
@@ -41,6 +41,9 @@ jobs:
modrinth-id: J6U9o3JG
modrinth-featured: false
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-dependencies: |
bluemap | suggests | *
dynmap | suggests | *
files-primary: target/HuskHomes-Plugin-*.jar
name: HuskHomes v${{ env.version_name }}
version: ${{ env.version_name }}
@@ -117,7 +117,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
this.manager = new Manager(this);
// Initialize the network messenger if proxy mode is enabled
if (getSettings().isCrossServer()) {
if (getSettings().doCrossServer()) {
initialize("message broker", (plugin) -> {
broker = switch (settings.getBrokerType()) {
case PLUGIN_MESSAGE -> new PluginMessageBroker(this);
@@ -391,7 +391,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
this.locales = Annotaml.create(new File(getDataFolder(), "messages_" + settings.getLanguage() + ".yml"), languagePresets).get();
// Load server from file
if (settings.isCrossServer()) {
if (settings.doCrossServer()) {
this.server = Annotaml.create(new File(getDataFolder(), "server.yml"), Server.class).get();
} else {
this.server = new Server(Server.getDefaultServerName());
@@ -423,8 +423,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
public void registerMetrics(int metricsId) {
try {
final Metrics metrics = new Metrics(this, metricsId);
metrics.addCustomChart(new SimplePie("bungee_mode", () -> Boolean.toString(getSettings().isCrossServer())));
if (getSettings().isCrossServer()) {
metrics.addCustomChart(new SimplePie("bungee_mode", () -> Boolean.toString(getSettings().doCrossServer())));
if (getSettings().doCrossServer()) {
metrics.addCustomChart(new SimplePie("messenger_type", () -> getSettings().getBrokerType().getDisplayName()));
}
metrics.addCustomChart(new SimplePie("language", () -> getSettings().getLanguage().toLowerCase()));
@@ -62,7 +62,7 @@ public class BukkitEventListener extends EventListener implements Listener {
// (https://jd.papermc.io/paper/1.19/com/destroystokyo/paper/event/player/PlayerSetSpawnEvent.html)
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerUpdateRespawnLocation(PlayerInteractEvent event) {
if (!(plugin.getSettings().isCrossServer() && plugin.getSettings().isGlobalRespawning())) return;
if (!(plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalRespawning())) return;
if (event.getClickedBlock() == null) return;
if (!(event.getClickedBlock().getBlockData() instanceof Bed
|| event.getClickedBlock().getBlockData() instanceof RespawnAnchor)) return;
@@ -147,7 +147,7 @@ public interface HuskHomes extends TaskRunner, EventDispatcher {
* @return the {@link Position} of the spawn, or an empty {@link Optional} if it has not been set
*/
default Optional<Position> getSpawn() {
return getSettings().isCrossServer() && getSettings().isGlobalSpawn()
return getSettings().doCrossServer() && getSettings().isGlobalSpawn()
? getDatabase().getWarp(getSettings().getGlobalSpawnName()).map(warp -> (Position) warp)
: getLocalCachedSpawn().map(spawn -> spawn.getPosition(getServerName()));
}
@@ -98,7 +98,7 @@ public abstract class BaseHuskHomesAPI {
* @since 3.0
*/
public CompletableFuture<Optional<Position>> getUserRespawnPosition(@NotNull User user) {
if (!plugin.getSettings().isCrossServer() || plugin.getSettings().isGlobalRespawning()) {
if (!plugin.getSettings().doCrossServer() || plugin.getSettings().isGlobalRespawning()) {
return CompletableFuture.completedFuture(Optional.empty());
}
return plugin.supplyAsync(() -> plugin.getDatabase().getRespawnPosition(user));
@@ -24,7 +24,7 @@ public class DelWarpCommand extends SavedPositionCommand<Warp> {
@Override
public void execute(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
if (plugin.getSettings().isPermissionRestrictWarps() && !executor.hasPermission(warp.getPermission())
if (plugin.getSettings().doPermissionRestrictWarps() && !executor.hasPermission(warp.getPermission())
&& !executor.hasPermission(Warp.getWildcardPermission())) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(executor::sendMessage);
@@ -227,13 +227,12 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
if (home.getMeta().getDescription().length() > 0) {
plugin.getLocales().getLocale("edit_home_menu_description",
home.getMeta().getDescription().length() > 50
? home.getMeta().getDescription().substring(0, 49).trim() + "…" : home.getMeta().getDescription(),
plugin.getLocales().truncateText(home.getMeta().getDescription(), 50),
plugin.getLocales().wrapText(home.getMeta().getDescription(), 40))
.ifPresent(this::add);
}
if (!plugin.getSettings().isCrossServer()) {
if (!plugin.getSettings().doCrossServer()) {
plugin.getLocales().getLocale("edit_home_menu_world", home.getWorld().getName())
.ifPresent(this::add);
} else {
@@ -135,13 +135,12 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
if (warp.getMeta().getDescription().length() > 0) {
plugin.getLocales().getLocale("edit_warp_menu_description",
warp.getMeta().getDescription().length() > 50
? warp.getMeta().getDescription().substring(0, 49).trim() + "…" : warp.getMeta().getDescription(),
plugin.getLocales().truncateText(warp.getMeta().getDescription(), 50),
plugin.getLocales().wrapText(warp.getMeta().getDescription(), 40))
.ifPresent(this::add);
}
if (!plugin.getSettings().isCrossServer()) {
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);
@@ -97,9 +97,8 @@ public class HuskHomesCommand extends Command implements TabProvider {
.filter(command -> user.hasPermission(command.getPermission()))
.map(command -> plugin.getLocales().getRawLocale("command_list_item",
Locales.escapeText(command.getName()),
Locales.escapeText(command.getDescription().length() > 50
? command.getDescription().substring(0, 49).trim() + "…"
: command.getDescription()),
Locales.escapeText(plugin.getLocales()
.truncateText(command.getDescription(), 50)),
Locales.escapeText(plugin.getLocales()
.wrapText(command.getUsage() + "\n" + command.getDescription(), 40)))
.orElse(command.getName()))
@@ -95,7 +95,7 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
private Optional<Warp> resolveWarp(@NotNull CommandUser executor, @NotNull String warpName) {
final Optional<Warp> warp = plugin.getDatabase().getWarp(warpName);
if (warp.isPresent() && executor instanceof OnlineUser user && plugin.getSettings().isPermissionRestrictWarps()
if (warp.isPresent() && executor instanceof OnlineUser user && plugin.getSettings().doPermissionRestrictWarps()
&& (!user.hasPermission(Warp.getWildcardPermission()) && !user.hasPermission(Warp.getPermission(warpName)))) {
plugin.getLocales().getLocale("error_warp_invalid", warpName)
.ifPresent(executor::sendMessage);
@@ -19,7 +19,7 @@ public class SetSpawnCommand extends InGameCommand {
public void execute(@NotNull OnlineUser executor, @NotNull String[] args) {
final Position position = executor.getPosition();
try {
if (plugin.getSettings().isCrossServer() && plugin.getSettings().isGlobalSpawn()) {
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")
@@ -39,7 +39,7 @@ public class TpAllCommand extends InGameCommand {
return;
}
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
Message.builder()
.target(Message.TARGET_ALL)
.type(Message.Type.TELEPORT_TO_POSITION)
@@ -27,7 +27,7 @@ public class WarpCommand extends SavedPositionCommand<Warp> {
@Override
public void execute(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
if (plugin.getSettings().isPermissionRestrictWarps()) {
if (plugin.getSettings().doPermissionRestrictWarps()) {
if (!executor.hasPermission(warp.getPermission()) && !executor.hasPermission(Warp.getWildcardPermission())) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(executor::sendMessage);
@@ -65,7 +65,7 @@ public class WarpListCommand extends ListCommand {
@NotNull
private List<Warp> getItems(@NotNull CommandUser executor) {
List<Warp> warps = plugin.getDatabase().getWarps();
if (plugin.getSettings().isPermissionRestrictWarps() && !executor.hasPermission(Warp.getWildcardPermission())) {
if (plugin.getSettings().doPermissionRestrictWarps() && !executor.hasPermission(Warp.getWildcardPermission())) {
warps = warps.stream()
.filter(warp -> executor.hasPermission(getPermission(warp.getPermission())))
.collect(Collectors.toList());
@@ -41,9 +41,6 @@ public class Locales {
* @return An {@link Optional} containing the locale corresponding to the id, if it exists
*/
public Optional<String> getRawLocale(@NotNull String localeId) {
if (!rawLocales.containsKey(localeId)) { // debug
return Optional.of(localeId + " (missing locale)"); // debug
} // debug
return Optional.ofNullable(rawLocales.get(localeId)).map(StringEscapeUtils::unescapeJava);
}
@@ -317,7 +317,7 @@ public class Settings {
return stackPermissionLimits;
}
public boolean isPermissionRestrictWarps() {
public boolean doPermissionRestrictWarps() {
return permissionRestrictWarps;
}
@@ -341,19 +341,19 @@ public class Settings {
return strictTpaHereRequests;
}
public boolean isAllowUnicodeNames() {
public boolean doAllowUnicodeNames() {
return allowUnicodeNames;
}
public boolean isAllowUnicodeDescriptions() {
public boolean doAllowUnicodeDescriptions() {
return allowUnicodeDescriptions;
}
public boolean isBackCommandReturnByDeath() {
public boolean doBackCommandReturnByDeath() {
return backCommandReturnByDeath;
}
public boolean isBackCommandSaveOnTeleportEvent() {
public boolean doBackCommandSaveOnTeleportEvent() {
return backCommandSaveOnTeleportEvent;
}
@@ -365,18 +365,18 @@ public class Settings {
return asynchronousTeleports;
}
public boolean isPlaySoundEffects() {
public boolean doPlaySoundEffects() {
return playSoundEffects;
}
public Optional<String> getSoundEffect(@NotNull SoundEffectAction action) {
if (!isPlaySoundEffects()) {
if (!doPlaySoundEffects()) {
return Optional.empty();
}
return Optional.ofNullable(soundEffects.get(action.name().toLowerCase()));
}
public boolean isCrossServer() {
public boolean doCrossServer() {
return crossServer;
}
@@ -90,7 +90,7 @@ public abstract class MapHook extends Hook {
return false;
}
return !plugin.getSettings().isCrossServer() || position.getServer().equals(plugin.getServerName());
return !plugin.getSettings().doCrossServer() || position.getServer().equals(plugin.getServerName());
}
@NotNull
@@ -46,7 +46,7 @@ public class PlanHook extends Hook {
private void registerDataExtension() {
try {
ExtensionService.getInstance().register(new PlanDataExtension(plugin.getDatabase(), plugin.getSettings().isCrossServer()));
ExtensionService.getInstance().register(new PlanDataExtension(plugin.getDatabase(), plugin.getSettings().doCrossServer()));
} catch (IllegalStateException planIsNotEnabled) {
plugin.log(Level.SEVERE, "Plan extension hook failed to register. Plan is not enabled.", planIsNotEnabled);
// Plan is not enabled, handle exception
@@ -40,7 +40,7 @@ public class EventListener {
plugin.getDatabase().ensureUser(onlineUser);
// Handle cross server checks
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
this.handleInboundTeleport(onlineUser);
// Synchronize the global player list
@@ -82,7 +82,7 @@ public class EventListener {
final Optional<Position> bedPosition = teleporter.getBedSpawnPosition();
if (bedPosition.isEmpty()) {
plugin.getSpawn().ifPresent(spawn -> {
if (plugin.getSettings().isCrossServer() && !spawn.getServer().equals(plugin.getServerName())) {
if (plugin.getSettings().doCrossServer() && !spawn.getServer().equals(plugin.getServerName())) {
plugin.runLater(() -> {
try {
Teleport.builder(plugin)
@@ -126,7 +126,7 @@ public class EventListener {
plugin.getManager().homes().removeUserHomes(onlineUser);
// Update global lists
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
final List<String> localPlayerList = plugin.getLocalPlayerList().stream()
.filter(player -> !player.equals(onlineUser.getUsername()))
.toList();
@@ -170,7 +170,7 @@ public class EventListener {
* @param onlineUser the {@link OnlineUser} who died
*/
protected final void handlePlayerDeath(@NotNull OnlineUser onlineUser) {
if (plugin.getSettings().isBackCommandReturnByDeath() && plugin.getCommand(BackCommand.class)
if (plugin.getSettings().doBackCommandReturnByDeath() && plugin.getCommand(BackCommand.class)
.map(Command::getPermission).map(onlineUser::hasPermission).orElse(false)) {
plugin.getDatabase().setLastPosition(onlineUser, onlineUser.getPosition());
}
@@ -188,13 +188,13 @@ public class EventListener {
.map(command -> onlineUser.hasPermission(command.getPermission())
&& onlineUser.hasPermission(command.getPermission("death")))
.orElse(false);
if (plugin.getSettings().isBackCommandReturnByDeath() && canReturnByDeath) {
if (plugin.getSettings().doBackCommandReturnByDeath() && canReturnByDeath) {
plugin.getLocales().getLocale("return_by_death_notification")
.ifPresent(onlineUser::sendMessage);
}
// Respawn the player cross-server if needed
if (plugin.getSettings().isCrossServer() && plugin.getSettings().isGlobalRespawning()) {
if (plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalRespawning()) {
plugin.getDatabase().getRespawnPosition(onlineUser).ifPresent(respawnPosition -> {
if (!respawnPosition.getServer().equals(plugin.getServerName())) {
Teleport.builder(plugin)
@@ -216,7 +216,7 @@ public class EventListener {
* @param sourcePosition the source {@link Position} they came from
*/
protected final void handlePlayerTeleport(@NotNull OnlineUser onlineUser, @NotNull Position sourcePosition) {
if (!plugin.getSettings().isBackCommandSaveOnTeleportEvent()) {
if (!plugin.getSettings().doBackCommandSaveOnTeleportEvent()) {
return;
}
@@ -231,7 +231,7 @@ public class EventListener {
* @param position the new spawn point
*/
protected final void handlePlayerUpdateSpawnPoint(@NotNull OnlineUser onlineUser, @NotNull Position position) {
if (plugin.getSettings().isCrossServer() && plugin.getSettings().isGlobalRespawning()) {
if (plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalRespawning()) {
plugin.getDatabase().setRespawnPosition(onlineUser, position);
}
}
@@ -80,7 +80,7 @@ public class HomesManager {
}
private void propagateCacheUpdate(@NotNull UUID homeId) {
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
.type(Message.Type.UPDATE_HOME)
.scope(Message.Scope.SERVER)
@@ -35,7 +35,7 @@ public class Manager {
// Update caches on all servers
protected void propagateCacheUpdate() {
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
.type(Message.Type.UPDATE_CACHES)
.scope(Message.Scope.SERVER)
@@ -121,7 +121,7 @@ public class RequestsManager {
sendLocalTeleportRequest(request, onlineUser);
}
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
Message.builder()
.type(Message.Type.TELEPORT_REQUEST)
.payload(Payload.withTeleportRequest(request))
@@ -151,7 +151,7 @@ public class RequestsManager {
}
// If the player couldn't be found locally, send the request cross-server
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
request.setRecipientName(targetUser);
Message.builder()
.type(Message.Type.TELEPORT_REQUEST)
@@ -272,7 +272,7 @@ public class RequestsManager {
final Optional<OnlineUser> localRequester = plugin.findOnlinePlayer(request.getRequesterName());
if (localRequester.isPresent()) {
handleLocalRequestResponse(localRequester.get(), request);
} else if (plugin.getSettings().isCrossServer()) {
} else if (plugin.getSettings().doCrossServer()) {
Message.builder()
.type(Message.Type.TELEPORT_REQUEST_RESPONSE)
.payload(Payload.withTeleportRequest(request))
@@ -49,7 +49,7 @@ public class WarpsManager {
}
private void propagateCacheUpdate(@NotNull UUID warpId) {
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
.type(Message.Type.UPDATE_WARP)
.scope(Message.Scope.SERVER)
@@ -56,7 +56,7 @@ public class Teleport {
// Teleport a user on another server
if (localTeleporter.isEmpty()) {
final Username teleporter = (Username) this.teleporter;
if (!plugin.getSettings().isCrossServer()) {
if (!plugin.getSettings().doCrossServer()) {
throw new TeleportationException(TeleportationException.Type.TELEPORTER_NOT_FOUND);
}
@@ -98,7 +98,7 @@ public class Teleport {
return;
}
if (plugin.getSettings().isCrossServer()) {
if (plugin.getSettings().doCrossServer()) {
fireEvent((event) -> {
executeEconomyActions();
Message.builder()
@@ -119,7 +119,7 @@ public class Teleport {
}
final Position target = (Position) this.target;
if (!plugin.getSettings().isCrossServer() || target.getServer().equals(plugin.getServerName())) {
if (!plugin.getSettings().doCrossServer() || target.getServer().equals(plugin.getServerName())) {
teleporter.teleportLocally(target, async);
this.displayTeleportingComplete(teleporter);
return;
@@ -23,7 +23,7 @@ public class Validator {
* @return True if the name is valid as per the plugin settings, false otherwise
*/
public boolean isValidName(@NotNull String name) {
return (isAsciiOnly(name) || plugin.getSettings().isAllowUnicodeNames())
return (isAsciiOnly(name) || plugin.getSettings().doAllowUnicodeNames())
&& !containsWhitespace(name)
&& name.length() <= MAX_NAME_LENGTH && name.length() >= MIN_NAME_LENGTH;
}
@@ -35,7 +35,7 @@ public class Validator {
* @return Whether the meta is valid against the plugin settings
*/
public boolean isValidDescription(@NotNull String description) {
return (isAsciiOnly(description) || plugin.getSettings().isAllowUnicodeDescriptions())
return (isAsciiOnly(description) || plugin.getSettings().doAllowUnicodeDescriptions())
&& description.length() <= MAX_DESCRIPTION_LENGTH;
}