dirty fix for /spy not working

This commit is contained in:
destro174 2021-08-22 10:47:39 +02:00
parent 1d5dd7c764
commit 3fd7bbfece
5 changed files with 28 additions and 13 deletions

View File

@ -22,7 +22,7 @@ public class ChatUser {
//private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat //private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback? private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in
private boolean spy;
private List<Mail> mails; // mails aren't finalized yet, so for now a table sender, reciever, sendtime, readtime(if emtpy mail isn't read yet?, could also do a byte to control this), the actual message private List<Mail> mails; // mails aren't finalized yet, so for now a table sender, reciever, sendtime, readtime(if emtpy mail isn't read yet?, could also do a byte to control this), the actual message
private List<UUID> ignoredPlayers; // a list of UUID, a new table non unique, where one is is the player select * from ignores where ignoredby = thisplayer? where the result is the uuid of the player ignored by this player? private List<UUID> ignoredPlayers; // a list of UUID, a new table non unique, where one is is the player select * from ignores where ignoredby = thisplayer? where the result is the uuid of the player ignored by this player?
private List<UUID> ignoredBy; // a list of UUID, same table as above but select * from ignores where ignored = thisplayer? result should be the other user that ignored this player? private List<UUID> ignoredBy; // a list of UUID, same table as above but select * from ignores where ignored = thisplayer? result should be the other user that ignored this player?
@ -48,6 +48,7 @@ public class ChatUser {
mails = Queries.getMails(uuid); mails = Queries.getMails(uuid);
ignoredPlayers = Queries.getIgnoredUsers(uuid); ignoredPlayers = Queries.getIgnoredUsers(uuid);
ignoredBy = new ArrayList<>(); // todo load ignoredPlayers ignoredBy = new ArrayList<>(); // todo load ignoredPlayers
spy = true;
} }
public UUID getUuid() { public UUID getUuid() {
@ -137,4 +138,12 @@ public class ChatUser {
public void setGcCooldown(long time) { public void setGcCooldown(long time) {
this.gcCooldown = time; this.gcCooldown = time;
} }
public boolean isSpy() {
return spy;
}
public void toggleSpy() {
this.spy = !spy;
}
} }

View File

@ -25,9 +25,9 @@ public class Spy implements CommandExecutor {
@Override @Override
public void run() { public void run() {
UUID uuid = ((Player) sender).getUniqueId(); UUID uuid = ((Player) sender).getUniqueId();
Utility.flipPermission(uuid, Config.SPYPERMISSION); ChatUser user = ChatUserManager.getChatUser(uuid);
//Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid()); user.toggleSpy();
sender.sendMessage(MiniMessage.get().parse("You have turned spy " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage sender.sendMessage(MiniMessage.get().parse("You have turned spy " + (user.isSpy() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
} }
}.runTaskAsynchronously(ChatPlugin.getInstance()); }.runTaskAsynchronously(ChatPlugin.getInstance());
return false; return false;

View File

@ -72,7 +72,7 @@ public class ChatHandler {
sendPrivateMessage(player, target, "privatemessage", component); sendPrivateMessage(player, target, "privatemessage", component);
Component spymessage = miniMessage.parse(Config.MESSAGESPY, templates); Component spymessage = miniMessage.parse(Config.MESSAGESPY, templates);
for(Player pl : Bukkit.getOnlinePlayers()) { for(Player pl : Bukkit.getOnlinePlayers()) {
if(pl.hasPermission(Config.SPYPERMISSION) && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) { // todo add a toggle for social spy if(pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) { // todo add a toggle for social spy
pl.sendMessage(spymessage); pl.sendMessage(spymessage);
} }
} }

View File

@ -39,10 +39,13 @@ public class PluginMessage implements PluginMessageListener {
String target = in.readUTF(); String target = in.readUTF();
Player p = Bukkit.getPlayer(uuid); Player p = Bukkit.getPlayer(uuid);
if (p != null) { if (p != null) {
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF())); ChatUser chatUser = ChatUserManager.getChatUser(uuid);
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config if (!chatUser.getIgnoredPlayers().contains(uuid)) {
ChatUser user = ChatUserManager.getChatUser(uuid); p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
user.setReplyTarget(target); p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config
ChatUser user = ChatUserManager.getChatUser(uuid);
user.setReplyTarget(target);
}
} }
break; break;
} }
@ -51,9 +54,12 @@ public class PluginMessage implements PluginMessageListener {
String target = in.readUTF(); String target = in.readUTF();
Player p = Bukkit.getPlayer(uuid); Player p = Bukkit.getPlayer(uuid);
if (p != null) { if (p != null) {
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF())); ChatUser chatUser = ChatUserManager.getChatUser(uuid);
ChatUser user = ChatUserManager.getChatUser(uuid); if (!chatUser.getIgnoredPlayers().contains(uuid)) {
user.setReplyTarget(target); p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
ChatUser user = ChatUserManager.getChatUser(uuid);
user.setReplyTarget(target);
}
} }
break; break;
} }

View File

@ -15,7 +15,7 @@ commands:
aliases: togglegc aliases: togglegc
message: message:
permission: command.message permission: command.message
aliases: msg aliases: [msg, tell]
reply: reply:
permission: command.message permission: command.message
aliases: r aliases: r