Mostly fixed chat formatting #60

Merged
NorbiPeti merged 11 commits from dev into master 2016-12-30 21:54:03 +00:00
10 changed files with 79 additions and 84 deletions
Showing only changes of commit 81b188f338 - Show all commits

Binary file not shown.

View file

@ -159,12 +159,6 @@
<version>1.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
</dependencies>
<artifactId>ButtonChat</artifactId>
<organization>

View file

@ -1,6 +1,6 @@
package buttondevteam.chat;
import org.bukkit.entity.Player;
import org.bukkit.Bukkit;
public class AnnouncerThread {
private static int AnnounceMessageIndex = 0;
@ -13,9 +13,7 @@ public class AnnouncerThread {
Thread.currentThread().interrupt();
}
if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) {
for (Player player : PluginMain.GetPlayers())
player.sendMessage(PluginMain.AnnounceMessages
.get(AnnounceMessageIndex));
Bukkit.broadcastMessage(PluginMain.AnnounceMessages.get(AnnounceMessageIndex));
AnnounceMessageIndex++;
if (AnnounceMessageIndex == PluginMain.AnnounceMessages.size())
AnnounceMessageIndex = 0;

View file

@ -38,7 +38,10 @@ public class ChatPlayer extends TBMCPlayer {
}
public FlairStates getFlairState() {
return getEnumData(FlairStates.class);
FlairStates data = getEnumData(FlairStates.class);
if (data == null)
setFlairState(data = FlairStates.NoComment);
return data;
}
public void setFlairState(FlairStates state) {
@ -70,7 +73,6 @@ public class ChatPlayer extends TBMCPlayer {
}
public boolean RPMode = true;
public boolean PressedF;
public Location SavedLocation;
public boolean Working;
// public int Tables = 10;

View file

@ -75,7 +75,7 @@ public class ChatProcessing {
.setOpenlink("https://twitter.com/hashtag/$1").setPriority(Priority.High).build());
}
// Returns e.setCancelled
// Returns e.setCancelled for custom event
public static boolean ProcessChat(Channel channel, CommandSender sender, String message) {
long processstart = System.nanoTime();
if (PluginMain.essentials == null)
@ -85,18 +85,12 @@ public class ChatProcessing {
if (player != null && PluginMain.essentials.getUser(player).isMuted())
return true;
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
PlayerListener.Fs.add(sender);
ChatPlayer mp = null;
if (player != null) {
if (player != null)
mp = TBMCPlayer.getPlayer(player).asPluginPlayer(ChatPlayer.class);
if (message.equalsIgnoreCase("F")) {
if (!mp.PressedF && PlayerListener.ActiveF) {
PlayerListener.FCount++;
mp.PressedF = true;
if (PlayerListener.FPlayer != null && PlayerListener.FPlayer.getFCount() < Integer.MAX_VALUE - 1)
PlayerListener.FPlayer.setFCount(PlayerListener.FPlayer.getFCount() + 1);
}
}
}
String msg = message.toLowerCase();
if (msg.contains("lol")) {
@ -132,22 +126,30 @@ public class ChatProcessing {
String suggestmsg = formattedmessage;
if (PluginMain.GetPlayers().size() > 0) {
if (Bukkit.getOnlinePlayers().size() > 0) {
StringBuilder namesb = new StringBuilder();
namesb.append("(?i)(");
for (Player p : PluginMain.GetPlayers())
for (Player p : Bukkit.getOnlinePlayers())
namesb.append(p.getName()).append("|");
namesb.deleteCharAt(namesb.length() - 1);
namesb.append(")");
StringBuilder nicksb = new StringBuilder();
nicksb.append("(?i)(");
for (Player p : PluginMain.GetPlayers()) {
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
if (nick != null) // Not everyone has a nickname
nicksb.append(nick).append("|");
{
final int size = Bukkit.getOnlinePlayers().size();
int index = 0;
for (Player p : Bukkit.getOnlinePlayers()) {
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
if (nick != null) {
nicksb.append(nick);
if (index < size - 1) {
nicksb.append("|");
}
}
index++;
}
nicksb.append(")");
}
nicksb.deleteCharAt(nicksb.length() - 1);
nicksb.append(")");
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())).setColor(Color.Aqua)
.setOnmatch((String match) -> {
@ -196,9 +198,10 @@ public class ChatProcessing {
json.addExtra(new TellrawPart("[C]").setHoverEvent(
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
}
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + currentchannel.DisplayName)
+ "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
json.addExtra(
new TellrawPart(("[" + (sender instanceof IDiscordSender ? "d|" : "") + currentchannel.DisplayName)
+ "]" + (mp != null && !mp.RPMode ? "[OOC]" : "")).setHoverEvent(
new TellrawPart(channelidentifier).setHoverEvent(
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
+ "Copy message").setColor(Color.Blue)))
@ -260,7 +263,7 @@ public class ChatProcessing {
sender.sendMessage("§cYou are not a player!");
return true;
}
for (Player p : PluginMain.GetPlayers()) {
for (Player p : Bukkit.getOnlinePlayers()) {
try {
Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase());
if (resident != null && !resident.getName().equals(player.getName())
@ -291,7 +294,7 @@ public class ChatProcessing {
index = PluginMain.Instance.Towns.size() - 1;
}
Objective obj = PluginMain.SB.getObjective("town");
for (Player p : PluginMain.GetPlayers()) {
for (Player p : Bukkit.getOnlinePlayers()) {
try {
if (town.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
obj.getScore(p.getName()).setScore(index);
@ -331,7 +334,7 @@ public class ChatProcessing {
index = PluginMain.Instance.Nations.size() - 1;
}
Objective obj = PluginMain.SB.getObjective("nation");
for (Player p : PluginMain.GetPlayers()) {
for (Player p : Bukkit.getOnlinePlayers()) {
try {
if (nation.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
obj.getScore(p.getName()).setScore(index);
@ -348,7 +351,7 @@ public class ChatProcessing {
return true;
}
Objective obj = PluginMain.SB.getObjective("admin");
for (Player p : PluginMain.GetPlayers()) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.isOp())
obj.getScore(p.getName()).setScore(1);
else
@ -362,7 +365,7 @@ public class ChatProcessing {
return true;
}
Objective obj = PluginMain.SB.getObjective("mod");
for (Player p : PluginMain.GetPlayers()) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (PluginMain.permission.playerInGroup(p, "mod"))
obj.getScore(p.getName()).setScore(1);
else
@ -379,12 +382,11 @@ public class ChatProcessing {
return true;
}
PluginMain.Instance.getServer().getConsoleSender()
.sendMessage(String.format("[%s] <%s%s> %s", currentchannel.DisplayName,
(player != null ? player.getDisplayName() : sender.getName()),
(mp != null ? mp.GetFormattedFlair() : ""), message));
.sendMessage(String.format("%s <%s> %s", channelidentifier,
(player != null ? player.getDisplayName() : sender.getName()), message));
DebugCommand.SendDebugMessage(
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
return true;
return false;
}
}

View file

@ -37,7 +37,6 @@ import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@ -253,10 +252,6 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r");
}
public static Collection<? extends Player> GetPlayers() {
return Instance.getServer().getOnlinePlayers();
}
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
public static int AnnounceTime = 15 * 60 * 1000;

View file

@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.TBMCCommandBase;
public final class UnlolCommand extends TBMCCommandBase {
@ -31,9 +30,7 @@ public final class UnlolCommand extends TBMCCommandBase {
String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName())
+ (Lastlolornot ? " unlolled " : " unlaughed ")
+ (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName());
for (Player pl : PluginMain.GetPlayers())
pl.sendMessage(msg);
Bukkit.getServer().getConsoleSender().sendMessage(msg);
Bukkit.broadcastMessage(msg);
Lastlol = null;
}
return true;

View file

@ -4,7 +4,6 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCYEEHAWEvent;
import buttondevteam.lib.chat.TBMCCommandBase;
@ -19,12 +18,11 @@ public class YeehawCommand extends TBMCCommandBase {
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
final String message = "§b* "
+ (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs.";
for (Player p : PluginMain.GetPlayers()) {
for (Player p : Bukkit.getOnlinePlayers()) {
p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f);
p.sendMessage(message);
} // Even a cmdblock could yeehaw in theory
// Or anyone from Discord
Bukkit.getConsoleSender().sendMessage(message);
Bukkit.broadcastMessage(message);
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
return true;
}

View file

@ -35,10 +35,15 @@ public final class HelpCommand extends UCommandBase {
ArrayList<String> text = new ArrayList<String>();
text.add("§6---- Command list ----");
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values())
if (!cmd.GetCommandPath().contains(" "))
if (!cmd.GetModOnly() || PluginMain.permission.has(sender, "tbmc.admin"))
if (!cmd.GetPlayerOnly() || sender instanceof Player)
if (!cmd.GetModOnly() || PluginMain.permission.has(sender, "tbmc.admin"))
if (!cmd.GetPlayerOnly() || sender instanceof Player)
if (!cmd.GetCommandPath().contains(" "))
text.add("/" + cmd.GetCommandPath());
else {
final String topcmd = cmd.GetCommandPath().substring(0, cmd.GetCommandPath().indexOf(' '));
if (!text.contains("/" + topcmd))
text.add("/" + topcmd);
}
sender.sendMessage(text.toArray(new String[text.size()]));
} else if (args[0].equalsIgnoreCase("colors")) {
sender.sendMessage(new String[] { "§6---- Chat colors/formats ----", //
@ -65,8 +70,9 @@ public final class HelpCommand extends UCommandBase {
if (subcmds.length > 0)
sender.sendMessage(subcmds);
else
sender.sendMessage(new String[] { "§cError: Command not found or you don't have permission for it: " + path,
"Usage example: /u accept --> /u help u accept" });
sender.sendMessage(
new String[] { "§cError: Command not found or you don't have permission for it: " + path,
"Usage example: /u accept --> /u help u accept" });
} else
sender.sendMessage(cmd.GetHelpText(args[0]));
}

View file

@ -1,5 +1,6 @@
package buttondevteam.chat.listener;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Timer;
@ -10,6 +11,7 @@ import com.palmergames.bukkit.towny.Towny;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -28,6 +30,7 @@ import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.TBMCPlayer.InfoTarget;
import buttondevteam.lib.chat.Channel;
@ -62,14 +65,14 @@ public class PlayerListener implements Listener {
public final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", "kek", "lmao", "hue", "hah" };
@EventHandler
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled())
return;
TBMCChatAPI.SendChatMessage(
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
event.getPlayer(), event.getMessage());
event.setCancelled(true);
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -110,8 +113,7 @@ public class PlayerListener implements Listener {
if (!PluginMain.essentials.getUser(event.getPlayer()).isMuted()) {
event.setCancelled(true);
String message = event.getMessage().substring(index + 1);
for (Player p : PluginMain.GetPlayers())
p.sendMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
Bukkit.broadcastMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
}
}
}
@ -166,10 +168,7 @@ public class PlayerListener implements Listener {
}
if (target != null) {
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
for (Player pl : PluginMain.GetPlayers())
pl.sendMessage(
event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
Bukkit.getServer().getConsoleSender().sendMessage(
Bukkit.broadcastMessage(
event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
event.setCancelled(true);
}
@ -197,10 +196,10 @@ public class PlayerListener implements Listener {
}
public static boolean ActiveF = false;
public static int FCount = 0;
public static ChatPlayer FPlayer = null;
private Timer Ftimer;
public static int AlphaDeaths;
public static ArrayList<CommandSender> Fs = new ArrayList<>();
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
@ -211,24 +210,21 @@ public class PlayerListener implements Listener {
if (Ftimer != null)
Ftimer.cancel();
ActiveF = true;
FCount = 0;
Fs.clear();
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId()).asPluginPlayer(ChatPlayer.class);
FPlayer.setFDeaths(FPlayer.getFDeaths() + 1);
for (Player p : PluginMain.GetPlayers()) {
ChatPlayer mp = TBMCPlayer.getPlayerAs(p.getUniqueId(), ChatPlayer.class);
mp.PressedF = false;
p.sendMessage("§bPress F to pay respects.§r");
}
Bukkit.broadcastMessage("§bPress F to pay respects.§r");
Ftimer = new Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
if (ActiveF) {
ActiveF = false;
for (Player p : PluginMain.GetPlayers()) {
p.sendMessage("§b" + FCount + " " + (FCount == 1 ? "person" : "people")
+ " paid their respects.§r");
}
if (FPlayer != null && FPlayer.getFCount() < Integer.MAX_VALUE - 1)
FPlayer.setFCount(FPlayer.getFCount() + Fs.size());
Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
+ " paid their respects.§r");
Fs.clear();
}
}
};
@ -314,10 +310,7 @@ public class PlayerListener implements Listener {
}
if (target != null) {
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
for (Player pl : PluginMain.GetPlayers())
pl.sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
Bukkit.getServer().getConsoleSender()
.sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
Bukkit.broadcastMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
event.setCommand("dontrunthiscmd");
}
}
@ -337,6 +330,16 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerTBMCChat(TBMCChatEvent e) {
ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage());
try {
e.setCancelled(ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage()));
} catch (Exception ex) {
for (Player p : Bukkit.getOnlinePlayers())
p.sendMessage("§c!§r["
+ e.getChannel().DisplayName + "] <" + (e.getSender() instanceof Player
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
+ "> " + e.getMessage());
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
e.setCancelled(true);
}
}
}