Announcement cmds fixed, nicknames update for mentions, Towny spy fixed, added RP channel, ChatRooms implemented #70

Merged
NorbiPeti merged 3 commits from dev into master 2017-08-28 16:13:44 +00:00
14 changed files with 189 additions and 359 deletions

View file

@ -92,12 +92,16 @@
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
<version>1.2.1</version> <executions> <execution> <goals> <goal>check</goal>
</goals> </execution> </executions> </plugin> -->
</plugins>
</build>
<groupId>buttondevteam</groupId>

View file

@ -42,7 +42,6 @@ public class ChatPlayer extends TBMCPlayerBase {
return data(false);
}
public boolean RPMode = true;
public Location SavedLocation;
public boolean Working;
// public int Tables = 10;

View file

@ -2,6 +2,7 @@ package buttondevteam.chat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
@ -40,37 +41,38 @@ public class ChatProcessing {
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("\\_");
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
private static final Pattern CODE_PATTERN = Pattern.compile("`");
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])\\]\\(([^\\(\\)])\\)");
private static final Color[] RainbowPresserColors = new Color[] { Color.Red, Color.Gold, Color.Yellow, Color.Green,
Color.Blue, Color.DarkPurple };
private static boolean pingedconsole = false;
public static final ChatFormatter ESCAPE_FORMATTER = new ChatFormatterBuilder().setRegex(ESCAPE_PATTERN).build();
public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build();
private static ArrayList<ChatFormatter> commonFormatters = Lists.newArrayList(
new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setBold(true).setRemoveCharCount((short) 2).setRange(true)
.setPriority(Priority.High).build(),
new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setItalic(true).setRemoveCharCount((short) 1)
.setRange(true).build(),
new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setUnderlined(true).setRemoveCharCount((short) 1)
.setRange(true).build(),
ESCAPE_FORMATTER,
new ChatFormatterBuilder().setRegex(URL_PATTERN).setUnderlined(true).setOpenlink("$1").build(),
new ChatFormatterBuilder().setRegex(NULL_MENTION_PATTERN).setColor(Color.DarkRed).build(), // Properly added a bug as a feature
new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(Color.Aqua)
.setOnmatch((match, builder) ->
ChatFormatter.builder().regex(BOLD_PATTERN).bold(true).removeCharCount((short) 2).range(true)
.priority(Priority.High).build(),
ChatFormatter.builder().regex(ITALIC_PATTERN).italic(true).removeCharCount((short) 1).range(true).build(),
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).range(true)
.build(),
ESCAPE_FORMATTER, ChatFormatter.builder().regex(URL_PATTERN).underlined(true).openlink("$1").build(),
ChatFormatter.builder().regex(NULL_MENTION_PATTERN).color(Color.DarkRed).build(), // Properly added a bug as a feature
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder) -> {
if (!pingedconsole) {
System.out.print("\007");
pingedconsole = true; // Will set it to false in ProcessChat
}
return match;
}).priority(Priority.High).build(),
{
if (!pingedconsole) {
System.out.print("\007");
pingedconsole = true; // Will set it to false in ProcessChat
}
return match;
}).setPriority(Priority.High).build(),
new ChatFormatterBuilder().setRegex(HASHTAG_PATTERN).setColor(Color.Blue)
.setOpenlink("https://twitter.com/hashtag/$1").setPriority(Priority.High).build(),
new ChatFormatterBuilder().setRegex(CYAN_PATTERN).setColor(Color.Aqua).build() // #55
);
ChatFormatter.builder().regex(HASHTAG_PATTERN).color(Color.Blue).openlink("https://twitter.com/hashtag/$1")
.priority(Priority.High).build(),
ChatFormatter.builder().regex(CYAN_PATTERN).color(Color.Aqua).build(), // #55
ChatFormatter.builder().regex(CODE_PATTERN).color(Color.DarkGray).removeCharCount((short) 1).range(true)
.build(),
ChatFormatter.builder().regex(MASKED_LINK_PATTERN).underlined(true).onmatch((match, builder) -> {
return match; // TODO!
}).build());
private static Gson gson = new GsonBuilder()
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
@ -108,14 +110,13 @@ public class ChatProcessing {
ArrayList<ChatFormatter> formatters = addFormatters(colormode);
if (colormode == channel.color && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
final AtomicInteger rpc = new AtomicInteger(0);
formatters.add(new ChatFormatterBuilder().setColor(colormode).setOnmatch((match, builder) -> {
builder.setColor(
RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf) -> {
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
return match;
}).build());
}
pingedconsole = false; // Will set it to true onmatch (static constructor)
final String channelidentifier = getChannelID(channel, sender, mp);
final String channelidentifier = getChannelID(channel, sender);
TellrawPart json = createTellraw(sender, message, player, mp, channelidentifier);
long combinetime = System.nanoTime();
@ -148,10 +149,18 @@ public class ChatProcessing {
score = e.getMCScore(sender);
if (score < 0) // Never send messages to score below 0
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
else
else {
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
score, jsonstr));
if (e.getChannel().ID.equals(PluginMain.TownChat.ID)
|| e.getChannel().ID.equals(PluginMain.NationChat.ID)) {
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
jsonstr = toJson(json);
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr));
}
}
} else
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
String.format("tellraw @a %s", jsonstr));
@ -235,9 +244,9 @@ public class ChatProcessing {
return json;
}
static String getChannelID(Channel channel, CommandSender sender, ChatPlayer mp) {
static String getChannelID(Channel channel, CommandSender sender) {
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + channel.DisplayName)
+ "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
+ "]";
return channelidentifier;
}
@ -245,8 +254,8 @@ public class ChatProcessing {
@SuppressWarnings("unchecked")
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) 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;
}

View file

@ -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;
/**
* <p>
@ -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));
*/

View file

@ -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 + " <message>" };
}
@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;
}
}

View file

@ -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 <username> if you commented from multiple accounts" };
"Stop the \"write your name in the thread\" message from showing up" };
}
@Override

View file

@ -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(" ");

View file

@ -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;

View file

@ -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 {

View file

@ -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<String, ChatFormatter, String> onmatch;
String openlink;
@Builder.Default
Priority priority = Priority.Normal;
@Builder.Default
short removeCharCount = 0;
@Builder.Default
boolean range = false;
public static void Combine(List<ChatFormatter> formatters, String str, TellrawPart tp) {
/*
@ -33,7 +50,7 @@ public final class ChatFormatter {
header("ChatFormatter.Combine begin");
ArrayList<FormattedSection> sections = new ArrayList<FormattedSection>();
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

View file

@ -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<String, ChatFormatterBuilder, String> 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<String, ChatFormatterBuilder, String> getOnmatch() {
return onmatch;
}
/**
* Making any changes here using the builder will not affect the previous matches with the current design
*/
public ChatFormatterBuilder setOnmatch(BiFunction<String, ChatFormatterBuilder, String> 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;
}
}

View file

@ -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)) {

View file

@ -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<Channel> getch = () -> sender instanceof Player ? mp.CurrentChannel : ConsoleChannel;
Consumer<Channel> 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 + " <player>)");
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 + " <player>)");
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 + " <player>)");
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());
}
}

View file

@ -63,7 +63,7 @@ public class ChatFormatIT extends TestCase {
@Test
public void testMessage() {
ArrayList<ChatFormatter> 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);