mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Exclude rtp restricted worlds from command TAB completion
This commit is contained in:
2 files changed
+32
-11
No files matched your search
@@ -76,13 +76,21 @@ public class RtpCommand extends Command implements UserListTabProvider {
|
|||||||
return switch (args.length) {
|
return switch (args.length) {
|
||||||
case 0, 1 -> user.hasPermission("other") ? UserListTabProvider.super.suggestLocal(args)
|
case 0, 1 -> user.hasPermission("other") ? UserListTabProvider.super.suggestLocal(args)
|
||||||
: user instanceof OnlineUser online ? List.of(online.getUsername()) : List.of();
|
: user instanceof OnlineUser online ? List.of(online.getUsername()) : List.of();
|
||||||
case 2 -> user.hasPermission("world") ? plugin.getWorlds().stream().map(World::getName).toList()
|
case 2 -> user.hasPermission("world") ? plugin.getWorlds().stream()
|
||||||
: List.of();
|
.filter(w -> !plugin.getSettings().isWorldRtpRestricted(w))
|
||||||
|
.map(World::getName).toList() : List.of();
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
// Check permissions if the user is being teleported by another player
|
||||||
if (!executor.equals(teleporter) && !executor.hasPermission(getPermission("other"))) {
|
if (!executor.equals(teleporter) && !executor.hasPermission(getPermission("other"))) {
|
||||||
@@ -113,8 +121,7 @@ public class RtpCommand extends Command implements UserListTabProvider {
|
|||||||
.ifPresent(executor::sendMessage);
|
.ifPresent(executor::sendMessage);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
if (plugin.getSettings().getRtpRestrictedWorlds().stream()
|
if (plugin.getSettings().isWorldRtpRestricted(world)) {
|
||||||
.anyMatch(worldName -> worldName.equals(world.getName()))) {
|
|
||||||
plugin.getLocales().getLocale("error_rtp_restricted_world")
|
plugin.getLocales().getLocale("error_rtp_restricted_world")
|
||||||
.ifPresent(executor::sendMessage);
|
.ifPresent(executor::sendMessage);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@@ -125,7 +132,7 @@ public class RtpCommand extends Command implements UserListTabProvider {
|
|||||||
.orElseThrow(() -> new IllegalStateException("No user data found for " + teleporter.getUsername()));
|
.orElseThrow(() -> new IllegalStateException("No user data found for " + teleporter.getUsername()));
|
||||||
final Instant currentTime = Instant.now();
|
final Instant currentTime = Instant.now();
|
||||||
if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) &&
|
if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) &&
|
||||||
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
||||||
plugin.getLocales().getLocale("error_rtp_cooldown", Long.toString(
|
plugin.getLocales().getLocale("error_rtp_cooldown", Long.toString(
|
||||||
currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1)
|
currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1)
|
||||||
).ifPresent(executor::sendMessage);
|
).ifPresent(executor::sendMessage);
|
||||||
@@ -135,7 +142,14 @@ public class RtpCommand extends Command implements UserListTabProvider {
|
|||||||
return Optional.of(world);
|
return Optional.of(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Executes the random teleport
|
/**
|
||||||
|
* Executes the random teleport
|
||||||
|
*
|
||||||
|
* @param teleporter The player to teleport
|
||||||
|
* @param executor The player executing the command
|
||||||
|
* @param world The world to teleport in
|
||||||
|
* @param args Arguments to pass to the RTP engine
|
||||||
|
*/
|
||||||
private void executeRtp(@NotNull OnlineUser teleporter, @NotNull CommandUser executor, @NotNull World world,
|
private void executeRtp(@NotNull OnlineUser teleporter, @NotNull CommandUser executor, @NotNull World world,
|
||||||
@NotNull String[] args) {
|
@NotNull String[] args) {
|
||||||
// Generate a random position
|
// Generate a random position
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import net.william278.huskhomes.command.Command;
|
|||||||
import net.william278.huskhomes.database.Database;
|
import net.william278.huskhomes.database.Database;
|
||||||
import net.william278.huskhomes.hook.EconomyHook;
|
import net.william278.huskhomes.hook.EconomyHook;
|
||||||
import net.william278.huskhomes.network.Broker;
|
import net.william278.huskhomes.network.Broker;
|
||||||
|
import net.william278.huskhomes.position.World;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -364,7 +365,9 @@ public class Settings {
|
|||||||
return strictTpaHereRequests;
|
return strictTpaHereRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean caseInsensitiveNames() { return caseInsensitiveNames; }
|
public boolean caseInsensitiveNames() {
|
||||||
|
return caseInsensitiveNames;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean doAllowUnicodeNames() {
|
public boolean doAllowUnicodeNames() {
|
||||||
return allowUnicodeNames;
|
return allowUnicodeNames;
|
||||||
@@ -461,8 +464,12 @@ public class Settings {
|
|||||||
return rtpDistributionStandardDeviation;
|
return rtpDistributionStandardDeviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getRtpRestrictedWorlds() {
|
public boolean isWorldRtpRestricted(@NotNull World world) {
|
||||||
return rtpRestrictedWorlds;
|
final String worldName = world.getName();
|
||||||
|
final String filteredName = worldName.startsWith("minecraft:") ? worldName.substring(10) : worldName;
|
||||||
|
return rtpRestrictedWorlds.stream()
|
||||||
|
.map(name -> name.startsWith("minecraft:") ? name.substring(10) : name)
|
||||||
|
.anyMatch(name -> name.equalsIgnoreCase(filteredName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doEconomy() {
|
public boolean doEconomy() {
|
||||||
@@ -504,7 +511,7 @@ public class Settings {
|
|||||||
return disabledCommands.stream().anyMatch(disabled -> {
|
return disabledCommands.stream().anyMatch(disabled -> {
|
||||||
final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled);
|
final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled);
|
||||||
return command.equalsIgnoreCase(type.getName())
|
return command.equalsIgnoreCase(type.getName())
|
||||||
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
|
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user