mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
1 parent
1dc45b8286
commit
b7cf0fa590
18 files changed
+111
-67
No files matched your search
@@ -163,6 +163,7 @@ public class Cache {
|
|||||||
if (eventDispatcher.dispatchViewHomeListEvent(homes, onlineUser, false).join().isCancelled()) {
|
if (eventDispatcher.dispatchViewHomeListEvent(homes, onlineUser, false).join().isCancelled()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
final String homeListArguments = !onlineUser.equals(homeOwner) ? " " + homeOwner.username : "";
|
||||||
final PaginatedList homeList = PaginatedList.of(homes.stream().map(home ->
|
final PaginatedList homeList = PaginatedList.of(homes.stream().map(home ->
|
||||||
locales.getRawLocale("home_list_item",
|
locales.getRawLocale("home_list_item",
|
||||||
Locales.escapeMineDown(home.meta.name),
|
Locales.escapeMineDown(home.meta.name),
|
||||||
@@ -172,7 +173,7 @@ public class Cache {
|
|||||||
.setHeaderFormat(locales.getRawLocale("home_list_page_title",
|
.setHeaderFormat(locales.getRawLocale("home_list_page_title",
|
||||||
homeOwner.username, "%first_item_on_page_index%",
|
homeOwner.username, "%first_item_on_page_index%",
|
||||||
"%last_item_on_page_index%", "%total_items%").orElse(""))
|
"%last_item_on_page_index%", "%total_items%").orElse(""))
|
||||||
.setCommand("/huskhomes:homelist").build());
|
.setCommand("/huskhomes:homelist" + homeListArguments).build());
|
||||||
this.privateHomeLists.put(homeOwner.username, homeList);
|
this.privateHomeLists.put(homeOwner.username, homeList);
|
||||||
return Optional.of(homeList.getNearestValidPage(page));
|
return Optional.of(homeList.getNearestValidPage(page));
|
||||||
}
|
}
|
||||||
@@ -200,18 +201,15 @@ public class Cache {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Optional<MineDown> getWarpList(@NotNull OnlineUser onlineUser, @NotNull Locales locales,
|
public Optional<MineDown> getWarpList(@NotNull OnlineUser onlineUser, @NotNull Locales locales,
|
||||||
@NotNull List<Warp> warps, final boolean permissionRestrictWarps,
|
@NotNull List<Warp> warps, final int itemsPerPage, final int page) {
|
||||||
final int itemsPerPage, final int page) {
|
|
||||||
if (eventDispatcher.dispatchViewWarpListEvent(warps, onlineUser).join().isCancelled()) {
|
if (eventDispatcher.dispatchViewWarpListEvent(warps, onlineUser).join().isCancelled()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
final PaginatedList warpList = PaginatedList.of(warps.stream()
|
final PaginatedList warpList = PaginatedList.of(warps.stream()
|
||||||
.filter(warp -> !permissionRestrictWarps || onlineUser.hasPermission(warp.getPermissionNode()))
|
.map(warp -> locales.getRawLocale("warp_list_item",
|
||||||
.map(warp ->
|
Locales.escapeMineDown(warp.meta.name),
|
||||||
locales.getRawLocale("warp_list_item",
|
Locales.escapeMineDown(locales.formatDescription(warp.meta.description)))
|
||||||
Locales.escapeMineDown(warp.meta.name),
|
.orElse(warp.meta.name)).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage)
|
||||||
Locales.escapeMineDown(locales.formatDescription(warp.meta.description)))
|
|
||||||
.orElse(warp.meta.name)).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage)
|
|
||||||
.setHeaderFormat(locales.getRawLocale("warp_list_page_title",
|
.setHeaderFormat(locales.getRawLocale("warp_list_page_title",
|
||||||
"%first_item_on_page_index%", "%last_item_on_page_index%",
|
"%first_item_on_page_index%", "%last_item_on_page_index%",
|
||||||
"%total_items%").orElse(""))
|
"%total_items%").orElse(""))
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package net.william278.huskhomes.command;
|
|||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
|
import org.intellij.lang.annotations.Pattern;
|
||||||
|
import org.intellij.lang.annotations.Subst;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +28,7 @@ public abstract class CommandBase {
|
|||||||
* The permission node required to use this command
|
* The permission node required to use this command
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@Pattern(Permission.PERMISSION_PATTERN)
|
||||||
public final String permission;
|
public final String permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,8 +37,8 @@ public abstract class CommandBase {
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected final HuskHomes plugin;
|
protected final HuskHomes plugin;
|
||||||
|
|
||||||
protected CommandBase(@NotNull String command, @NotNull Permission permission, @NotNull HuskHomes implementor,
|
protected CommandBase(@NotNull String command, @NotNull @Subst("huskhomes") Permission permission,
|
||||||
@NotNull String... aliases) {
|
@NotNull HuskHomes implementor, @NotNull String... aliases) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.permission = permission.node;
|
this.permission = permission.node;
|
||||||
this.plugin = implementor;
|
this.plugin = implementor;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
private void deletePlayerHome(@NotNull OnlineUser deleter, @NotNull User homeOwner, @NotNull String homeName,
|
private void deletePlayerHome(@NotNull OnlineUser deleter, @NotNull User homeOwner, @NotNull String homeName,
|
||||||
final boolean delHomeAllConfirm) {
|
final boolean delHomeAllConfirm) {
|
||||||
plugin.getSavedPositionManager().deleteHome(homeOwner, homeName).thenAccept(deleted -> {
|
plugin.getSavedPositionManager().deleteHome(homeOwner, homeName).thenAccept(deleted -> {
|
||||||
if (deleter.uuid.equals(homeOwner.uuid)) {
|
if (deleter.equals(homeOwner)) {
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage);
|
plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
private void editHome(@NotNull Home home, @NotNull OnlineUser editor,
|
private void editHome(@NotNull Home home, @NotNull OnlineUser editor,
|
||||||
@Nullable String editOperation, @Nullable String editArgs) {
|
@Nullable String editOperation, @Nullable String editArgs) {
|
||||||
final AtomicBoolean showMenuFlag = new AtomicBoolean(false);
|
final AtomicBoolean showMenuFlag = new AtomicBoolean(false);
|
||||||
final boolean otherOwner = !editor.uuid.equals(home.owner.uuid);
|
final boolean otherOwner = !editor.equals(home.owner);
|
||||||
|
|
||||||
if (editOperation == null) {
|
if (editOperation == null) {
|
||||||
getHomeEditorWindow(home, true, otherOwner,
|
getHomeEditorWindow(home, true, otherOwner,
|
||||||
@@ -119,7 +119,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(newHomeName, home.meta.description))
|
plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(newHomeName, home.meta.description))
|
||||||
.thenAccept(renameResult -> (switch (renameResult.resultType()) {
|
.thenAccept(renameResult -> (switch (renameResult.resultType()) {
|
||||||
case SUCCESS -> {
|
case SUCCESS -> {
|
||||||
if (home.owner.uuid.equals(editor.uuid)) {
|
if (home.owner.equals(editor)) {
|
||||||
yield plugin.getLocales().getLocale("edit_home_update_name",
|
yield plugin.getLocales().getLocale("edit_home_update_name",
|
||||||
oldHomeName, newHomeName);
|
oldHomeName, newHomeName);
|
||||||
} else {
|
} else {
|
||||||
@@ -140,7 +140,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(home.meta.name, newDescription))
|
plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(home.meta.name, newDescription))
|
||||||
.thenAccept(descriptionUpdateResult -> (switch (descriptionUpdateResult.resultType()) {
|
.thenAccept(descriptionUpdateResult -> (switch (descriptionUpdateResult.resultType()) {
|
||||||
case SUCCESS -> {
|
case SUCCESS -> {
|
||||||
if (home.owner.uuid.equals(editor.uuid)) {
|
if (home.owner.equals(editor)) {
|
||||||
yield plugin.getLocales().getLocale("edit_home_update_description",
|
yield plugin.getLocales().getLocale("edit_home_update_description",
|
||||||
home.meta.name,
|
home.meta.name,
|
||||||
oldHomeDescription.isBlank() ? plugin.getLocales()
|
oldHomeDescription.isBlank() ? plugin.getLocales()
|
||||||
@@ -166,7 +166,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
}
|
}
|
||||||
case "relocate" ->
|
case "relocate" ->
|
||||||
plugin.getSavedPositionManager().updateHomePosition(home, editor.getPosition()).thenRun(() -> {
|
plugin.getSavedPositionManager().updateHomePosition(home, editor.getPosition()).thenRun(() -> {
|
||||||
if (home.owner.uuid.equals(editor.uuid)) {
|
if (home.owner.equals(editor)) {
|
||||||
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location",
|
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location",
|
||||||
home.meta.name).orElse(new MineDown("")));
|
home.meta.name).orElse(new MineDown("")));
|
||||||
} else {
|
} else {
|
||||||
@@ -233,7 +233,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
|
|
||||||
// Execute the update
|
// Execute the update
|
||||||
plugin.getSavedPositionManager().updateHomePrivacy(home, newIsPublic.get()).thenRun(() -> {
|
plugin.getSavedPositionManager().updateHomePrivacy(home, newIsPublic.get()).thenRun(() -> {
|
||||||
if (home.owner.uuid.equals(editor.uuid)) {
|
if (home.owner.equals(editor)) {
|
||||||
editor.sendMessage(plugin.getLocales().getLocale(
|
editor.sendMessage(plugin.getLocales().getLocale(
|
||||||
"edit_home_privacy_" + privacyKeyedString + "_success",
|
"edit_home_privacy_" + privacyKeyedString + "_success",
|
||||||
home.meta.name).orElse(new MineDown("")));
|
home.meta.name).orElse(new MineDown("")));
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
||||||
final boolean otherHome = !owner.uuid.equals(teleporter.uuid);
|
final boolean otherHome = !owner.equals(teleporter);
|
||||||
plugin.getDatabase()
|
plugin.getDatabase()
|
||||||
.getHome(owner, homeName)
|
.getHome(owner, homeName)
|
||||||
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
|
|||||||
}
|
}
|
||||||
plugin.getDatabase().getHomes(userData.user()).thenAcceptAsync(homes -> {
|
plugin.getDatabase().getHomes(userData.user()).thenAcceptAsync(homes -> {
|
||||||
if (homes.isEmpty()) {
|
if (homes.isEmpty()) {
|
||||||
if (!onlineUser.uuid.equals(userData.user().uuid)) {
|
if (!onlineUser.equals(userData.user())) {
|
||||||
plugin.getLocales().getLocale("error_no_homes_set_other",
|
plugin.getLocales().getLocale("error_no_homes_set_other",
|
||||||
userData.user().username).ifPresent(onlineUser::sendMessage);
|
userData.user().username).ifPresent(onlineUser::sendMessage);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
||||||
final boolean otherHome = !owner.uuid.equals(teleporter.uuid);
|
final boolean otherHome = !owner.equals(teleporter);
|
||||||
plugin.getDatabase()
|
plugin.getDatabase()
|
||||||
.getHome(owner, homeName)
|
.getHome(owner, homeName)
|
||||||
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
||||||
@@ -114,7 +114,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
|||||||
.orElse(null)),
|
.orElse(null)),
|
||||||
() -> matchedHome.set(plugin.getDatabase().getPublicHomes().join()
|
() -> matchedHome.set(plugin.getDatabase().getPublicHomes().join()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(home -> home.owner.uuid.equals(playerToTeleport.uuid) && home.meta.name.equalsIgnoreCase(args[1]))
|
.filter(home -> home.owner.equals(playerToTeleport) && home.meta.name.equalsIgnoreCase(args[1]))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null)));
|
.orElse(null)));
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final OnlineUser userToTeleport = target;
|
final OnlineUser userToTeleport = target;
|
||||||
final boolean isExecutorTeleporting = userToTeleport.uuid.equals(onlineUser.uuid);
|
final boolean isExecutorTeleporting = userToTeleport.equals(onlineUser);
|
||||||
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> {
|
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> {
|
||||||
// Check the user is not still on /rtp cooldown
|
// Check the user is not still on /rtp cooldown
|
||||||
if (userData.isEmpty()) {
|
if (userData.isEmpty()) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import net.william278.huskhomes.position.Warp;
|
|||||||
import net.william278.huskhomes.teleport.Teleport;
|
import net.william278.huskhomes.teleport.Teleport;
|
||||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.intellij.lang.annotations.Subst;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -23,30 +22,30 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
|
|||||||
@Override
|
@Override
|
||||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0 -> plugin.getDatabase().getWarps().thenAcceptAsync(warps -> {
|
case 0 -> plugin.getDatabase().getWarps()
|
||||||
if (warps.isEmpty()) {
|
.thenApply(warps -> warps.stream()
|
||||||
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
|
.filter(warp -> warp.hasPermission(plugin.getSettings().permissionRestrictWarps, onlineUser))
|
||||||
return;
|
.collect(Collectors.toList()))
|
||||||
}
|
.thenAccept(warps -> {
|
||||||
plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
|
if (warps.isEmpty()) {
|
||||||
plugin.getSettings().permissionRestrictWarps,
|
plugin.getLocales().getLocale("error_no_warps_set")
|
||||||
plugin.getSettings().listItemsPerPage, 1)
|
.ifPresent(onlineUser::sendMessage);
|
||||||
.ifPresent(onlineUser::sendMessage);
|
return;
|
||||||
});
|
}
|
||||||
|
plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
|
||||||
|
plugin.getSettings().listItemsPerPage, 1)
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
});
|
||||||
case 1 -> {
|
case 1 -> {
|
||||||
final String warpName = args[0];
|
final String warpName = args[0];
|
||||||
plugin.getDatabase()
|
plugin.getDatabase()
|
||||||
.getWarp(warpName)
|
.getWarp(warpName)
|
||||||
.thenAccept(warpResult -> warpResult.ifPresentOrElse(warp -> {
|
.thenAccept(warpResult -> warpResult.ifPresentOrElse(warp -> {
|
||||||
// Handle permission restrictions
|
// Handle permission restrictions
|
||||||
if (plugin.getSettings().permissionRestrictWarps) {
|
if (!warp.hasPermission(plugin.getSettings().permissionRestrictWarps, onlineUser)) {
|
||||||
@Subst("huskhomes.command.warp") final String warpPermission = Permission.COMMAND_WARP.node + "." + warp.meta.name;
|
plugin.getLocales().getLocale("error_no_permission")
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
if (!onlineUser.hasPermission(warpPermission) && !onlineUser.hasPermission(Permission.COMMAND_SET_WARP.node)) {
|
return;
|
||||||
plugin.getLocales().getLocale("error_no_permission")
|
|
||||||
.ifPresent(onlineUser::sendMessage);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Teleport.builder(plugin, onlineUser)
|
Teleport.builder(plugin, onlineUser)
|
||||||
@@ -65,8 +64,7 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
|
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||||
return plugin.getCache().warps.stream()
|
return plugin.getCache().warps.stream()
|
||||||
.filter(s -> user == null || plugin.getSettings().permissionRestrictWarps && !user.hasPermission(
|
.filter(s -> user == null || Warp.hasPermission(plugin.getSettings().permissionRestrictWarps, user, s))
|
||||||
Permission.COMMAND_SET_WARP.node) && user.hasPermission(Warp.getPermissionNode(s)))
|
|
||||||
.filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : ""))
|
.filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : ""))
|
||||||
.sorted()
|
.sorted()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class WarpListCommand extends CommandBase implements ConsoleExecutable {
|
public class WarpListCommand extends CommandBase implements ConsoleExecutable {
|
||||||
|
|
||||||
@@ -45,17 +46,19 @@ public class WarpListCommand extends CommandBase implements ConsoleExecutable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch the warp list event
|
// Dispatch the warp list event
|
||||||
plugin.getDatabase().getWarps().thenAcceptAsync(warps -> {
|
plugin.getDatabase().getWarps()
|
||||||
if (warps.isEmpty()) {
|
.thenApply(warps -> warps.stream()
|
||||||
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
|
.filter(warp -> warp.hasPermission(plugin.getSettings().permissionRestrictWarps, onlineUser))
|
||||||
return;
|
.collect(Collectors.toList()))
|
||||||
}
|
.thenAccept(warps -> {
|
||||||
plugin.getCache().getWarpList(onlineUser,
|
if (warps.isEmpty()) {
|
||||||
plugin.getLocales(), warps,
|
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
|
||||||
plugin.getSettings().permissionRestrictWarps,
|
return;
|
||||||
plugin.getSettings().listItemsPerPage,
|
}
|
||||||
pageNumber).ifPresent(onlineUser::sendMessage);
|
plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
|
||||||
});
|
plugin.getSettings().listItemsPerPage, pageNumber)
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ public abstract class Database {
|
|||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
} catch (HuskHomesException e) {
|
} catch (HuskHomesException e) {
|
||||||
return getWarps().thenApplyAsync(warps -> warps.stream()
|
return getWarps().thenApplyAsync(warps -> warps.stream()
|
||||||
.filter(warp -> plugin.getWorlds().stream().anyMatch(world -> world.uuid.equals(warp.world.uuid)))
|
.filter(warp -> plugin.getWorlds().stream().anyMatch(world -> world.equals(warp.world)))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ public abstract class Database {
|
|||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
} catch (HuskHomesException e) {
|
} catch (HuskHomesException e) {
|
||||||
return plugin.getDatabase().getPublicHomes().thenApplyAsync(homes -> homes.stream()
|
return plugin.getDatabase().getPublicHomes().thenApplyAsync(homes -> homes.stream()
|
||||||
.filter(home -> plugin.getWorlds().stream().anyMatch(world -> world.uuid.equals(home.world.uuid)))
|
.filter(home -> plugin.getWorlds().stream().anyMatch(world -> world.equals(home.world)))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class EventListener {
|
|||||||
// Update the cached player list using another online player if possible
|
// Update the cached player list using another online player if possible
|
||||||
plugin.getOnlinePlayers()
|
plugin.getOnlinePlayers()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(onlinePlayer -> !onlinePlayer.uuid.equals(onlineUser.uuid))
|
.filter(onlinePlayer -> !onlinePlayer.equals(onlineUser))
|
||||||
.findAny()
|
.findAny()
|
||||||
.ifPresent(updater -> plugin.getCache().updatePlayerListCache(plugin, updater));
|
.ifPresent(updater -> plugin.getCache().updatePlayerListCache(plugin, updater));
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(@NotNull Object other) {
|
||||||
if (other instanceof Message message) {
|
if (other instanceof Message message) {
|
||||||
return message.uuid.equals(this.uuid);
|
return message.uuid.equals(this.uuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,11 @@ public class User {
|
|||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@NotNull Object obj) {
|
||||||
|
if (obj instanceof User user) {
|
||||||
|
return user.uuid.equals(uuid);
|
||||||
|
}
|
||||||
|
return super.equals(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.william278.huskhomes.position;
|
package net.william278.huskhomes.position;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,13 +17,14 @@ public class Server {
|
|||||||
this.name = (name != null ? name : "server");
|
this.name = (name != null ? name : "server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public Server() {
|
public Server() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(@NotNull Object other) {
|
||||||
|
// If the name of this server matches another, the servers are the same.
|
||||||
if (other instanceof Server server) {
|
if (other instanceof Server server) {
|
||||||
// If the name of this server matches another, the servers are the same.
|
|
||||||
return server.name.equalsIgnoreCase(this.name);
|
return server.name.equalsIgnoreCase(this.name);
|
||||||
}
|
}
|
||||||
return super.equals(other);
|
return super.equals(other);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.william278.huskhomes.position;
|
package net.william278.huskhomes.position;
|
||||||
|
|
||||||
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.intellij.lang.annotations.Subst;
|
import org.intellij.lang.annotations.Subst;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -27,16 +28,40 @@ public class Warp extends SavedPosition {
|
|||||||
super(position, meta);
|
super(position, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
/**
|
||||||
@Subst("huskhomes.command.warp")
|
* Get the permission node for a warp
|
||||||
public String getPermissionNode() {
|
*
|
||||||
return getPermissionNode(meta.name);
|
* @param warp The warp name
|
||||||
}
|
* @return The permission node
|
||||||
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
@Subst("huskhomes.command.warp")
|
@Subst("huskhomes.command.warp")
|
||||||
public static String getPermissionNode(@NotNull String warp) {
|
public static String getPermissionNode(@NotNull String warp) {
|
||||||
return Permission.COMMAND_WARP + "." + warp;
|
return Permission.COMMAND_WARP + "." + warp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a {@link OnlineUser} has permission to teleport to this warp
|
||||||
|
*
|
||||||
|
* @param restrictWarps Whether to restrict warps to permission nodes
|
||||||
|
* @param user The {@link OnlineUser} to check
|
||||||
|
* @return true if the user has permission to teleport to this warp
|
||||||
|
*/
|
||||||
|
public boolean hasPermission(boolean restrictWarps, @NotNull OnlineUser user) {
|
||||||
|
return hasPermission(restrictWarps, user, meta.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a {@link OnlineUser} has permission to teleport to this warp
|
||||||
|
*
|
||||||
|
* @param restrictWarps Whether to restrict warps to permission nodes
|
||||||
|
* @param user The {@link OnlineUser} to check
|
||||||
|
* @param warp The warp name to check
|
||||||
|
* @return true if the user has permission to teleport to this warp
|
||||||
|
*/
|
||||||
|
public static boolean hasPermission(boolean restrictWarps, @NotNull OnlineUser user, @NotNull String warp) {
|
||||||
|
return !restrictWarps || (user.hasPermission(Permission.COMMAND_SET_WARP.node)
|
||||||
|
|| user.hasPermission(getPermissionNode(warp)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,7 @@ public class World {
|
|||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public World() {
|
public World() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,4 +52,11 @@ public class World {
|
|||||||
CUSTOM
|
CUSTOM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@NotNull Object obj) {
|
||||||
|
if (obj instanceof World world) {
|
||||||
|
return world.uuid.equals(uuid);
|
||||||
|
}
|
||||||
|
return super.equals(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ public class RequestManager {
|
|||||||
Instant.now().getEpochSecond() + plugin.getSettings().teleportRequestExpiryTime);
|
Instant.now().getEpochSecond() + plugin.getSettings().teleportRequestExpiryTime);
|
||||||
final Optional<OnlineUser> localTarget = plugin.findOnlinePlayer(targetUser);
|
final Optional<OnlineUser> localTarget = plugin.findOnlinePlayer(targetUser);
|
||||||
if (localTarget.isPresent()) {
|
if (localTarget.isPresent()) {
|
||||||
if (localTarget.get().uuid.equals(requester.uuid)) {
|
if (localTarget.get().equals(requester)) {
|
||||||
return CompletableFuture.completedFuture(Optional.empty());
|
return CompletableFuture.completedFuture(Optional.empty());
|
||||||
}
|
}
|
||||||
request.recipientName = localTarget.get().username;
|
request.recipientName = localTarget.get().username;
|
||||||
|
|||||||
Reference in new issue
Block a user