) commonFormatters.clone();
- formatters.add(new ChatFormatterBuilder().setRegex(ENTIRE_MESSAGE_PATTERN).setColor(colormode)
- .setPriority(Priority.Low).build());
+ formatters.add(
+ ChatFormatter.builder().regex(ENTIRE_MESSAGE_PATTERN).color(colormode).priority(Priority.Low).build());
if (Bukkit.getOnlinePlayers().size() > 0) {
StringBuilder namesb = new StringBuilder("(?i)(");
@@ -271,8 +280,8 @@ public class ChatProcessing {
}
nicksb.append(")");
- formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())).setColor(Color.Aqua)
- .setOnmatch((match, builder) -> {
+ formatters.add(ChatFormatter.builder().regex(Pattern.compile(namesb.toString())).color(Color.Aqua)
+ .onmatch((match, builder) -> {
Player p = Bukkit.getPlayer(match);
if (p == null) {
PluginMain.Instance.getLogger()
@@ -287,11 +296,11 @@ public class ChatProcessing {
(float) PlayerListener.NotificationPitch);
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
return color + p.getName() + "§r";
- }).setPriority(Priority.High).build());
+ }).priority(Priority.High).build());
if (addNickFormatter)
- formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString()))
- .setColor(Color.Aqua).setOnmatch((match, builder) -> {
+ formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua)
+ .onmatch((match, builder) -> {
if (PlayerListener.nicknames.containsKey(match)) {
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
if (p == null) {
@@ -309,7 +318,7 @@ public class ChatProcessing {
Bukkit.getServer().getLogger().warning("Player nicknamed " + match
+ " not found in nickname map but was reported as online.");
return "§c" + match + "§r";
- }).setPriority(Priority.High).build());
+ }).priority(Priority.High).build());
}
return formatters;
}
diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java
index f54690c..a381f5d 100644
--- a/src/main/java/buttondevteam/chat/PluginMain.java
+++ b/src/main/java/buttondevteam/chat/PluginMain.java
@@ -23,7 +23,6 @@ import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.Channel.RecipientTestResult;
import buttondevteam.lib.player.TBMCPlayerBase;
-
import com.earth2me.essentials.Essentials;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@@ -63,6 +62,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public static Channel TownChat;
public static Channel NationChat;
+ public static Channel RPChannel;
/**
*
@@ -93,6 +93,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
TBMCChatAPI.RegisterChatChannel(
NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true)));
+ TBMCChatAPI.RegisterChatChannel(RPChannel = new Channel("§7RP§f", Color.Gray, "rp", Channel.noScoreResult(s -> {
+ if (s instanceof ConsoleCommandSender)
+ return true;
+ return true; // TODO: Allow hiding it
+ }, "You need to show the RP chat in order to speak in it.")));
setupChat();
setupEconomy();
@@ -324,10 +329,16 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) {
if (!(sender instanceof Player))
return new RecipientTestResult("§cYou are not a player!");
+ Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
+ RecipientTestResult result = checkTownNationChatInternal(sender, nationchat, resident);
+ if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it
+ result = new RecipientTestResult(1000); // There won't be more than a thousand towns/nations probably
+ return result;
+ }
+
+ private static RecipientTestResult checkTownNationChatInternal(CommandSender sender, boolean nationchat,
+ Resident resident) {
try {
- Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
- if (resident != null && resident.getModes().contains("spy"))
- return null;
/*
* p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message));
*/
diff --git a/src/main/java/buttondevteam/chat/commands/OOCCommand.java b/src/main/java/buttondevteam/chat/commands/OOCCommand.java
deleted file mode 100644
index c85151f..0000000
--- a/src/main/java/buttondevteam/chat/commands/OOCCommand.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package buttondevteam.chat.commands;
-
-import org.bukkit.entity.Player;
-
-import buttondevteam.chat.ChatPlayer;
-import buttondevteam.lib.chat.CommandClass;
-import buttondevteam.lib.chat.PlayerCommandBase;
-import buttondevteam.lib.player.TBMCPlayer;
-
-@CommandClass(modOnly = false)
-public final class OOCCommand extends PlayerCommandBase {
-
- @Override
- public String[] GetHelpText(String alias) {
- return new String[] { "§6---- Out-of-character message ----",
- "This command will put a [OCC] tag before your message indicating that you are talking out of character",
- "Usage: /" + alias + " " };
- }
-
- @Override
- public boolean OnCommand(Player player, String alias, String[] args) {
- if (args.length == 0) {
- return false;
- } else {
- final ChatPlayer cp = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
- cp.RPMode = false;
- String message = "";
- for (String arg : args)
- message += arg + " ";
- player.chat(message.substring(0, message.length() - 1));
- cp.RPMode = true;
- }
- return true;
- }
-
-}
diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java
index 9e333db..4ea2973 100644
--- a/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java
+++ b/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java
@@ -16,8 +16,7 @@ public final class IgnoreCommand extends UCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Ignore flair ----",
- "Stop the \"write your name in the thread\" message from showing up",
- "Use /u ignore if you commented from multiple accounts" };
+ "Stop the \"write your name in the thread\" message from showing up" };
}
@Override
diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java
index be359b2..d86fcf2 100644
--- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java
+++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java
@@ -23,7 +23,7 @@ public class AddCommand extends AnnounceCommandBase {
return false;
}
StringBuilder sb = new StringBuilder();
- for (int i = 2; i < args.length; i++) {
+ for (int i = 0; i < args.length; i++) {
sb.append(args[i]);
if (i != args.length - 1)
sb.append(" ");
diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java
index 42b3ada..0bb0c32 100644
--- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java
+++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java
@@ -21,22 +21,22 @@ public class EditCommand extends AnnounceCommandBase {
sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended.");
return true;
}
- if (args.length < 4) {
+ if (args.length < 1) {
return false;
}
StringBuilder sb1 = new StringBuilder();
- for (int i1 = 3; i1 < args.length; i1++) {
+ for (int i1 = 1; i1 < args.length; i1++) {
sb1.append(args[i1]);
if (i1 != args.length - 1)
sb1.append(" ");
}
String finalmessage1 = sb1.toString().replace('&', '§');
- int index = Integer.parseInt(args[2]);
+ int index = Integer.parseInt(args[0]);
if (index > 100)
return false;
while (PluginMain.AnnounceMessages.size() <= index)
PluginMain.AnnounceMessages.add("");
- PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
+ PluginMain.AnnounceMessages.set(Integer.parseInt(args[0]),
finalmessage1);
sender.sendMessage("Announcement edited.");
return true;
diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java
index fe488d6..4e36a0b 100644
--- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java
+++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java
@@ -16,7 +16,7 @@ public class SetTimeCommand extends AnnounceCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias,
String[] args) {
- if (args.length < 3) {
+ if (args.length < 1) {
return false;
}
try {
diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java
index e655e1f..4924ff5 100644
--- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java
+++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java
@@ -4,12 +4,17 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import buttondevteam.lib.chat.*;
+import lombok.Builder;
+import lombok.Data;
/**
* A {@link ChatFormatter} shows what formatting to use based on regular expressions. {@link ChatFormatter#Combine(List, String, TellrawPart)} is used to turn it into a {@link TellrawPart}, combining
@@ -19,12 +24,24 @@ import buttondevteam.lib.chat.*;
* @author NorbiPeti
*
*/
+@Data
+@Builder
public final class ChatFormatter {
- private ChatFormatterBuilder builder;
-
- public ChatFormatter(ChatFormatterBuilder builder) {
- this.builder = builder;
- }
+ Pattern regex;
+ boolean italic;
+ boolean bold;
+ boolean underlined;
+ boolean strikethrough;
+ boolean obfuscated;
+ Color color;
+ BiFunction onmatch;
+ String openlink;
+ @Builder.Default
+ Priority priority = Priority.Normal;
+ @Builder.Default
+ short removeCharCount = 0;
+ @Builder.Default
+ boolean range = false;
public static void Combine(List formatters, String str, TellrawPart tp) {
/*
@@ -33,7 +50,7 @@ public final class ChatFormatter {
header("ChatFormatter.Combine begin");
ArrayList sections = new ArrayList();
for (ChatFormatter formatter : formatters) {
- Matcher matcher = formatter.builder.regex.matcher(str);
+ Matcher matcher = formatter.regex.matcher(str);
while (matcher.find()) {
DebugCommand.SendDebugMessage("Found match from " + matcher.start() + " to " + (matcher.end() - 1));
DebugCommand.SendDebugMessage("With formatter:" + formatter);
@@ -44,13 +61,13 @@ public final class ChatFormatter {
if (groups.size() > 0)
DebugCommand.SendDebugMessage("First group: " + groups.get(0));
FormattedSection section = new FormattedSection(formatter, matcher.start(), matcher.end() - 1, groups,
- formatter.builder.removecharcount, formatter.builder.removecharcount, formatter.builder.range);
+ formatter.removeCharCount, formatter.removeCharCount, formatter.range);
sections.add(section);
}
}
sections.sort((s1, s2) -> s1.Start == s2.Start
- ? s1.End == s2.End ? Integer.compare(s2.Formatters.get(0).builder.priority.GetValue(),
- s1.Formatters.get(0).builder.priority.GetValue()) : Integer.compare(s2.End, s1.End)
+ ? s1.End == s2.End ? Integer.compare(s2.Formatters.get(0).priority.GetValue(),
+ s1.Formatters.get(0).priority.GetValue()) : Integer.compare(s2.End, s1.End)
: Integer.compare(s1.Start, s2.Start));
header("Range section conversion");
@@ -243,11 +260,10 @@ public final class ChatFormatter {
if (found) {
i = 1;
found = false;
- sections.sort((s1,
- s2) -> s1.Start == s2.Start ? s1.End == s2.End
- ? Integer.compare(s2.Formatters.get(0).builder.priority.GetValue(),
- s1.Formatters.get(0).builder.priority.GetValue())
- : Integer.compare(s2.End, s1.End) : Integer.compare(s1.Start, s2.Start));
+ sections.sort((s1, s2) -> s1.Start == s2.Start
+ ? s1.End == s2.End ? Integer.compare(s2.Formatters.get(0).priority.GetValue(),
+ s1.Formatters.get(0).priority.GetValue()) : Integer.compare(s2.End, s1.End)
+ : Integer.compare(s1.Start, s2.Start));
} else
cont = false;
}
@@ -266,25 +282,25 @@ public final class ChatFormatter {
Color color = null;
boolean bold = false, italic = false, underlined = false, strikethrough = false, obfuscated = false;
String openlink = null;
- section.Formatters.sort((cf2, cf1) -> cf1.builder.priority.compareTo(cf2.builder.priority));
+ section.Formatters.sort((cf2, cf1) -> cf1.priority.compareTo(cf2.priority));
for (ChatFormatter formatter : section.Formatters) {
DebugCommand.SendDebugMessage("Applying formatter: " + formatter);
- if (formatter.builder.onmatch != null)
- originaltext = formatter.builder.onmatch.apply(originaltext, formatter.builder);
- if (formatter.builder.color != null)
- color = formatter.builder.color;
- if (formatter.builder.bold)
+ if (formatter.onmatch != null)
+ originaltext = formatter.onmatch.apply(originaltext, formatter);
+ if (formatter.color != null)
+ color = formatter.color;
+ if (formatter.bold)
bold = true;
- if (formatter.builder.italic)
+ if (formatter.italic)
italic = true;
- if (formatter.builder.underlined)
+ if (formatter.underlined)
underlined = true;
- if (formatter.builder.strikethrough)
+ if (formatter.strikethrough)
strikethrough = true;
- if (formatter.builder.obfuscated)
+ if (formatter.obfuscated)
obfuscated = true;
- if (formatter.builder.openlink != null)
- openlink = formatter.builder.openlink;
+ if (formatter.openlink != null)
+ openlink = formatter.openlink;
}
TellrawPart newtp = new TellrawPart("");
newtp.setText(originaltext);
@@ -306,16 +322,6 @@ public final class ChatFormatter {
header("ChatFormatter.Combine done");
}
- @Override
- public String toString() {
- return new StringBuilder("F(").append(builder.color).append(", ")
- .append((builder.bold ? "bold" : "") + (builder.italic ? "italic" : "")
- + (builder.underlined ? "underlined" : "") + (builder.strikethrough ? "strikethrough" : "")
- + (builder.obfuscated ? "obfuscated" : ""))
- .append(", ").append(builder.openlink).append(", ").append(builder.priority).append(", ")
- .append(builder.regex).append(")").toString(); // TODO: Lombok
- }
-
/**
*
* @param str
diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java
deleted file mode 100644
index 4772180..0000000
--- a/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package buttondevteam.chat.formatting;
-
-import java.io.Serializable;
-import java.util.function.BiFunction;
-import java.util.regex.Pattern;
-
-import buttondevteam.lib.chat.*;
-import lombok.SneakyThrows;
-
-public class ChatFormatterBuilder implements Serializable {
- private static final long serialVersionUID = -6115913400749778686L;
- Pattern regex;
- boolean italic;
- boolean bold;
- boolean underlined;
- boolean strikethrough;
- boolean obfuscated;
- Color color;
- BiFunction onmatch;
- String openlink;
- Priority priority = Priority.Normal;
- short removecharcount = 0;
- boolean range = false;
-
- /**
- * The returned object is backed by this builder. All changes made to this object affets the returned one.
- */
- @SneakyThrows
- public ChatFormatter build() {
- return new ChatFormatter(this);
- }
-
- public Pattern getRegex() {
- return regex;
- }
-
- public ChatFormatterBuilder setRegex(Pattern regex) {
- this.regex = regex;
- return this;
- }
-
- public boolean isItalic() {
- return italic;
- }
-
- public ChatFormatterBuilder setItalic(boolean italic) {
- this.italic = italic;
- return this;
- }
-
- public boolean isBold() {
- return bold;
- }
-
- public ChatFormatterBuilder setBold(boolean bold) {
- this.bold = bold;
- return this;
- }
-
- public boolean isUnderlined() {
- return underlined;
- }
-
- public ChatFormatterBuilder setUnderlined(boolean underlined) {
- this.underlined = underlined;
- return this;
- }
-
- public boolean isStrikethrough() {
- return strikethrough;
- }
-
- public ChatFormatterBuilder setStrikethrough(boolean strikethrough) {
- this.strikethrough = strikethrough;
- return this;
- }
-
- public boolean isObfuscated() {
- return obfuscated;
- }
-
- public ChatFormatterBuilder setObfuscated(boolean obfuscated) {
- this.obfuscated = obfuscated;
- return this;
- }
-
- public Color getColor() {
- return color;
- }
-
- public ChatFormatterBuilder setColor(Color color) {
- this.color = color;
- return this;
- }
-
- public BiFunction getOnmatch() {
- return onmatch;
- }
-
- /**
- * Making any changes here using the builder will not affect the previous matches with the current design
- */
- public ChatFormatterBuilder setOnmatch(BiFunction onmatch) {
- this.onmatch = onmatch;
- return this;
- }
-
- public String getOpenlink() {
- return openlink;
- }
-
- public ChatFormatterBuilder setOpenlink(String openlink) {
- this.openlink = openlink;
- return this;
- }
-
- public Priority getPriority() {
- return priority;
- }
-
- public ChatFormatterBuilder setPriority(Priority priority) {
- this.priority = priority == null ? Priority.Normal : priority;
- return this;
- }
-
- public short getRemoveCharCount() {
- return removecharcount;
- }
-
- /**
- * Sets the amount of characters to be removed from the start and the end of the match.
- *
- * @return This instance
- */
- public ChatFormatterBuilder setRemoveCharCount(short removecharcount) {
- this.removecharcount = removecharcount;
- return this;
- }
-
- public boolean isRange() {
- return range;
- }
-
- public ChatFormatterBuilder setRange(boolean range) {
- this.range = range;
- return this;
- }
-}
diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java
index 5e05bee..aa96a2b 100644
--- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java
+++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java
@@ -86,8 +86,6 @@ public class PlayerJoinLeaveListener implements Listener {
nwithoutformatting = p.getName();
PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId());
- cp.RPMode = true;
-
cp.FlairUpdate();
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java
index 521eb54..0e8bb55 100644
--- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java
+++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java
@@ -2,9 +2,12 @@ package buttondevteam.chat.listener;
import java.util.*;
import java.util.Map.Entry;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
import org.bukkit.event.entity.PlayerDeathEvent;
@@ -18,9 +21,11 @@ import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.ChatChannelRegisterEvent;
+import buttondevteam.lib.chat.ChatRoom;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
+import net.ess3.api.events.NickChangeEvent;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import com.google.common.collect.BiMap;
@@ -57,43 +62,67 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void PlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
- if (event.getMessage().length() < 2)
- return;
- int index = event.getMessage().indexOf(" ");
- ChatPlayer mp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class);
+ if (!event.isCancelled())
+ event.setCancelled(onCommandPreprocess(event.getPlayer(), event.getMessage()));
+ }
+
+ private boolean onCommandPreprocess(CommandSender sender, String message) {
+ if (message.length() < 2)
+ return false;
+ int index = message.indexOf(" ");
+ ChatPlayer mp;
+ if (sender instanceof Player)
+ mp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class);
+ else
+ mp = null;
String cmd = "";
- if (index == -1) { // Only the command is run
- cmd = event.getMessage().substring(1);
+ if (index == -1 && (sender instanceof Player || sender instanceof ConsoleCommandSender)) { // Only the command is run
+ // ^^ We can only store player or console channels - Directly sending to channels would still work if they had an event
+ cmd = sender instanceof ConsoleCommandSender ? message : message.substring(1);
for (Channel channel : Channel.getChannels()) {
if (cmd.equalsIgnoreCase(channel.ID)) {
- if (mp.CurrentChannel.equals(channel))
- mp.CurrentChannel = Channel.GlobalChat;
- else
- mp.CurrentChannel = channel;
- event.getPlayer().sendMessage("§6You are now talking in: §b" + mp.CurrentChannel.DisplayName);
- event.setCancelled(true);
- break;
+ Supplier getch = () -> sender instanceof Player ? mp.CurrentChannel : ConsoleChannel;
+ Consumer setch = ch -> {
+ if (sender instanceof Player)
+ mp.CurrentChannel = ch;
+ else
+ ConsoleChannel = ch;
+ };
+ Channel oldch = getch.get();
+ if (oldch instanceof ChatRoom)
+ ((ChatRoom) oldch).leaveRoom(sender);
+ if (oldch.equals(channel))
+ setch.accept(Channel.GlobalChat);
+ else {
+ setch.accept(channel);
+ if (channel instanceof ChatRoom)
+ ((ChatRoom) channel).joinRoom(sender);
+ }
+ sender.sendMessage("§6You are now talking in: §b" + getch.get().DisplayName);
+ return true;
}
}
} else { // We have arguments
- cmd = event.getMessage().substring(1, index);
+ cmd = sender instanceof ConsoleCommandSender ? message.substring(0, index) : message.substring(1, index);
if (cmd.equalsIgnoreCase("tpahere")) {
- Player player = Bukkit.getPlayer(event.getMessage().substring(index + 1));
- if (player != null)
- player.sendMessage("§b" + event.getPlayer().getDisplayName() + " §bis in this world: "
- + event.getPlayer().getWorld().getName());
+ Player player = Bukkit.getPlayer(message.substring(index + 1));
+ if (player != null && sender instanceof Player)
+ player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: "
+ + ((Player) sender).getWorld().getName());
} else if (cmd.equalsIgnoreCase("minecraft:me")) {
- if (!PluginMain.essentials.getUser(event.getPlayer()).isMuted()) {
- event.setCancelled(true);
- String message = event.getMessage().substring(index + 1);
- Bukkit.broadcastMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
+ if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
+ String msg = message.substring(index + 1);
+ Bukkit.broadcastMessage(String.format("* %s %s", ((Player) sender).getDisplayName(), msg));
+ return true;
+ } else {
+ sender.sendMessage("§cCan't use /minecraft:me while muted.");
+ return true;
}
} else
for (Channel channel : Channel.getChannels()) {
if (cmd.equalsIgnoreCase(channel.ID)) {
- event.setCancelled(true);
- TBMCChatAPI.SendChatMessage(channel, event.getPlayer(),
- event.getMessage().substring(index + 1));
+ TBMCChatAPI.SendChatMessage(channel, sender, message.substring(index + 1));
+ return true;
}
}
// TODO: Target selectors
@@ -102,24 +131,24 @@ public class PlayerListener implements Listener {
if (cmd.toLowerCase().startsWith("un")) {
for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) {
if (ht.getName().equalsIgnoreCase("/" + cmd))
- return;
+ return false;
}
- if (PluginMain.permission.has(event.getPlayer(), "tbmc.admin")) {
+ if (PluginMain.permission.has(sender, "tbmc.admin")) {
String s = cmd.substring(2);
Player target = null;
- target = Bukkit.getPlayer(event.getMessage().substring(index + 1));
+ target = Bukkit.getPlayer(message.substring(index + 1));
if (target == null) {
- event.getPlayer().sendMessage("§cError: Player not found. (/un" + s + " )");
- event.setCancelled(true);
- }
- if (target != null) {
- target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
- Bukkit.broadcastMessage(
- event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
- event.setCancelled(true);
+ sender.sendMessage("§cError: Player not found. (/un" + s + " )");
+ return true;
}
+ target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
+ Bukkit.broadcastMessage(
+ (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " un" + s
+ + "'d " + target.getDisplayName());
+ return true;
}
}
+ return false;
}
@EventHandler
@@ -203,54 +232,8 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsoleCommand(ServerCommandEvent event) {
- if (event.getCommand().length() < 2)
- return;
- int index = event.getCommand().indexOf(" ");
- String cmd = "";
- if (index == -1) {
- cmd = event.getCommand();
- for (Channel channel : Channel.getChannels()) {
- if (cmd.equalsIgnoreCase(channel.ID)) {
- if (ConsoleChannel.equals(channel))
- ConsoleChannel = Channel.GlobalChat;
- else
- ConsoleChannel = channel;
- event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName);
- event.setCommand("dontrunthiscmd");
- break;
- }
- }
- } else {
- cmd = event.getCommand().substring(0, index);
- for (Channel channel : Channel.getChannels()) {
- if (cmd.equalsIgnoreCase(channel.ID)) {
- Channel c = ConsoleChannel;
- ConsoleChannel = channel;
- TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, Bukkit.getConsoleSender(),
- event.getCommand().substring(index + 1));
- ConsoleChannel = c;
- event.setCommand("dontrunthiscmd");
- }
- }
- }
- if (cmd.toLowerCase().startsWith("un")) {
- for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) {
- if (ht.getName().equalsIgnoreCase("/" + cmd))
- return;
- }
- String s = cmd.substring(2);
- Player target = null;
- target = Bukkit.getPlayer(event.getCommand().substring(index + 1));
- if (target == null) {
- event.getSender().sendMessage("§cError: Player not found. (/un" + s + " )");
- event.setCommand("dontrunthiscmd");
- }
- if (target != null) {
- target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
- Bukkit.broadcastMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
- event.setCommand("dontrunthiscmd");
- }
- }
+ if (onCommandPreprocess(event.getSender(), event.getCommand()))
+ event.setCommand("dontrunthiscmd");
}
@EventHandler
@@ -292,4 +275,9 @@ public class PlayerListener implements Listener {
if (e.getChannel().filteranderrormsg != null && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet
PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy");
}
+
+ @EventHandler
+ public void onNickChange(NickChangeEvent e) {
+ nicknames.inverse().put(e.getAffected().getBase().getUniqueId(), e.getValue());
+ }
}
diff --git a/src/test/java/buttondevteam/chat/ChatFormatIT.java b/src/test/java/buttondevteam/chat/ChatFormatIT.java
index 19c8f59..fc8124b 100644
--- a/src/test/java/buttondevteam/chat/ChatFormatIT.java
+++ b/src/test/java/buttondevteam/chat/ChatFormatIT.java
@@ -63,7 +63,7 @@ public class ChatFormatIT extends TestCase {
@Test
public void testMessage() {
ArrayList cfs = ChatProcessing.addFormatters(Color.White);
- final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, null);
+ final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender);
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, chid);
ChatFormatter.Combine(cfs, message, tp);
System.out.println("Testing: " + message);