mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Add /tpignore
This commit is contained in:
1 parent
52a30c98ca
commit
a1667a4daf
6 files changed
+61
-10
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user