mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +00:00
feat: add restricted worlds for /back
also adds docs for this
This commit is contained in:
1 parent
0e975232c0
commit
f7528ef95d
10 files changed
+149
-48
No files matched your search
@@ -124,11 +124,11 @@ public final class Settings {
|
||||
private int maxHomes = 10;
|
||||
|
||||
@Comment("The maximum public homes a user can create. "
|
||||
+ "Override with the huskhomes.max_public_homes.<number> permission.")
|
||||
+ "Override with the huskhomes.max_public_homes.<number> permission.")
|
||||
private int maxPublicHomes = 10;
|
||||
|
||||
@Comment("Whether permission limits (i.e. huskhomes.max_homes.<number>) should stack "
|
||||
+ "if the user inherits multiple nodes.")
|
||||
+ "if the user inherits multiple nodes.")
|
||||
private boolean stackPermissionLimits = false;
|
||||
|
||||
@Comment("Whether users require a permission (huskhomes.warp.<warp_name>) to use warps")
|
||||
@@ -153,14 +153,14 @@ public final class Settings {
|
||||
private int teleportRequestExpiryTime = 60;
|
||||
|
||||
@Comment("Whether /tpahere should use the location of the sender when sent. "
|
||||
+ "Docs: https://william278.net/docs/huskhomes/strict-tpahere/")
|
||||
+ "Docs: https://william278.net/docs/huskhomes/strict-tpahere/")
|
||||
private boolean strictTpaHereRequests = true;
|
||||
|
||||
@Comment("How many items should be displayed per-page in chat menu lists")
|
||||
private int listItemsPerPage = 12;
|
||||
|
||||
@Comment("Whether the user should always be put back at the /spawn point when they die "
|
||||
+ "(ignores beds/respawn anchors)")
|
||||
+ "(ignores beds/respawn anchors)")
|
||||
private boolean alwaysRespawnAtSpawn = false;
|
||||
|
||||
@Comment("Whether teleportation should be carried out async (ensuring chunks load before teleporting)")
|
||||
@@ -180,7 +180,7 @@ public final class Settings {
|
||||
private boolean caseInsensitive = false;
|
||||
|
||||
@Comment("Whether home and warp names should be restricted to a regex filter."
|
||||
+ "Set this to false to allow full UTF-8 names (i.e. allow /home 你好).")
|
||||
+ "Set this to false to allow full UTF-8 names (i.e. allow /home 你好).")
|
||||
private boolean restrict = true;
|
||||
|
||||
@Comment("Regex which home and warp names must match. Names have a max length of 16 characters")
|
||||
@@ -195,11 +195,11 @@ public final class Settings {
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public static class DescriptionSettings {
|
||||
@Comment("Whether home/warp descriptions should be restricted to a regex filter. "
|
||||
+ "Set this to true to restrict UTF-8 usage.")
|
||||
+ "Set this to true to restrict UTF-8 usage.")
|
||||
private boolean restrict = false;
|
||||
|
||||
@Comment("Regex which home and warp descriptions must match. "
|
||||
+ "A hard max length of 256 characters is enforced")
|
||||
+ "A hard max length of 256 characters is enforced")
|
||||
private String regex = "\\A\\p{ASCII}*\\z";
|
||||
}
|
||||
|
||||
@@ -215,6 +215,19 @@ public final class Settings {
|
||||
|
||||
@Comment("Whether /back should work with other plugins that use the PlayerTeleportEvent (can conflict)")
|
||||
private boolean saveOnTeleportEvent = false;
|
||||
|
||||
@Comment({"List of world names where the /back command cannot RETURN the player to. ",
|
||||
"A user's last position won't be updated if they die or teleport from these worlds, but they still "
|
||||
+ "will be able to use the command while IN the world."})
|
||||
private List<String> restrictedWorlds = new ArrayList<>();
|
||||
|
||||
public boolean canReturnToWorld(@NotNull World world) {
|
||||
final String name = world.getName();
|
||||
final String formattedName = name.replace("minecraft:", "");
|
||||
return restrictedWorlds.stream()
|
||||
.map(n -> n.replace("minecraft:", ""))
|
||||
.anyMatch(n -> n.equalsIgnoreCase(formattedName));
|
||||
}
|
||||
}
|
||||
|
||||
@Comment("Settings for sound effects")
|
||||
@@ -286,7 +299,7 @@ public final class Settings {
|
||||
}
|
||||
|
||||
@Comment("Define a single global /spawn for your network via a warp. "
|
||||
+ "Docs: https://william278.net/docs/huskhomes/global-spawn/")
|
||||
+ "Docs: https://william278.net/docs/huskhomes/global-spawn/")
|
||||
private GlobalSpawnSettings globalSpawn = new GlobalSpawnSettings();
|
||||
|
||||
@Getter
|
||||
@@ -300,7 +313,7 @@ public final class Settings {
|
||||
}
|
||||
|
||||
@Comment("Whether player respawn positions should work cross-server. "
|
||||
+ "Docs: https://william278.net/docs/huskhomes/global-respawning/")
|
||||
+ "Docs: https://william278.net/docs/huskhomes/global-respawning/")
|
||||
private boolean globalRespawning = false;
|
||||
}
|
||||
|
||||
@@ -428,7 +441,7 @@ public final class Settings {
|
||||
.anyMatch(disabled -> {
|
||||
final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled);
|
||||
return command.equalsIgnoreCase(type.getName())
|
||||
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
|
||||
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package net.william278.huskhomes.hook;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.importer.Importer;
|
||||
|
||||
@@ -24,17 +24,18 @@ import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.command.BackCommand;
|
||||
import net.william278.huskhomes.command.Command;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.network.Broker;
|
||||
import net.william278.huskhomes.network.Message;
|
||||
import net.william278.huskhomes.network.Payload;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TeleportBuilder;
|
||||
import net.william278.huskhomes.teleport.TeleportationException;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.Blocking;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -68,8 +69,8 @@ public abstract class EventListener {
|
||||
|
||||
// Synchronize the global player list
|
||||
plugin.runSyncDelayed(() -> this.updateUserList(
|
||||
onlineUser,
|
||||
plugin.getOnlineUsers().stream().map(u -> (User) u).toList()),
|
||||
onlineUser,
|
||||
plugin.getOnlineUsers().stream().map(u -> (User) u).toList()),
|
||||
onlineUser,
|
||||
40L
|
||||
);
|
||||
@@ -108,7 +109,7 @@ public abstract class EventListener {
|
||||
online.removeInvulnerabilityIfPermitted();
|
||||
|
||||
plugin.runAsync(() -> {
|
||||
// Set offline position
|
||||
// Set offline position
|
||||
plugin.getDatabase().setOfflinePosition(online, online.getPosition());
|
||||
|
||||
// Remove this user's home cache
|
||||
@@ -166,7 +167,7 @@ public abstract class EventListener {
|
||||
if (bedPosition.isEmpty()) {
|
||||
plugin.getSpawn().ifPresent(spawn -> {
|
||||
if (plugin.getSettings().getCrossServer().isEnabled()
|
||||
&& !spawn.getServer().equals(plugin.getServerName())) {
|
||||
&& !spawn.getServer().equals(plugin.getServerName())) {
|
||||
plugin.runSyncDelayed(() -> Teleport.builder(plugin)
|
||||
.teleporter(teleporter)
|
||||
.target(spawn)
|
||||
@@ -220,11 +221,24 @@ public abstract class EventListener {
|
||||
*/
|
||||
protected final void handlePlayerDeath(@NotNull OnlineUser onlineUser) {
|
||||
final Position lastPosition = onlineUser.getPosition();
|
||||
final World lastWorld = lastPosition.getWorld();
|
||||
|
||||
// Check the user can use /back to return here
|
||||
final BackCommand command = plugin.getCommand(BackCommand.class).orElse(null);
|
||||
if (command == null || !onlineUser.hasPermission(command.getPermission()) ||
|
||||
!onlineUser.hasPermission(command.getPermission("back"))) {
|
||||
return;
|
||||
}
|
||||
final Settings.GeneralSettings.BackCommandSettings back = plugin.getSettings().getGeneral().getBackCommand();
|
||||
if (!back.isReturnByDeath() || !back.canReturnToWorld(lastWorld)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the player's last position
|
||||
plugin.runAsync(() -> {
|
||||
if (plugin.getSettings().getGeneral().getBackCommand().isReturnByDeath() && plugin.getCommand(BackCommand.class)
|
||||
.map(Command::getPermission).map(onlineUser::hasPermission).orElse(false)) {
|
||||
plugin.getDatabase().setLastPosition(onlineUser, lastPosition);
|
||||
}
|
||||
plugin.getDatabase().setLastPosition(onlineUser, lastPosition);
|
||||
plugin.getLocales().getLocale("return_by_death_notification")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -234,26 +248,15 @@ public abstract class EventListener {
|
||||
* @param onlineUser the respawning {@link OnlineUser}
|
||||
*/
|
||||
protected final void handlePlayerRespawn(@NotNull OnlineUser onlineUser) {
|
||||
plugin.runAsync(() -> {
|
||||
// Display the return by death via /back notification
|
||||
final boolean canReturnByDeath = plugin.getCommand(BackCommand.class)
|
||||
.map(command -> onlineUser.hasPermission(command.getPermission())
|
||||
&& onlineUser.hasPermission(command.getPermission("death")))
|
||||
.orElse(false);
|
||||
if (plugin.getSettings().getGeneral().getBackCommand().isReturnByDeath() && canReturnByDeath) {
|
||||
plugin.getLocales().getLocale("return_by_death_notification")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
|
||||
// Respawn the player via the global respawn system
|
||||
final Settings.CrossServerSettings crossServer = plugin.getSettings().getCrossServer();
|
||||
if (crossServer.isEnabled() && crossServer.isGlobalRespawning()) {
|
||||
this.respawnGlobally(onlineUser);
|
||||
}
|
||||
});
|
||||
final Settings.CrossServerSettings crossServer = plugin.getSettings().getCrossServer();
|
||||
if (!crossServer.isEnabled() || !crossServer.isGlobalRespawning()) {
|
||||
return;
|
||||
}
|
||||
plugin.runAsync(() -> this.respawnGlobally(onlineUser));
|
||||
}
|
||||
|
||||
// Respawn a player to where they should be
|
||||
@Blocking
|
||||
private void respawnGlobally(@NotNull OnlineUser onlineUser) {
|
||||
final TeleportBuilder builder = Teleport.builder(plugin)
|
||||
.teleporter(onlineUser)
|
||||
@@ -289,12 +292,13 @@ public abstract class EventListener {
|
||||
* @param sourcePosition the source {@link Position} they came from
|
||||
*/
|
||||
protected final void handlePlayerTeleport(@NotNull OnlineUser onlineUser, @NotNull Position sourcePosition) {
|
||||
if (!plugin.getSettings().getGeneral().getBackCommand().isSaveOnTeleportEvent()) {
|
||||
final Settings.GeneralSettings.BackCommandSettings back = plugin.getSettings().getGeneral().getBackCommand();
|
||||
if (!back.isSaveOnTeleportEvent() || back.canReturnToWorld(sourcePosition.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.runAsync(() -> plugin.getDatabase().getUser(onlineUser.getUuid())
|
||||
.ifPresent(data -> plugin.getDatabase().setLastPosition(data.getUser(), sourcePosition)));
|
||||
// Set the player's last position
|
||||
plugin.runAsync(() -> plugin.getDatabase().setLastPosition(onlineUser, sourcePosition));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,8 +309,8 @@ public abstract class EventListener {
|
||||
*/
|
||||
protected final void handlePlayerUpdateSpawnPoint(@NotNull OnlineUser onlineUser, @NotNull Position position) {
|
||||
if (!plugin.getSettings().getGeneral().isAlwaysRespawnAtSpawn()
|
||||
&& plugin.getSettings().getCrossServer().isEnabled()
|
||||
&& plugin.getSettings().getCrossServer().isGlobalRespawning()) {
|
||||
&& plugin.getSettings().getCrossServer().isEnabled()
|
||||
&& plugin.getSettings().getCrossServer().isGlobalRespawning()) {
|
||||
plugin.getDatabase().setRespawnPosition(onlineUser, position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package net.william278.huskhomes.position;
|
||||
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class Teleport implements Completable {
|
||||
this.async = plugin.getSettings().getGeneral().isTeleportAsync();
|
||||
this.updateLastPosition = updateLastPosition && plugin.getCommand(BackCommand.class)
|
||||
.map(command -> executor.hasPermission(command.getPermission())
|
||||
&& executor.hasPermission(command.getPermission("previous")))
|
||||
&& executor.hasPermission(command.getPermission("previous")))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class Teleport implements Completable {
|
||||
if (localTarget.isPresent()) {
|
||||
fireEvent((event) -> {
|
||||
performTransactions();
|
||||
if (updateLastPosition) {
|
||||
if (updateLastPosition && canReturnToWorld(teleporter)) {
|
||||
plugin.getDatabase().setLastPosition(teleporter, teleporter.getPosition());
|
||||
}
|
||||
teleporter.teleportLocally(localTarget.get().getPosition(), async);
|
||||
@@ -123,13 +123,13 @@ public class Teleport implements Completable {
|
||||
|
||||
fireEvent((event) -> {
|
||||
performTransactions();
|
||||
if (updateLastPosition) {
|
||||
if (updateLastPosition && canReturnToWorld(teleporter)) {
|
||||
plugin.getDatabase().setLastPosition(teleporter, teleporter.getPosition());
|
||||
}
|
||||
|
||||
final Position target = (Position) this.target;
|
||||
if (!plugin.getSettings().getCrossServer().isEnabled()
|
||||
|| target.getServer().equals(plugin.getServerName())) {
|
||||
|| target.getServer().equals(plugin.getServerName())) {
|
||||
teleporter.teleportLocally(target, async);
|
||||
this.displayTeleportingComplete(teleporter);
|
||||
teleporter.handleInvulnerability();
|
||||
@@ -166,6 +166,10 @@ public class Teleport implements Completable {
|
||||
}));
|
||||
}
|
||||
|
||||
private boolean canReturnToWorld(@NotNull OnlineUser user) {
|
||||
return plugin.getSettings().getGeneral().getBackCommand().canReturnToWorld(user.getPosition().getWorld());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Optional<OnlineUser> resolveLocalTeleporter() throws TeleportationException {
|
||||
if (this.teleporter instanceof Username username) {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
The /back [command](commands) lets users teleport to a position they were at previously. This includes:
|
||||
|
||||
* Where the player was before they last used another HuskHomes teleportation command (on by default)
|
||||
* Where the player was before they last died (off by default, requires permission)
|
||||
* Where the player was before they last used another plugin's teleport command (off by default)
|
||||
|
||||
## Configuration
|
||||
Through the config file and permissions, you can choose which last positions to let users return to.
|
||||
|
||||
<details>
|
||||
<summary>Back Command – config.yml</summary>
|
||||
|
||||
```yaml
|
||||
# Settings for the /back command
|
||||
back_command:
|
||||
# Whether /back should work to teleport the user to where they died
|
||||
return_by_death: true
|
||||
# Whether /back should work with other plugins that use the PlayerTeleportEvent (can conflict)
|
||||
save_on_teleport_event: false
|
||||
# List of world names where the /back command cannot RETURN the player to.
|
||||
# A user's last position won't be updated if they die or teleport from these worlds, but they still will be able to use the command while IN the world
|
||||
restricted_worlds: []
|
||||
```
|
||||
</details>
|
||||
|
||||
## Restricting /back
|
||||
There are several options for restricting the use of `/back`.
|
||||
|
||||
### Letting users return to a previous position
|
||||
Being able to return to where a user last performed a HuskHomes teleportation command from is the default functionality of `/back`.
|
||||
|
||||
To disable this, give the player the `huskhomes.command.back.previous` permission node, set to the value `false`.
|
||||
|
||||
### Letting users "return by death"
|
||||
To enable "return by death" – where a user can return to where they most recently died with /back – first enable `return_by_death` under `config.yml`
|
||||
|
||||
<details>
|
||||
<summary>Return By Death – config.yml</summary>
|
||||
|
||||
```yaml
|
||||
back_command:
|
||||
# Whether /back should work to teleport the user to where they died
|
||||
return_by_death: true
|
||||
```
|
||||
</details>
|
||||
|
||||
Then, grant the player the `huskhomes.command.back.death` permission node.
|
||||
|
||||
### Disabling using /back to return to certain worlds
|
||||
Add world names to the `restricted_worlds` list under `back_command` in the config file and the plugin will no longer save last positions within the listed worlds.
|
||||
|
||||
This will stop the plugin from letting users _return_ to certain specific worlds. It will _not_, however, prevent users from using the `/back` command _in_ these worlds. To stop users from using `/back` in specific worlds, use [LuckPerms Contextual Permissions](https://luckperms.net/wiki/Context).
|
||||
|
||||
<details>
|
||||
<summary>Restricted Worlds – config.yml</summary>
|
||||
|
||||
```yaml
|
||||
back_command:
|
||||
# List of world names where the /back command cannot RETURN the player to.
|
||||
# A user's last position won't be updated if they die or teleport from these worlds, but they still will be able to use the command while IN the world
|
||||
restricted_worlds: []
|
||||
```
|
||||
</details>
|
||||
|
||||
### Returning from other plugins' teleports
|
||||
> **Warning:** This may cause conflicts with the behaviour of some plugins, please take caution when enabling this if you have lots of plugins installed!
|
||||
|
||||
To use `/back` to return to where other plugins' teleported a user from, enable `save_on_teleport_event`.
|
||||
|
||||
<details>
|
||||
<summary>Teleport Event – config.yml</summary>
|
||||
|
||||
```yaml
|
||||
back_command:
|
||||
# Whether /back should work with other plugins that use the PlayerTeleportEvent (can conflict)
|
||||
save_on_teleport_event: false
|
||||
```
|
||||
</details>
|
||||
@@ -105,6 +105,9 @@ general:
|
||||
return_by_death: true
|
||||
# Whether /back should work with other plugins that use the PlayerTeleportEvent (can conflict)
|
||||
save_on_teleport_event: false
|
||||
# List of world names where the /back command cannot RETURN the player to.
|
||||
# A user's last position won't be updated if they die or teleport from these worlds, but they still will be able to use the command while IN the world
|
||||
restricted_worlds: []
|
||||
# Settings for sound effects
|
||||
sound_effects:
|
||||
# Whether to play sound effects
|
||||
|
||||
@@ -15,6 +15,7 @@ Welcome to the plugin documentation for HuskHomes v4.x+, the powerful & intuitiv
|
||||
* 🗺️ [[Map Hooks]]
|
||||
* 💵 [[Economy Hook]]
|
||||
* ⚠️ [[Strict Tpahere]]
|
||||
* 🔙 [[Back Command]]
|
||||
* 🚫 [[Restricted Warps]]
|
||||
* ⏰ [[Cooldowns]]
|
||||
* 🌎 [[Global Spawn]]
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
* 🗺️ [[Map Hooks]]
|
||||
* 💵 [[Economy Hook]]
|
||||
* ⚠️ [[Strict Tpahere]]
|
||||
* 🔙 [[Back Command]]
|
||||
* 🚫 [[Restricted Warps]]
|
||||
* ⏰ [[Cooldowns]]
|
||||
* 🌎 [[Global Spawn]]
|
||||
|
||||
@@ -29,7 +29,6 @@ import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.william278.huskhomes.FabricHuskHomes;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
Reference in new issue
Block a user