make getPlayer a function because mongo doesnt call constructors

This commit is contained in:
Taah 2022-08-02 15:23:54 -07:00
parent 829bb88959
commit 16e29b80a7
2 changed files with 11 additions and 5 deletions

View File

@ -24,11 +24,15 @@ public class CommandListener extends PlexListener
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
Bukkit.getOnlinePlayers().stream().filter(pl -> plugin.getPlayerCache().getPlexPlayer(pl.getUniqueId()).isCommandSpy() && hasCommandSpy(plugin.getPlayerCache().getPlexPlayer(pl.getUniqueId()))).forEach(pl ->
Bukkit.getOnlinePlayers().stream().filter(pl -> {
PlexPlayer player = plugin.getPlayerCache().getPlexPlayer(pl.getUniqueId());
return player.isCommandSpy() && hasCommandSpy(plugin.getPlayerCache().getPlexPlayer(pl.getUniqueId()));
}).forEach(pl ->
{
System.out.println("Sending to " + pl.getUniqueId());
Player player = event.getPlayer();
String command = event.getMessage();
if (pl != player)
if (!pl.getUniqueId().equals(player.getUniqueId()))
{
pl.sendMessage(ChatColor.GRAY + player.getName() + ": " + command);
}

View File

@ -41,7 +41,6 @@ public class PlexPlayer
@Indexed
private String name;
private transient Player player;
private String loginMessage;
private String prefix;
@ -78,7 +77,6 @@ public class PlexPlayer
this.id = uuid.toString().substring(0, 8);
this.name = "";
this.player = Bukkit.getPlayer(name);
this.loginMessage = "";
this.prefix = "";
@ -106,7 +104,7 @@ public class PlexPlayer
public String displayName()
{
return PlainTextComponentSerializer.plainText().serialize(player.displayName());
return PlainTextComponentSerializer.plainText().serialize(getPlayer().displayName());
}
public Rank getRankFromString()
@ -150,4 +148,8 @@ public class PlexPlayer
{
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
}
public Player getPlayer() {
return Bukkit.getPlayer(this.uuid);
}
}