Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java

165 lines
4.5 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.managers;
import java.util.Iterator;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
2015-02-24 01:03:51 +01:00
import mineplex.core.party.Party;
2013-08-27 17:14:08 +02:00
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState;
2015-08-05 07:57:52 +02:00
import nautilus.game.arcade.game.GameTeam;
2013-08-27 17:14:08 +02:00
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class GameChatManager implements Listener
{
ArcadeManager Manager;
2013-10-09 12:50:39 +02:00
2013-08-27 17:14:08 +02:00
public GameChatManager(ArcadeManager manager)
{
Manager = manager;
2013-10-09 12:50:39 +02:00
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
}
2013-10-09 12:50:39 +02:00
2013-08-27 17:14:08 +02:00
@EventHandler
public void MeCancel(PlayerCommandPreprocessEvent event)
{
2014-12-16 18:42:06 +01:00
if (event.getMessage().startsWith("/me "))
2013-08-27 17:14:08 +02:00
{
event.getPlayer().sendMessage(F.main("Mirror", "You can't see /me messages, are you a vampire?"));
event.setCancelled(true);
}
}
@EventHandler
public void HandleChat(AsyncPlayerChatEvent event)
2013-08-27 17:14:08 +02:00
{
if (event.isCancelled())
return;
2013-10-09 12:50:39 +02:00
2013-08-27 17:14:08 +02:00
Player sender = event.getPlayer();
2015-04-01 07:56:13 +02:00
String senderName = sender.getName();
2014-01-21 01:56:35 +01:00
//Dead Prefix
2013-08-27 17:14:08 +02:00
String dead = "";
if (Manager.GetGame() != null)
if (Manager.GetGame().GetTeam(sender) != null)
if (!Manager.GetGame().IsAlive(sender))
dead = C.cGray + "Dead ";
Rank rank = Manager.GetClients().Get(sender).GetRank();
boolean ownsUltra = false;
if (Manager.GetGame() != null)
ownsUltra= Manager.GetDonation().Get(sender.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA");
2014-11-07 23:15:27 +01:00
//Level
2014-12-22 03:19:45 +01:00
String levelStr = "";
if (!Manager.GetGameHostManager().isPrivateServer())
levelStr = Manager.GetAchievement().getMineplexLevel(sender, rank);
2014-11-07 23:15:27 +01:00
2013-08-27 17:14:08 +02:00
String rankStr = "";
2014-12-22 03:19:45 +01:00
//Rank Prefix & MPS Host Prefix
if (Manager.GetGameHostManager().isHost(event.getPlayer()))
{
2015-03-12 02:14:49 +01:00
if (Manager.GetGameHostManager().isEventServer())
2015-03-09 12:15:24 +01:00
rankStr = C.cDGreen + C.Bold + "Event Host ";
else
rankStr = C.cDGreen + C.Bold + "MPS Host ";
2014-12-22 03:19:45 +01:00
}
2014-12-22 06:31:13 +01:00
else if (Manager.GetGameHostManager().isAdmin(event.getPlayer(), false))
2014-12-22 03:19:45 +01:00
{
if (Manager.GetGameHostManager().isEventServer())
2015-03-09 12:15:24 +01:00
rankStr = C.cDGreen + C.Bold + "Event Admin ";
else
rankStr = C.cDGreen + C.Bold + "MPS Admin ";
2014-12-22 03:19:45 +01:00
}
else
{
if (rank != Rank.ALL)
rankStr = rank.GetTag(true, true) + " ";
2013-08-27 17:14:08 +02:00
2014-12-22 03:19:45 +01:00
if (ownsUltra && !rank.Has(Rank.ULTRA))
rankStr = Rank.ULTRA.GetTag(true, true) + " ";
}
2015-02-24 01:03:51 +01:00
if (event.getMessage().charAt(0) == '@')
{
//Party Chat
Party party = Manager.getPartyManager().GetParty(sender);
if (party != null)
{
event.getRecipients().clear();
event.setMessage(event.getMessage().substring(1, event.getMessage().length()));
2015-04-01 07:56:13 +02:00
event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + senderName + " " + C.cPurple + "%2$s");
2015-02-24 01:03:51 +01:00
event.getRecipients().addAll(party.GetPlayersOnline());
return;
}
}
2013-08-27 17:14:08 +02:00
//Base Format
2015-04-01 07:56:13 +02:00
event.setFormat(dead + levelStr + rankStr + Manager.GetColor(sender) + senderName + " " + ChatColor.WHITE + "%2$s");
2013-08-27 17:14:08 +02:00
//Public/Private (Not If Player Dead)
if (Manager.GetGame() != null && Manager.GetGame().GetState() == GameState.Live)
{
boolean globalMessage = false;
//Team
GameTeam team = Manager.GetGame().GetTeam(sender);
if (team != null)
{
//Team Chat
if (event.getMessage().charAt(0) == '@')
{
event.setMessage(event.getMessage().substring(1, event.getMessage().length()));
2015-04-01 07:56:13 +02:00
event.setFormat(C.cWhite + C.Bold + "Team" + " " + dead + levelStr + rankStr + team.GetColor() + senderName + " " + C.cWhite + "%2$s");
2013-08-27 17:14:08 +02:00
}
//All Chat
else
{
globalMessage = true;
2015-04-01 07:56:13 +02:00
event.setFormat(dead + levelStr + rankStr + team.GetColor() + senderName + " " + C.cWhite + "%2$s");
2013-08-27 17:14:08 +02:00
}
}
if (globalMessage)
return;
//Team Message Remove Recipient
Iterator<Player> recipientIterator = event.getRecipients().iterator();
while (recipientIterator.hasNext())
{
Player receiver = recipientIterator.next();
if (!Manager.GetServerConfig().Tournament && Manager.GetClients().Get(receiver).GetRank().Has(Rank.MODERATOR))
2013-08-27 17:14:08 +02:00
continue;
GameTeam recTeam = Manager.GetGame().GetTeam(receiver);
GameTeam sendTeam = Manager.GetGame().GetTeam(sender);
if (recTeam == null || sendTeam == null)
{
continue;
}
2013-08-27 17:14:08 +02:00
if (!recTeam.equals(sendTeam))
2013-08-27 17:14:08 +02:00
recipientIterator.remove();
}
}
}
}