Add /tpignore

This commit is contained in:
William committed 2022-08-20 18:17:44 +01:00
1 parent 52a30c98ca
commit a1667a4daf
6 files changed
+61 -10

No files matched your search

@@ -27,6 +27,7 @@ public enum BukkitCommandType {
TPACCEPT_COMMAND(new TpRespondCommand(BukkitHuskHomes.getInstance(), true)),
TPDECLINE_COMMAND(new TpRespondCommand(BukkitHuskHomes.getInstance(), false)),
RTP_COMMAND(new RtpCommand(BukkitHuskHomes.getInstance())),
TP_IGNORE_COMMAND(new TpIgnoreCommand(BukkitHuskHomes.getInstance())),
BACK_COMMAND(new BackCommand(BukkitHuskHomes.getInstance()));
public final CommandBase commandBase;
+2
View File
@@ -57,5 +57,7 @@ commands:
aliases: [tpdeny, tpno]
rtp:
usage: /rtp [player]
tpignore:
usage: /tpignore <player>
back:
usage: /back
@@ -0,0 +1,30 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
public class TpIgnoreCommand extends CommandBase {
protected TpIgnoreCommand(@NotNull HuskHomes implementor) {
super("tpignore", Permission.COMMAND_TPIGNORE, implementor);
}
@Override
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
if (args.length != 0) {
plugin.getLocales().getLocale("error_invalid_syntax", "/tpignore")
.ifPresent(onlineUser::sendMessage);
return;
}
final boolean isIgnoringRequests = !plugin.getRequestManager().isIgnoringRequests(onlineUser);
plugin.getRequestManager().setIgnoringRequests(onlineUser, isIgnoringRequests);
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData ->
userData.ifPresent(data -> plugin.getDatabase().updateUserData(new UserData(onlineUser,
data.homeSlots(), isIgnoringRequests, data.rtpCooldown())).join()))
.thenRun(() -> plugin.getLocales().getLocale("tpignore_toggle_" + (isIgnoringRequests ? "on" : "off"))
.ifPresent(onlineUser::sendMessage));
}
}
@@ -58,16 +58,32 @@ public class EventListener {
plugin.getLocales().getLocale("teleporting_complete")
.ifPresent(onlineUser::sendMessage);
}
}).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null))));
}).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null))))
.join();
// Update the player list
assert plugin.getNetworkMessenger() != null;
plugin.getCache().updateOnlinePlayerList(plugin, onlineUser);
}
// Get this user's tp-ignore state and set locally
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> {
if (userData.isPresent()) {
final boolean ignoringRequests = userData.get().ignoringTeleports();
plugin.getRequestManager().setIgnoringRequests(onlineUser, ignoringRequests);
// Send a reminder message if they are still ignoring requests
if (ignoringRequests) {
plugin.getLocales().getLocale("tpignore_on_reminder")
.ifPresent(onlineUser::sendMessage);
}
}
}).join();
// Cache this user's homes
plugin.getDatabase().getHomes(onlineUser).thenAccept(homes ->
plugin.getCache().homes.put(onlineUser.uuid,
homes.stream().map(home -> home.meta.name).collect(Collectors.toList())));
plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> plugin.getCache()
.homes.put(onlineUser.uuid, homes
.stream().map(home -> home.meta.name)
.collect(Collectors.toList()))).join();
// Ensure the server has been set
if (plugin.getOnlinePlayers().size() == 1) {
@@ -36,12 +36,12 @@ public class RequestManager {
this.ignoringRequests = new HashSet<>();
}
public void setIgnoringRequests(@NotNull User user) {
this.ignoringRequests.add(user.uuid);
}
public void removeIgnoringRequests(@NotNull User user) {
this.ignoringRequests.remove(user.uuid);
public void setIgnoringRequests(@NotNull User user, boolean ignoring) {
if (ignoring) {
this.ignoringRequests.add(user.uuid);
} else {
this.ignoringRequests.remove(user.uuid);
}
}
public boolean isIgnoringRequests(@NotNull User user) {
@@ -94,9 +94,11 @@ delete_all_homes_success: '[Successfully deleted your](#00fb9a) [%1%](#00fb9a bo
delete_all_warps_success: '[Successfully deleted all](#00fb9a) [%1%](#00fb9a bold) [server warp(s).](#00fb9a)'
teleporting_complete_console: '[Console teleported you to %1%.](gray)'
spawn_warp_default_description: 'The /spawn position of the server'
tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)'
tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to any incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to ignore incoming teleport requests run_command=/huskhomes:tpignore)'
tpignore_on_reminder: '[You are currently ignoring incoming teleport requests!](gray) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)'
teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)'
economy_action_additional_home_slot: '[ℹ Spent %1% to set an additional home.](gray)'