Added /waitwhat, applied userdata changes, added format test, progressed with formatting #62
24 changed files with 625 additions and 394 deletions
36
Notes.txt
Normal file
36
Notes.txt
Normal file
|
@ -0,0 +1,36 @@
|
|||
Expected:
|
||||
|
||||
***test***
|
||||
||- ||-
|
||||
|
||||
||: bold
|
||||
-: italic
|
||||
|
||||
|
||||
Actual:
|
||||
|
||||
***test***
|
||||
||- ||-
|
||||
-|| -||
|
||||
- -
|
||||
|
||||
nextSection:
|
||||
*: italic(0)
|
||||
**:
|
||||
Either italic(0), bold(0) - Delete italic
|
||||
bold(0), italic(1) - Delete italic
|
||||
bold(0)
|
||||
Or bold(0), italic(0) - Delete italic?
|
||||
italic, italic - 0-length section as result, delete?
|
||||
|
||||
takenStart, takenEnd
|
||||
because it's ordered, the indexes will be either the same or ascending
|
||||
|
||||
|
||||
^^ Implemented
|
||||
|
||||
**test**
|
||||
^ ^ <-- !
|
||||
start end
|
||||
RemChar: 2
|
||||
tes*
|
|
@ -6,70 +6,43 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.*;
|
||||
import buttondevteam.lib.player.EnumPlayerData;
|
||||
import buttondevteam.lib.player.PlayerClass;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
public class ChatPlayer extends TBMCPlayer {
|
||||
public String getUserName() {
|
||||
return getData();
|
||||
@PlayerClass(pluginname = "ButtonChat")
|
||||
public class ChatPlayer extends TBMCPlayerBase {
|
||||
public PlayerData<String> UserName() {
|
||||
return data();
|
||||
}
|
||||
|
||||
public void setUserName(String name) {
|
||||
setData(name);
|
||||
public List<String> UserNames() {
|
||||
PlayerData<List<String>> data = data();
|
||||
if (data.get() == null)
|
||||
data.set(new ArrayList<String>());
|
||||
return data.get();
|
||||
}
|
||||
|
||||
public List<String> getUserNames() {
|
||||
List<String> data = getData();
|
||||
if (data == null)
|
||||
setUserNames(data = new ArrayList<String>());
|
||||
return data;
|
||||
public PlayerData<Integer> FlairTime() {
|
||||
return data();
|
||||
}
|
||||
|
||||
public void setUserNames(List<String> names) {
|
||||
setData(names);
|
||||
public EnumPlayerData<FlairStates> FlairState() {
|
||||
return dataEnum(FlairStates.class);
|
||||
}
|
||||
|
||||
public short getFlairTime() {
|
||||
return getIntData(Short.class).orElse(FlairTimeNone);
|
||||
public PlayerData<Integer> FCount() {
|
||||
return data();
|
||||
}
|
||||
|
||||
private void setFlairTime(short time) {
|
||||
setIntData(time);
|
||||
public PlayerData<Integer> FDeaths() {
|
||||
return data();
|
||||
}
|
||||
|
||||
public FlairStates getFlairState() {
|
||||
FlairStates data = getEnumData(FlairStates.class);
|
||||
if (data == null)
|
||||
setFlairState(data = FlairStates.NoComment);
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setFlairState(FlairStates state) {
|
||||
setEnumData(state);
|
||||
}
|
||||
|
||||
public int getFCount() {
|
||||
return getIntData(Integer.class).orElse(0);
|
||||
}
|
||||
|
||||
public void setFCount(int count) {
|
||||
setIntData(count);
|
||||
}
|
||||
|
||||
public int getFDeaths() {
|
||||
return getIntData(Integer.class).orElse(0);
|
||||
}
|
||||
|
||||
public void setFDeaths(int count) {
|
||||
setIntData(count);
|
||||
}
|
||||
|
||||
public boolean getFlairCheater() {
|
||||
return getBoolData();
|
||||
}
|
||||
|
||||
private void setFlairCheater(boolean cheater) {
|
||||
setData(cheater);
|
||||
public PlayerData<Boolean> FlairCheater() {
|
||||
return data();
|
||||
}
|
||||
|
||||
public boolean RPMode = true;
|
||||
|
@ -83,9 +56,9 @@ public class ChatPlayer extends TBMCPlayer {
|
|||
public boolean ChatOnly = false;
|
||||
public int LoginWarningCount = 0;
|
||||
|
||||
public static final short FlairTimeNonPresser = -1;
|
||||
public static final short FlairTimeCantPress = -2;
|
||||
public static final short FlairTimeNone = -3;
|
||||
public static final int FlairTimeNonPresser = -1;
|
||||
public static final int FlairTimeCantPress = -2;
|
||||
public static final int FlairTimeNone = -3;
|
||||
|
||||
/**
|
||||
* Gets the player's flair, optionally formatting for Minecraft.
|
||||
|
@ -95,14 +68,15 @@ public class ChatPlayer extends TBMCPlayer {
|
|||
* @return The flair
|
||||
*/
|
||||
public String GetFormattedFlair(boolean noformats) {
|
||||
if (getFlairTime() == FlairTimeCantPress)
|
||||
int time = FlairTime().getOrDefault(FlairTimeNone);
|
||||
if (time == FlairTimeCantPress)
|
||||
return String.format(noformats ? "(can't press)" : "§r(--s)§r");
|
||||
if (getFlairTime() == FlairTimeNonPresser)
|
||||
if (time == FlairTimeNonPresser)
|
||||
return String.format(noformats ? "(non-presser)" : "§7(--s)§r");
|
||||
if (getFlairTime() == FlairTimeNone)
|
||||
if (time == FlairTimeNone)
|
||||
return "";
|
||||
return noformats ? String.format("(%ss)", getFlairTime())
|
||||
: String.format("§%x(%ss)§r", GetFlairColor(), getFlairTime());
|
||||
return noformats ? String.format("(%ss)", FlairTime().get())
|
||||
: String.format("§%x(%ss)§r", GetFlairColor(), FlairTime().get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,14 +88,14 @@ public class ChatPlayer extends TBMCPlayer {
|
|||
return GetFormattedFlair(false);
|
||||
}
|
||||
|
||||
public void SetFlair(short time) {
|
||||
setFlairTime(time);
|
||||
public void SetFlair(int time) {
|
||||
FlairTime().set(time);
|
||||
FlairUpdate();
|
||||
}
|
||||
|
||||
public void SetFlair(short time, boolean cheater) {
|
||||
setFlairTime(time);
|
||||
setFlairCheater(cheater);
|
||||
public void SetFlair(int time, boolean cheater) {
|
||||
FlairTime().set(time);
|
||||
FlairCheater().set(cheater);
|
||||
FlairUpdate();
|
||||
}
|
||||
|
||||
|
@ -129,29 +103,29 @@ public class ChatPlayer extends TBMCPlayer {
|
|||
|
||||
// Flairs from Command Block The Button - Teams
|
||||
// PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add()
|
||||
Player p = Bukkit.getPlayer(getUuid());
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
if (p != null)
|
||||
p.setPlayerListName(String.format("%s%s", p.getName(), GetFormattedFlair()));
|
||||
}
|
||||
|
||||
public short GetFlairColor() {
|
||||
if (getFlairCheater())
|
||||
if (FlairCheater().get())
|
||||
return 0x5;
|
||||
if (getFlairTime() == -1)
|
||||
if (FlairTime().get() == -1)
|
||||
return 0x7;
|
||||
else if (getFlairTime() == -2)
|
||||
else if (FlairTime().get() == -2)
|
||||
return 0xf;
|
||||
else if (getFlairTime() <= 60 && getFlairTime() >= 52)
|
||||
else if (FlairTime().get() <= 60 && FlairTime().get() >= 52)
|
||||
return 0x5;
|
||||
else if (getFlairTime() <= 51 && getFlairTime() >= 42)
|
||||
else if (FlairTime().get() <= 51 && FlairTime().get() >= 42)
|
||||
return 0x9;
|
||||
else if (getFlairTime() <= 41 && getFlairTime() >= 32)
|
||||
else if (FlairTime().get() <= 41 && FlairTime().get() >= 32)
|
||||
return 0xa;
|
||||
else if (getFlairTime() <= 31 && getFlairTime() >= 22)
|
||||
else if (FlairTime().get() <= 31 && FlairTime().get() >= 22)
|
||||
return 0xe;
|
||||
else if (getFlairTime() <= 21 && getFlairTime() >= 11)
|
||||
else if (FlairTime().get() <= 21 && FlairTime().get() >= 11)
|
||||
return 0x6;
|
||||
else if (getFlairTime() <= 11 && getFlairTime() >= 0)
|
||||
else if (FlairTime().get() <= 11 && FlairTime().get() >= 0)
|
||||
return 0xc;
|
||||
return 0xf;
|
||||
}
|
||||
|
|
|
@ -22,9 +22,10 @@ import buttondevteam.chat.commands.UnlolCommand;
|
|||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.formatting.*;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.lib.chat.*;
|
||||
|
||||
|
@ -44,6 +45,7 @@ public class ChatProcessing {
|
|||
private static boolean pingedconsole = false;
|
||||
|
||||
private static ArrayList<ChatFormatter> commonFormatters = new ArrayList<>();
|
||||
private static Gson gson;
|
||||
|
||||
public static final ChatFormatter ESCAPE_FORMATTER = new ChatFormatterBuilder().setRegex(ESCAPE_PATTERN).build();
|
||||
|
||||
|
@ -51,16 +53,15 @@ public class ChatProcessing {
|
|||
}
|
||||
|
||||
static {
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setFormat(Format.Bold)
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setBold(true)
|
||||
.setRemoveCharCount((short) 2).setRange(true).build());
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setFormat(Format.Italic)
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setItalic(true)
|
||||
.setRemoveCharCount((short) 1).setRange(true).build());
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setFormat(Format.Underlined)
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setUnderlined(true)
|
||||
.setRemoveCharCount((short) 1).setRange(true).build());
|
||||
commonFormatters.add(ESCAPE_FORMATTER);
|
||||
// URLs + Rainbow text
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(Format.Underlined)
|
||||
.setOpenlink("$1").setRange(true).build());
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setUnderlined(true).setOpenlink("$1")
|
||||
.setRange(true).build());
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(NULL_MENTION_PATTERN).setColor(Color.DarkRed).build()); // Properly added a bug as a feature
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(Color.Aqua)
|
||||
.setOnmatch((String match) -> {
|
||||
|
@ -74,6 +75,11 @@ public class ChatProcessing {
|
|||
commonFormatters.add(new ChatFormatterBuilder().setRegex(HASHTAG_PATTERN).setColor(Color.Blue)
|
||||
.setOpenlink("https://twitter.com/hashtag/$1").setPriority(Priority.High).build());
|
||||
commonFormatters.add(new ChatFormatterBuilder().setRegex(CYAN_PATTERN).setColor(Color.Aqua).build()); // #55
|
||||
gson = new GsonBuilder()
|
||||
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
||||
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
||||
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
||||
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
||||
}
|
||||
|
||||
// Returns e.setCancelled for custom event
|
||||
|
@ -86,32 +92,13 @@ 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);
|
||||
doFunStuff(sender, message);
|
||||
|
||||
ChatPlayer mp = null;
|
||||
if (player != null)
|
||||
mp = TBMCPlayer.getPlayer(player).asPluginPlayer(ChatPlayer.class);
|
||||
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
|
||||
String msg = message.toLowerCase();
|
||||
if (msg.contains("lol")) {
|
||||
UnlolCommand.Lastlolornot = true;
|
||||
UnlolCommand.Lastlol = sender;
|
||||
} else {
|
||||
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
||||
if (msg.contains(PlayerListener.LaughStrings[i])) {
|
||||
UnlolCommand.Lastlol = sender;
|
||||
UnlolCommand.Lastlolornot = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Channel currentchannel = channel;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
|
||||
|
||||
Color colormode = currentchannel.color;
|
||||
Color colormode = channel.color;
|
||||
if (mp != null && mp.OtherColorMode != null)
|
||||
colormode = mp.OtherColorMode;
|
||||
if (mp != null && mp.RainbowPresserColorMode)
|
||||
|
@ -120,150 +107,22 @@ public class ChatProcessing {
|
|||
colormode = Color.Green;
|
||||
// If greentext, ignore channel or player colors
|
||||
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(ENTIRE_MESSAGE_PATTERN).setColor(colormode)
|
||||
.setPriority(Priority.Low).build());
|
||||
|
||||
String formattedmessage = message;
|
||||
|
||||
String suggestmsg = formattedmessage;
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
StringBuilder namesb = new StringBuilder();
|
||||
namesb.append("(?i)(");
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
namesb.append(p.getName()).append("|");
|
||||
namesb.deleteCharAt(namesb.length() - 1);
|
||||
namesb.append(")");
|
||||
StringBuilder nicksb = new StringBuilder();
|
||||
nicksb.append("(?i)(");
|
||||
boolean addNickFormatter = false;
|
||||
{
|
||||
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("|");
|
||||
addNickFormatter = true;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
nicksb.append(")");
|
||||
}
|
||||
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())).setColor(Color.Aqua)
|
||||
.setOnmatch((String match) -> {
|
||||
Player p = Bukkit.getPlayer(match);
|
||||
if (p == null) {
|
||||
PluginMain.Instance.getLogger()
|
||||
.warning("Error: Can't find player " + match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
ChatPlayer mpp = TBMCPlayer.getPlayer(p).asPluginPlayer(ChatPlayer.class);
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
||||
return color + p.getName() + "§r";
|
||||
}).setPriority(Priority.High).build());
|
||||
|
||||
if (addNickFormatter)
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString()))
|
||||
.setColor(Color.Aqua).setOnmatch((String match) -> {
|
||||
if (PlayerListener.nicknames.containsKey(match)) {
|
||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
||||
if (p == null) {
|
||||
PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
|
||||
+ match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
return PluginMain.essentials.getUser(p).getNickname();
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
ArrayList<ChatFormatter> formatters = addFormatters(colormode);
|
||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||
final String channelidentifier = getChannelID(channel, sender, mp);
|
||||
|
||||
TellrawPart json = new TellrawPart("");
|
||||
if (mp != null && mp.ChatOnly) {
|
||||
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(channelidentifier)
|
||||
.setHoverEvent(
|
||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
||||
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
||||
+ "Copy message").setColor(Color.Blue)))
|
||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
|
||||
TellrawEvent.ClickAction.SUGGEST_COMMAND, suggestmsg)));
|
||||
json.addExtra(new TellrawPart(" <"));
|
||||
json.addExtra(
|
||||
new TellrawPart(
|
||||
(player != null ? player.getDisplayName() : sender.getName()))
|
||||
.setHoverEvent(
|
||||
TellrawEvent
|
||||
.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
||||
new TellrawPart("")
|
||||
.addExtra(new TellrawPart(String.format("Flair: %s",
|
||||
(mp != null ? mp.GetFormattedFlair() : "-"))))
|
||||
.addExtra(new TellrawPart(
|
||||
String.format("\nPlayername: %s\n",
|
||||
(player != null ? player.getName()
|
||||
: sender.getName())))
|
||||
.setColor(Color.Aqua))
|
||||
.addExtra(new TellrawPart(String.format("World: %s\n",
|
||||
(player != null ? player.getWorld().getName()
|
||||
: "-"))))
|
||||
.addExtra(
|
||||
new TellrawPart(String.format("Respect: %s%s%s",
|
||||
(mp != null ? (mp.getFCount()
|
||||
/ (double) mp.getFDeaths())
|
||||
: "Infinite"),
|
||||
(mp != null && mp.getUserName() != null
|
||||
&& !mp.getUserName().isEmpty()
|
||||
? "\nUserName: "
|
||||
+ mp.getUserName()
|
||||
: ""),
|
||||
(mp != null && mp.getPlayerName()
|
||||
.equals("\nAlpha_Bacca44")
|
||||
? "\nDeaths: "
|
||||
+ PlayerListener.AlphaDeaths
|
||||
: ""))))
|
||||
.addExtra(new TellrawPart("\nFor more, do /u info "
|
||||
+ sender.getName())))));
|
||||
json.addExtra(new TellrawPart("> "));
|
||||
TellrawPart json = createTellraw(sender, message, player, mp, channelidentifier);
|
||||
long combinetime = System.nanoTime();
|
||||
ChatFormatter.Combine(formatters, formattedmessage, json);
|
||||
ChatFormatter.Combine(formatters, message, json);
|
||||
combinetime = System.nanoTime() - combinetime;
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
||||
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
||||
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
||||
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
||||
String jsonstr = gson.toJson(json);
|
||||
String jsonstr = toJson(json);
|
||||
if (jsonstr.length() >= 32767) {
|
||||
sender.sendMessage(
|
||||
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
||||
return true;
|
||||
}
|
||||
DebugCommand.SendDebugMessage(jsonstr);
|
||||
if (currentchannel.equals(Channel.TownChat) || currentchannel.equals(Channel.NationChat)) {
|
||||
if (channel.equals(Channel.TownChat) || channel.equals(Channel.NationChat)) {
|
||||
if (player == null) {
|
||||
sender.sendMessage("§cYou are not a player!");
|
||||
return true;
|
||||
|
@ -274,13 +133,13 @@ public class ChatProcessing {
|
|||
if (resident != null && !resident.getName().equals(player.getName())
|
||||
&& resident.getModes().contains("spy"))
|
||||
Bukkit.getPlayer(resident.getName()).sendMessage(String.format("[SPY-%s] - %s: %s",
|
||||
currentchannel.DisplayName, player.getDisplayName(), message));
|
||||
channel.DisplayName, player.getDisplayName(), message));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (currentchannel.equals(Channel.TownChat)) {
|
||||
if (channel.equals(Channel.TownChat)) {
|
||||
Town town = null;
|
||||
try {
|
||||
final Resident resident = PluginMain.Instance.TU.getResidentMap()
|
||||
|
@ -311,7 +170,7 @@ public class ChatProcessing {
|
|||
}
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
String.format("tellraw @a[score_town=%d,score_town_min=%d] %s", index, index, jsonstr));
|
||||
} else if (currentchannel.equals(Channel.NationChat)) {
|
||||
} else if (channel.equals(Channel.NationChat)) {
|
||||
Town town = null;
|
||||
try {
|
||||
final Resident resident = PluginMain.Instance.TU.getResidentMap()
|
||||
|
@ -350,7 +209,7 @@ public class ChatProcessing {
|
|||
}
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
String.format("tellraw @a[score_nation=%d,score_nation_min=%d] %s", index, index, jsonstr));
|
||||
} else if (currentchannel.equals(Channel.AdminChat)) {
|
||||
} else if (channel.equals(Channel.AdminChat)) {
|
||||
if (player != null && !player.isOp()) {
|
||||
player.sendMessage("§cYou need to be an OP to use this channel.");
|
||||
return true;
|
||||
|
@ -364,7 +223,7 @@ public class ChatProcessing {
|
|||
}
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
String.format("tellraw @a[score_admin=%d,score_admin_min=%d] %s", 1, 1, jsonstr));
|
||||
} else if (currentchannel.equals(Channel.ModChat)) {
|
||||
} else if (channel.equals(Channel.ModChat)) {
|
||||
if (player != null && !PluginMain.permission.playerInGroup(player, "mod")) {
|
||||
player.sendMessage("§cYou need to be a mod to use this channel.");
|
||||
return true;
|
||||
|
@ -393,4 +252,161 @@ public class ChatProcessing {
|
|||
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
||||
return false;
|
||||
}
|
||||
|
||||
static String toJson(TellrawPart json) {
|
||||
String jsonstr = gson.toJson(json);
|
||||
return jsonstr;
|
||||
}
|
||||
|
||||
static TellrawPart createTellraw(CommandSender sender, String message, Player player, ChatPlayer mp,
|
||||
final String channelidentifier) {
|
||||
TellrawPart json = new TellrawPart("");
|
||||
if (mp != null && mp.ChatOnly) {
|
||||
json.addExtra(new TellrawPart("[C]").setHoverEvent(
|
||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
||||
}
|
||||
json.addExtra(
|
||||
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)))
|
||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
|
||||
TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
||||
json.addExtra(new TellrawPart(" <"));
|
||||
json.addExtra(
|
||||
new TellrawPart(
|
||||
(player != null ? player.getDisplayName() : sender.getName()))
|
||||
.setHoverEvent(
|
||||
TellrawEvent
|
||||
.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
||||
new TellrawPart("")
|
||||
.addExtra(new TellrawPart(String.format("Flair: %s",
|
||||
(mp != null ? mp.GetFormattedFlair() : "-"))))
|
||||
.addExtra(new TellrawPart(
|
||||
String.format("\nPlayername: %s\n",
|
||||
(player != null ? player.getName()
|
||||
: sender.getName())))
|
||||
.setColor(Color.Aqua))
|
||||
.addExtra(new TellrawPart(String.format("World: %s\n",
|
||||
(player != null ? player.getWorld().getName()
|
||||
: "-"))))
|
||||
.addExtra(new TellrawPart(String.format(
|
||||
"Respect: %s%s%s",
|
||||
(mp != null ? (mp.FCount().getOrDefault(0)
|
||||
/ (double) mp.FDeaths().getOrDefault(0))
|
||||
: "Infinite"),
|
||||
(mp != null && mp.UserName().get() != null
|
||||
&& !mp.UserName().get().isEmpty()
|
||||
? "\nUserName: "
|
||||
+ mp.UserName().get()
|
||||
: ""),
|
||||
(mp != null && mp.PlayerName().get()
|
||||
.equals("\nAlpha_Bacca44")
|
||||
? "\nDeaths: "
|
||||
+ PlayerListener.AlphaDeaths
|
||||
: ""))))
|
||||
.addExtra(new TellrawPart("\nFor more, do /u info "
|
||||
+ sender.getName())))));
|
||||
json.addExtra(new TellrawPart("> "));
|
||||
return json;
|
||||
}
|
||||
|
||||
static String getChannelID(Channel channel, CommandSender sender, ChatPlayer mp) {
|
||||
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + channel.DisplayName)
|
||||
+ "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
|
||||
return channelidentifier;
|
||||
}
|
||||
|
||||
static ArrayList<ChatFormatter> addFormatters(Color colormode) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
|
||||
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(ENTIRE_MESSAGE_PATTERN).setColor(colormode)
|
||||
.setPriority(Priority.Low).build());
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
StringBuilder namesb = new StringBuilder("(?i)(");
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
namesb.append(p.getName()).append("|");
|
||||
namesb.deleteCharAt(namesb.length() - 1);
|
||||
namesb.append(")");
|
||||
StringBuilder nicksb = new StringBuilder("(?i)(");
|
||||
boolean addNickFormatter = false;
|
||||
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("|");
|
||||
addNickFormatter = true;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
nicksb.append(")");
|
||||
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())).setColor(Color.Aqua)
|
||||
.setOnmatch((String match) -> {
|
||||
Player p = Bukkit.getPlayer(match);
|
||||
if (p == null) {
|
||||
PluginMain.Instance.getLogger()
|
||||
.warning("Error: Can't find player " + match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
ChatPlayer mpp = TBMCPlayer.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
||||
return color + p.getName() + "§r";
|
||||
}).setPriority(Priority.High).build());
|
||||
|
||||
if (addNickFormatter)
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString()))
|
||||
.setColor(Color.Aqua).setOnmatch((String match) -> {
|
||||
if (PlayerListener.nicknames.containsKey(match)) {
|
||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
||||
if (p == null) {
|
||||
PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
|
||||
+ match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
return PluginMain.essentials.getUser(p).getNickname();
|
||||
}
|
||||
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());
|
||||
}
|
||||
return formatters;
|
||||
}
|
||||
|
||||
static void doFunStuff(CommandSender sender, String message) {
|
||||
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
||||
PlayerListener.Fs.add(sender);
|
||||
|
||||
String msg = message.toLowerCase();
|
||||
if (msg.contains("lol")) {
|
||||
UnlolCommand.Lastlolornot = true;
|
||||
UnlolCommand.Lastlol = sender;
|
||||
} else {
|
||||
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
||||
if (msg.contains(PlayerListener.LaughStrings[i])) {
|
||||
UnlolCommand.Lastlol = sender;
|
||||
UnlolCommand.Lastlolornot = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import org.htmlcleaner.TagNode;
|
|||
import buttondevteam.chat.commands.YeehawCommand;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.google.gson.JsonArray;
|
||||
|
@ -57,7 +57,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
* This variable is used as a cache for flair state checking when reading the flair thread.
|
||||
* </p>
|
||||
* <p>
|
||||
* It's used because normally it has to load all associated player files every time to read the filename
|
||||
* It's used because normally it has to load all associated player files every time to read the flair state
|
||||
* </p>
|
||||
*/
|
||||
private Set<String> PlayersWithFlairs = new HashSet<>();
|
||||
|
@ -139,16 +139,16 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
ign = ign.trim();
|
||||
if (PlayersWithFlairs.contains(ign))
|
||||
continue;
|
||||
try (ChatPlayer mp = TBMCPlayer.getFromName(ign).asPluginPlayer(ChatPlayer.class)) { // Loads player file
|
||||
try (ChatPlayer mp = TBMCPlayerBase.getFromName(ign, ChatPlayer.class)) { // Loads player file
|
||||
if (mp == null)
|
||||
continue;
|
||||
/*
|
||||
* if (!JoinedBefore(mp, 2015, 6, 5)) continue;
|
||||
*/
|
||||
if (!mp.getUserNames().contains(author))
|
||||
mp.getUserNames().add(author);
|
||||
if (mp.getFlairState().equals(FlairStates.NoComment)) {
|
||||
mp.setFlairState(FlairStates.Commented);
|
||||
if (!mp.UserNames().contains(author))
|
||||
mp.UserNames().add(author);
|
||||
if (mp.FlairState().getOrDefault(FlairStates.NoComment).equals(FlairStates.NoComment)) {
|
||||
mp.FlairState().set(FlairStates.Commented);
|
||||
ConfirmUserMessage(mp);
|
||||
}
|
||||
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
|
||||
|
@ -176,8 +176,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
|
||||
public void DownloadFlair(ChatPlayer mp) throws MalformedURLException, IOException {
|
||||
String[] flairdata = TBMCCoreAPI
|
||||
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.getUserName()).replace("\"", "")
|
||||
.split(":");
|
||||
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get())
|
||||
.replace("\"", "").split(":");
|
||||
String flair;
|
||||
if (flairdata.length > 1)
|
||||
flair = flairdata[1];
|
||||
|
@ -188,12 +188,12 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass = "unknown";
|
||||
SetFlair(mp, flair, flairclass, mp.getUserName());
|
||||
SetFlair(mp, flair, flairclass, mp.UserName().get());
|
||||
}
|
||||
|
||||
private void SetFlair(ChatPlayer p, String text, String flairclass, String username) {
|
||||
p.setUserName(username);
|
||||
p.setFlairState(FlairStates.Recognised);
|
||||
p.UserName().set(username);
|
||||
p.FlairState().set(FlairStates.Recognised);
|
||||
switch (flairclass) {
|
||||
case "cheater":
|
||||
p.SetFlair(Short.parseShort(text), true);
|
||||
|
@ -209,9 +209,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
p.SetFlair(ChatPlayer.FlairTimeCantPress);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
p.setFlairState(FlairStates.Commented); // Flair unknown
|
||||
p.FlairState().set(FlairStates.Commented); // Flair unknown
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
TBMCCoreAPI.SendException("Error while checking join date for player " + p.getPlayerName() + "!", e);
|
||||
TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName() + "!", e);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
|
@ -225,7 +225,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
}
|
||||
|
||||
public static boolean JoinedBefore(ChatPlayer mp, int year, int month, int day) throws Exception {
|
||||
URL url = new URL("https://www.reddit.com/u/" + mp.getUserName());
|
||||
URL url = new URL("https://www.reddit.com/u/" + mp.UserName());
|
||||
URLConnection con = url.openConnection();
|
||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||
InputStream in = con.getInputStream();
|
||||
|
@ -243,9 +243,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
}
|
||||
|
||||
public static void ConfirmUserMessage(ChatPlayer mp) {
|
||||
Player p = Bukkit.getPlayer(mp.getUuid());
|
||||
if (mp.getFlairState().equals(FlairStates.Commented) && p != null)
|
||||
if (mp.getUserNames().size() > 1)
|
||||
Player p = Bukkit.getPlayer(mp.getUUID());
|
||||
if (mp.FlairState().get().equals(FlairStates.Commented) && p != null)
|
||||
if (mp.UserNames().size() > 1)
|
||||
p.sendMessage(
|
||||
"§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r");
|
||||
else
|
||||
|
|
|
@ -5,8 +5,8 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
public final class ChatonlyCommand extends TBMCCommandBase {
|
||||
|
||||
|
@ -22,7 +22,7 @@ public final class ChatonlyCommand extends TBMCCommandBase {
|
|||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
p.ChatOnly = true;
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.sendMessage("§bChat-only mode enabled. You are now invincible.");
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
public final class OOCCommand extends TBMCCommandBase {
|
||||
|
||||
|
@ -22,7 +22,7 @@ public final class OOCCommand extends TBMCCommandBase {
|
|||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
final ChatPlayer cp = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
|
||||
final ChatPlayer cp = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
cp.RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
public class WaitWhatCommand extends TBMCCommandBase {
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
Channel channel;
|
||||
if (sender instanceof Player && ((Player) sender).isOnline())
|
||||
channel = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel;
|
||||
else
|
||||
channel = Channel.GlobalChat;
|
||||
final String message;
|
||||
if (args.length == 0)
|
||||
message = "wait what";
|
||||
else
|
||||
message = "wait " + Arrays.stream(args).collect(Collectors.joining(" ")) + " what";
|
||||
TBMCChatAPI.SendChatMessage(channel, sender, message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6--- Wait what ----", //
|
||||
"Wait what" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean GetPlayerOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean GetModOnly() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.lib.TBMCYEEHAWEvent;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCYEEHAWEvent;
|
||||
|
||||
public class YeehawCommand extends TBMCCommandBase {
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||
|
||||
|
@ -23,7 +23,8 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
|||
msg = args[i] + " " + msg;
|
||||
if (sender instanceof Player)
|
||||
TBMCChatAPI.SendChatMessage(
|
||||
TBMCPlayer.getPlayer((Player) sender).asPluginPlayer(ChatPlayer.class).CurrentChannel, sender, msg);
|
||||
TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel, sender,
|
||||
msg);
|
||||
else if (sender.isOp())
|
||||
TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, sender, msg);
|
||||
else
|
||||
|
|
|
@ -10,7 +10,7 @@ import buttondevteam.chat.FlairStates;
|
|||
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
public class AcceptCommand extends UCommandBase {
|
||||
|
||||
|
@ -25,21 +25,21 @@ public class AcceptCommand extends UCommandBase {
|
|||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
final Player player = (Player) sender;
|
||||
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
|
||||
if (args.length < 1 && p.getUserNames().size() > 1) {
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (args.length < 1 && p.UserNames().size() > 1) {
|
||||
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("§6Usernames:");
|
||||
for (String username : p.getUserNames())
|
||||
for (String username : p.UserNames())
|
||||
sb.append(" ").append(username);
|
||||
player.sendMessage(sb.toString());
|
||||
return true;
|
||||
}
|
||||
if (p.getFlairState().equals(FlairStates.NoComment) || p.getUserNames().size() == 0) {
|
||||
if (p.FlairState().get().equals(FlairStates.NoComment) || p.UserNames().size() == 0) {
|
||||
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/ChromaGamers§r");
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && !p.getUserNames().contains(args[0])) {
|
||||
if (args.length > 0 && !p.UserNames().contains(args[0])) {
|
||||
player.sendMessage("§cError: Unknown name: " + args[0] + "§r");
|
||||
return true;
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ public class AcceptCommand extends UCommandBase {
|
|||
return true;
|
||||
}
|
||||
|
||||
if ((args.length > 0 ? args[0] : p.getUserNames().get(0)).equals(p.getUserName())) {
|
||||
if ((args.length > 0 ? args[0] : p.UserNames().get(0)).equals(p.UserName().get())) {
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0)
|
||||
p.setUserName(args[0]);
|
||||
p.UserName().set(args[0]);
|
||||
else
|
||||
p.setUserName(p.getUserNames().get(0));
|
||||
p.UserName().set(p.UserNames().get(0));
|
||||
|
||||
player.sendMessage("§bObtaining flair...");
|
||||
p.Working = true;
|
||||
|
@ -74,14 +74,14 @@ public class AcceptCommand extends UCommandBase {
|
|||
return;
|
||||
}
|
||||
|
||||
if (mp.getFlairState().equals(FlairStates.Commented)) {
|
||||
if (mp.FlairState().get().equals(FlairStates.Commented)) {
|
||||
player.sendMessage(
|
||||
"Sorry, but your flair isn't recorded. Please ask an admin to set it for you. Also, prepare a comment on /r/thebutton, if possible.");
|
||||
mp.Working = false;
|
||||
return;
|
||||
}
|
||||
String flair = mp.GetFormattedFlair();
|
||||
mp.setFlairState(FlairStates.Accepted);
|
||||
mp.FlairState().set(FlairStates.Accepted);
|
||||
PluginMain.ConfirmUserMessage(mp);
|
||||
player.sendMessage("§bYour flair has been set:§r " + flair);
|
||||
mp.Working = false;
|
||||
|
|
|
@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.*;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
public class CCommand extends UCommandBase {
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class CCommand extends UCommandBase {
|
|||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (args.length < 1) {
|
||||
if (PluginMain.permission.has(player, "tbmc.rainbow")) {
|
||||
p.RainbowPresserColorMode = !p.RainbowPresserColorMode;
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.FlairStates;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
public final class IgnoreCommand extends UCommandBase {
|
||||
|
||||
|
@ -19,19 +19,19 @@ public final class IgnoreCommand extends UCommandBase {
|
|||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
final Player player = (Player) sender;
|
||||
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
|
||||
if (p.getFlairState().equals(FlairStates.Accepted)) {
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (p.FlairState().get().equals(FlairStates.Accepted)) {
|
||||
player.sendMessage("§cYou can only ignore the \"write your name in the thread\" message.");
|
||||
return true;
|
||||
}
|
||||
if (p.getFlairState().equals(FlairStates.Commented)) {
|
||||
if (p.FlairState().get().equals(FlairStates.Commented)) {
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||
return true;
|
||||
}
|
||||
if (!p.getFlairState().equals(FlairStates.Ignored)) {
|
||||
p.setFlairState(FlairStates.Ignored);
|
||||
if (!p.FlairState().get().equals(FlairStates.Ignored)) {
|
||||
p.FlairState().set(FlairStates.Ignored);
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
p.setUserName("");
|
||||
p.UserName().set("");
|
||||
player.sendMessage("§bYou have ignored the message.§r");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored the message.§r");
|
||||
|
|
|
@ -2,8 +2,10 @@ package buttondevteam.chat.commands.ucmds;
|
|||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.TBMCPlayer.InfoTarget;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
public class InfoCommand extends UCommandBase {
|
||||
|
||||
|
@ -12,7 +14,7 @@ public class InfoCommand extends UCommandBase {
|
|||
return new String[] { //
|
||||
"§6---- User information ----", //
|
||||
"Get some information known about the user.", //
|
||||
"Usage: /"+alias+" info <playername>" //
|
||||
"Usage: /" + alias + " info <playername>" //
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -27,15 +29,18 @@ public class InfoCommand extends UCommandBase {
|
|||
return false;
|
||||
if (args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("server")
|
||||
|| args[0].equalsIgnoreCase("@console")) {
|
||||
sender.sendMessage("The server console."); // TODO: Console login? The Discord thing might replace it
|
||||
sender.sendMessage("The server console.");
|
||||
return true;
|
||||
}
|
||||
try (TBMCPlayer p = TBMCPlayer.getFromName(args[0])) {
|
||||
try (TBMCPlayer p = TBMCPlayerBase.getFromName(args[0], TBMCPlayer.class)) {
|
||||
if (p == null) {
|
||||
sender.sendMessage("§cThe specified player cannot be found");
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(p.getInfo(InfoTarget.MCCommand));
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while getting player information!", e);
|
||||
sender.sendMessage("§cError while getting player information!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
|||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class DebugCommand extends AdminCommandBase {
|
||||
private static boolean DebugMode = false;
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
|
@ -20,13 +20,15 @@ public class DebugCommand extends AdminCommandBase {
|
|||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
sender.sendMessage("§eDebug mode "
|
||||
+ ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));
|
||||
sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SendDebugMessage(String message) {
|
||||
if (DebugMode)
|
||||
PluginMain.Instance.getLogger().info(message);
|
||||
if (PluginMain.Instance != null)
|
||||
PluginMain.Instance.getLogger().info(message);
|
||||
else
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package buttondevteam.chat.commands.ucmds.admin;
|
|||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
public class PlayerInfoCommand extends AdminCommandBase {
|
||||
|
||||
|
@ -19,23 +19,23 @@ public class PlayerInfoCommand extends AdminCommandBase {
|
|||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
ChatPlayer p = TBMCPlayer.getFromName(args[0]).asPluginPlayer(ChatPlayer.class);
|
||||
ChatPlayer p = TBMCPlayerBase.getFromName(args[0], ChatPlayer.class);
|
||||
if (p == null) {
|
||||
sender.sendMessage("§cPlayer not found: " + args[0] + "§r");
|
||||
return true;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("§6Usernames:");
|
||||
for (String username : p.getUserNames())
|
||||
for (String username : p.UserNames())
|
||||
sb.append(" ").append(username);
|
||||
sender.sendMessage(new String[] { //
|
||||
"Player name: " + p.getPlayerName(), //
|
||||
"Player name: " + p.PlayerName(), //
|
||||
"User flair: " + p.GetFormattedFlair(), //
|
||||
"Username: " + p.getUserName(), //
|
||||
"Flair state: " + p.getFlairState(), //
|
||||
"Username: " + p.UserName(), //
|
||||
"Flair state: " + p.FlairState(), //
|
||||
sb.toString(), //
|
||||
"FCount: " + p.getFCount(), //
|
||||
"FDeaths: " + p.getFDeaths() //
|
||||
"FCount: " + p.FCount(), //
|
||||
"FDeaths: " + p.FDeaths() //
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.FlairStates;
|
||||
import buttondevteam.lib.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
public class SetFlairCommand extends AdminCommandBase {
|
||||
|
||||
|
@ -53,18 +53,18 @@ public class SetFlairCommand extends AdminCommandBase {
|
|||
sender.sendMessage("§cUnknown value for cheater parameter. Run without args to see usage.");
|
||||
return true;
|
||||
}
|
||||
ChatPlayer mp = TBMCPlayer.getPlayerAs(p, ChatPlayer.class);
|
||||
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
||||
mp.SetFlair(flairtime, cheater);
|
||||
mp.setFlairState(FlairStates.Accepted);
|
||||
mp.FlairState().set(FlairStates.Accepted);
|
||||
if (args.length < 4)
|
||||
mp.setUserName("");
|
||||
mp.UserName().set("");
|
||||
else {
|
||||
mp.setUserName(args[3]);
|
||||
if (!mp.getUserNames().contains(args[3]))
|
||||
mp.getUserNames().add(args[3]);
|
||||
mp.UserName().set(args[3]);
|
||||
if (!mp.UserNames().contains(args[3]))
|
||||
mp.UserNames().add(args[3]);
|
||||
}
|
||||
sender.sendMessage(
|
||||
"§bThe flair has been set. Player: " + mp.getPlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
|
||||
"§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,11 @@ import buttondevteam.lib.chat.*;
|
|||
|
||||
public final class ChatFormatter {
|
||||
private Pattern regex;
|
||||
private Format format;
|
||||
private boolean italic;
|
||||
private boolean bold;
|
||||
private boolean underlined;
|
||||
private boolean strikethrough;
|
||||
private boolean obfuscated;
|
||||
private Color color;
|
||||
private Function<String, String> onmatch;
|
||||
private String openlink;
|
||||
|
@ -24,14 +28,23 @@ public final class ChatFormatter {
|
|||
private short removecharpos = -1;
|
||||
private boolean isrange;
|
||||
|
||||
public ChatFormatter(Pattern regex, Format format, Color color, Function<String, String> onmatch, String openlink,
|
||||
Priority priority, short removecharcount, short removecharpos, boolean isrange) {
|
||||
public ChatFormatter(Pattern regex, boolean italic, boolean bold, boolean underlined, boolean strikethrough,
|
||||
boolean obfuscated, Color color, Function<String, String> onmatch, String openlink, Priority priority,
|
||||
short removecharcount, short removecharpos, boolean isrange) {
|
||||
super();
|
||||
this.regex = regex;
|
||||
this.format = format;
|
||||
this.italic = italic;
|
||||
this.bold = bold;
|
||||
this.underlined = underlined;
|
||||
this.strikethrough = strikethrough;
|
||||
this.obfuscated = obfuscated;
|
||||
this.color = color;
|
||||
this.onmatch = onmatch;
|
||||
this.openlink = openlink;
|
||||
this.priority = Priority.High;
|
||||
if (priority == null)
|
||||
this.priority = Priority.Normal;
|
||||
else
|
||||
this.priority = priority;
|
||||
this.removecharcount = removecharcount;
|
||||
this.removecharpos = removecharpos;
|
||||
this.isrange = isrange;
|
||||
|
@ -67,6 +80,8 @@ public final class ChatFormatter {
|
|||
ArrayList<FormattedSection> combined = new ArrayList<>();
|
||||
Map<ChatFormatter, FormattedSection> nextSection = new HashMap<>();
|
||||
boolean escaped = false;
|
||||
int takenStart = -1, takenEnd = -1;
|
||||
ChatFormatter takenFormatter = null;
|
||||
for (int i = 0; i < sections.size(); i++) {
|
||||
// Set ending to -1 until closed with another 1 long "section" - only do this if IsRange is true
|
||||
final FormattedSection section = sections.get(i);
|
||||
|
@ -79,9 +94,22 @@ public final class ChatFormatter {
|
|||
continue;
|
||||
}
|
||||
if (!escaped) {
|
||||
if (section.Start >= takenStart && section.Start <= takenEnd) {
|
||||
if (section.RemCharFromStart <= takenEnd - takenStart) {
|
||||
System.out.println("Lose: " + section);
|
||||
System.out.println("And win: " + takenFormatter);
|
||||
continue; // The current section loses
|
||||
}
|
||||
nextSection.remove(takenFormatter); // The current section wins
|
||||
System.out.println("Win: " + section);
|
||||
System.out.println("And lose: " + takenFormatter);
|
||||
}
|
||||
takenStart = section.Start;
|
||||
takenEnd = section.Start + section.RemCharFromStart;
|
||||
takenFormatter = section.Formatters.get(0);
|
||||
if (nextSection.containsKey(section.Formatters.get(0))) {
|
||||
FormattedSection s = nextSection.remove(section.Formatters.get(0));
|
||||
s.End = section.Start;
|
||||
s.End = section.Start + section.RemCharFromStart - 1;
|
||||
s.IsRange = false; // IsRange means it's a 1 long section indicating a start or an end
|
||||
combined.add(s);
|
||||
DebugCommand.SendDebugMessage("Finished section: " + s);
|
||||
|
@ -89,6 +117,8 @@ public final class ChatFormatter {
|
|||
DebugCommand.SendDebugMessage("Adding next section: " + section);
|
||||
nextSection.put(section.Formatters.get(0), section);
|
||||
}
|
||||
DebugCommand
|
||||
.SendDebugMessage("New area taken: (" + takenStart + "-" + takenEnd + ") " + takenFormatter);
|
||||
} else {
|
||||
DebugCommand.SendDebugMessage("Skipping section: " + section);
|
||||
escaped = false; // Reset escaping if applied, like if we're at the '*' in '\*'
|
||||
|
@ -196,7 +226,7 @@ public final class ChatFormatter {
|
|||
originaltext = textsb.toString();
|
||||
DebugCommand.SendDebugMessage("Section text: " + originaltext);
|
||||
Color color = null;
|
||||
int format = 0;
|
||||
boolean bold = false, italic = false, underlined = false, strikethrough = false, obfuscated = false;
|
||||
String openlink = null;
|
||||
section.Formatters.sort((cf2, cf1) -> cf1.priority.compareTo(cf2.priority));
|
||||
for (ChatFormatter formatter : section.Formatters) {
|
||||
|
@ -205,8 +235,16 @@ public final class ChatFormatter {
|
|||
originaltext = formatter.onmatch.apply(originaltext);
|
||||
if (formatter.color != null)
|
||||
color = formatter.color;
|
||||
if (formatter.format != null)
|
||||
format = formatter.format.getFlag(); // TODO: Fix
|
||||
if (formatter.bold)
|
||||
bold = true;
|
||||
if (formatter.italic)
|
||||
italic = true;
|
||||
if (formatter.underlined)
|
||||
underlined = true;
|
||||
if (formatter.strikethrough)
|
||||
strikethrough = true;
|
||||
if (formatter.obfuscated)
|
||||
obfuscated = true;
|
||||
if (formatter.openlink != null)
|
||||
openlink = formatter.openlink;
|
||||
}
|
||||
|
@ -214,8 +252,11 @@ public final class ChatFormatter {
|
|||
newtp.setText(originaltext);
|
||||
if (color != null)
|
||||
newtp.setColor(color);
|
||||
if (format != 0)
|
||||
newtp.setFormat(format);
|
||||
newtp.setBold(bold);
|
||||
newtp.setItalic(italic);
|
||||
newtp.setUnderlined(underlined);
|
||||
newtp.setStrikethrough(strikethrough);
|
||||
newtp.setObfuscated(obfuscated);
|
||||
if (openlink != null && openlink.length() > 0) {
|
||||
newtp.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC, TellrawEvent.ClickAction.OPEN_URL,
|
||||
(section.Matches.size() > 0 ? openlink.replace("$1", section.Matches.get(0)) : openlink)))
|
||||
|
@ -228,7 +269,10 @@ public final class ChatFormatter {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("F(").append(color).append(", ").append(format).append(", ").append(openlink)
|
||||
.append(", ").append(priority).append(", ").append(regex).append(")").toString();
|
||||
return new StringBuilder("F(").append(color).append(", ")
|
||||
.append((bold ? "bold" : "") + (italic ? "italic" : "") + (underlined ? "underlined" : "")
|
||||
+ (strikethrough ? "strikethrough" : "") + (obfuscated ? "obfuscated" : ""))
|
||||
.append(", ").append(openlink).append(", ").append(priority).append(", ").append(regex).append(")")
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,11 @@ import buttondevteam.lib.chat.*;
|
|||
|
||||
public class ChatFormatterBuilder {
|
||||
private Pattern regex;
|
||||
private Format format;
|
||||
private boolean italic;
|
||||
private boolean bold;
|
||||
private boolean underlined;
|
||||
private boolean strikethrough;
|
||||
private boolean obfuscated;
|
||||
private Color color;
|
||||
private Function<String, String> onmatch;
|
||||
private String openlink;
|
||||
|
@ -17,8 +21,8 @@ public class ChatFormatterBuilder {
|
|||
private boolean range = false;
|
||||
|
||||
public ChatFormatter build() {
|
||||
return new ChatFormatter(regex, format, color, onmatch, openlink, priority, removecharcount, removecharpos,
|
||||
range);
|
||||
return new ChatFormatter(regex, italic, bold, underlined, strikethrough, obfuscated, color, onmatch, openlink,
|
||||
priority, removecharcount, removecharpos, range);
|
||||
}
|
||||
|
||||
public Pattern getRegex() {
|
||||
|
@ -30,12 +34,48 @@ public class ChatFormatterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Format getFormat() {
|
||||
return format;
|
||||
public boolean isItalic() {
|
||||
return italic;
|
||||
}
|
||||
|
||||
public ChatFormatterBuilder setFormat(Format format) {
|
||||
this.format = format;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ class FormattedSection {
|
|||
short RemCharFromStart;
|
||||
short RemCharFromEnd;
|
||||
ArrayList<Integer> RemCharPos = new ArrayList<Integer>();
|
||||
/**
|
||||
* Is it a 1-long section indicating a start or an end
|
||||
*/
|
||||
boolean IsRange;
|
||||
|
||||
FormattedSection(ChatFormatter formatter, int start, int end, ArrayList<String> matches, short remcharfromstart,
|
||||
|
|
|
@ -6,11 +6,9 @@ import java.util.List;
|
|||
|
||||
import buttondevteam.lib.chat.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class TellrawPart implements Serializable {
|
||||
private static final long serialVersionUID = 4125357644462144024L;
|
||||
private Color color;
|
||||
private transient int format;
|
||||
private boolean italic;
|
||||
private boolean bold;
|
||||
private boolean underlined;
|
||||
|
@ -34,29 +32,48 @@ public final class TellrawPart implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public int getFormat() {
|
||||
return format;
|
||||
public boolean isItalic() {
|
||||
return italic;
|
||||
}
|
||||
|
||||
public TellrawPart setFormat(int format) {
|
||||
this.format = format;
|
||||
this.italic = false;
|
||||
this.bold = false;
|
||||
this.underlined = false;
|
||||
this.strikethrough = false;
|
||||
this.obfuscated = false;
|
||||
if ((format & Format.Italic.getFlag()) != 0)
|
||||
this.italic = true;
|
||||
else if ((format & Format.Bold.getFlag()) != 0)
|
||||
this.bold = true;
|
||||
else if ((format & Format.Underlined.getFlag()) != 0)
|
||||
this.underlined = true;
|
||||
else if ((format & Format.Strikethrough.getFlag()) != 0)
|
||||
this.strikethrough = true;
|
||||
else if ((format & Format.Obfuscated.getFlag()) != 0)
|
||||
this.obfuscated = true;
|
||||
else
|
||||
throw new UnsupportedOperationException("Trying to set to an unknown format!");
|
||||
public TellrawPart setItalic(boolean italic) {
|
||||
this.italic = italic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isBold() {
|
||||
return bold;
|
||||
}
|
||||
|
||||
public TellrawPart setBold(boolean bold) {
|
||||
this.bold = bold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isUnderlined() {
|
||||
return underlined;
|
||||
}
|
||||
|
||||
public TellrawPart setUnderlined(boolean underlined) {
|
||||
this.underlined = underlined;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isStrikethrough() {
|
||||
return strikethrough;
|
||||
}
|
||||
|
||||
public TellrawPart setStrikethrough(boolean strikethrough) {
|
||||
this.strikethrough = strikethrough;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isObfuscated() {
|
||||
return obfuscated;
|
||||
}
|
||||
|
||||
public TellrawPart setObfuscated(boolean obfuscated) {
|
||||
this.obfuscated = obfuscated;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package buttondevteam.chat.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Timer;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -17,10 +16,9 @@ import buttondevteam.chat.ChatPlayer;
|
|||
import buttondevteam.chat.FlairStates;
|
||||
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCPlayerAddEvent;
|
||||
import buttondevteam.lib.TBMCPlayerJoinEvent;
|
||||
import buttondevteam.lib.TBMCPlayerLoadEvent;
|
||||
import buttondevteam.lib.TBMCPlayerSaveEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
|
||||
|
||||
public class PlayerJoinLeaveListener implements Listener {
|
||||
|
||||
|
@ -35,9 +33,9 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
if (PluginMain.essentials == null)
|
||||
PluginMain.essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
|
||||
Player p = Bukkit.getPlayer(cp.getUuid());
|
||||
Player p = Bukkit.getPlayer(cp.getUUID());
|
||||
|
||||
if (!cp.getFlairState().equals(FlairStates.NoComment)) {
|
||||
if (!cp.FlairState().get().equals(FlairStates.NoComment)) {
|
||||
PluginMain.ConfirmUserMessage(cp);
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
|
@ -49,26 +47,26 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
tt.mp = cp;
|
||||
timer.schedule(tt, 1000);
|
||||
} else {
|
||||
if (cp.getFlairTime() == 0x00)
|
||||
if (cp.FlairTime().get() == 0x00)
|
||||
cp.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Player player = Bukkit.getPlayer(mp.getPlayerName());
|
||||
Player player = Bukkit.getPlayer(mp.PlayerName().get());
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (mp.getFlairState().equals(FlairStates.NoComment)) {
|
||||
if (mp.FlairState().get().equals(FlairStates.NoComment)) {
|
||||
String json = String.format(
|
||||
"[\"\",{\"text\":\"If you're from Reddit and you'd like your /r/TheButton flair displayed ingame, write your Minecraft name to \",\"color\":\"aqua\"},{\"text\":\"[this thread].\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]",
|
||||
PluginMain.FlairThreadURL);
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
"tellraw " + mp.getPlayerName() + " " + json);
|
||||
"tellraw " + mp.PlayerName() + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you aren't from Reddit or don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
"tellraw " + mp.getPlayerName() + " " + json);
|
||||
"tellraw " + mp.PlayerName() + " " + json);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -101,14 +99,6 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
public void onPlayerSave(TBMCPlayerSaveEvent e) {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerAdd(TBMCPlayerAddEvent event) {
|
||||
ChatPlayer cp = event.GetPlayer().asPluginPlayer(ChatPlayer.class);
|
||||
cp.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
cp.setFlairState(FlairStates.NoComment);
|
||||
cp.setUserNames(new ArrayList<>());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
|
|
|
@ -31,11 +31,12 @@ 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;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.TBMCPlayerGetInfoEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
|
@ -70,7 +71,7 @@ public class PlayerListener implements Listener {
|
|||
if (event.isCancelled())
|
||||
return;
|
||||
TBMCChatAPI.SendChatMessage(
|
||||
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
|
||||
TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class).CurrentChannel,
|
||||
event.getPlayer(), event.getMessage());
|
||||
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
||||
}
|
||||
|
@ -80,7 +81,7 @@ public class PlayerListener implements Listener {
|
|||
if (event.getMessage().length() < 2)
|
||||
return;
|
||||
int index = event.getMessage().indexOf(" ");
|
||||
ChatPlayer mp = TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class);
|
||||
ChatPlayer mp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class);
|
||||
String cmd = "";
|
||||
if (index == -1) {
|
||||
cmd = event.getMessage().substring(1);
|
||||
|
@ -211,8 +212,8 @@ public class PlayerListener implements Listener {
|
|||
Ftimer.cancel();
|
||||
ActiveF = true;
|
||||
Fs.clear();
|
||||
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId()).asPluginPlayer(ChatPlayer.class);
|
||||
FPlayer.setFDeaths(FPlayer.getFDeaths() + 1);
|
||||
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class);
|
||||
FPlayer.FDeaths().set(FPlayer.FDeaths().get() + 1);
|
||||
Bukkit.broadcastMessage("§bPress F to pay respects.§r");
|
||||
Ftimer = new Timer();
|
||||
TimerTask tt = new TimerTask() {
|
||||
|
@ -220,8 +221,8 @@ public class PlayerListener implements Listener {
|
|||
public void run() {
|
||||
if (ActiveF) {
|
||||
ActiveF = false;
|
||||
if (FPlayer != null && FPlayer.getFCount() < Integer.MAX_VALUE - 1)
|
||||
FPlayer.setFCount(FPlayer.getFCount() + Fs.size());
|
||||
if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1)
|
||||
FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size());
|
||||
Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
Fs.clear();
|
||||
|
@ -249,14 +250,14 @@ public class PlayerListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
ChatPlayer mp = TBMCPlayer.getPlayerAs(e.getPlayer(), ChatPlayer.class);
|
||||
ChatPlayer mp = TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class);
|
||||
if (mp.ChatOnly)
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
||||
if (TBMCPlayer.getPlayerAs(e.getPlayer(), ChatPlayer.class).ChatOnly) {
|
||||
if (TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class).ChatOnly) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode.");
|
||||
}
|
||||
|
@ -318,19 +319,26 @@ public class PlayerListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
|
||||
ChatPlayer cp = e.getPlayer().asPluginPlayer(ChatPlayer.class);
|
||||
e.addInfo("Minecraft name: " + cp.getPlayerName());
|
||||
if (cp.getUserName() != null && cp.getUserName().length() > 0)
|
||||
e.addInfo("Reddit name: " + cp.getUserName());
|
||||
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
|
||||
if (flair.length() > 0)
|
||||
e.addInfo("/r/TheButton flair: " + flair);
|
||||
e.addInfo("Respect: " + (double) cp.getFCount() / (double) cp.getFDeaths());
|
||||
try (ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class)) {
|
||||
if (cp == null)
|
||||
return;
|
||||
e.addInfo("Minecraft name: " + cp.PlayerName().get());
|
||||
if (cp.UserName().get() != null && cp.UserName().get().length() > 0)
|
||||
e.addInfo("Reddit name: " + cp.UserName().get());
|
||||
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
|
||||
if (flair.length() > 0)
|
||||
e.addInfo("/r/TheButton flair: " + flair);
|
||||
e.addInfo("Respect: " + (double) cp.FCount().getOrDefault(0) / (double) cp.FDeaths().getOrDefault(0));
|
||||
} catch (Exception ex) {
|
||||
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTBMCChat(TBMCChatEvent e) {
|
||||
try {
|
||||
if (e.isCancelled())
|
||||
return;
|
||||
e.setCancelled(ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage()));
|
||||
} catch (Exception ex) {
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
|
@ -339,7 +347,6 @@ public class PlayerListener implements Listener {
|
|||
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
|
||||
+ "> " + e.getMessage());
|
||||
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ commands:
|
|||
description: Shrug.
|
||||
yeehaw:
|
||||
description: This command makes you yeehaw.
|
||||
waitwhat:
|
||||
description: Wait what.
|
||||
aliases: ww
|
||||
author: NorbiPeti
|
||||
depend:
|
||||
- Essentials
|
||||
|
|
44
src/test/java/buttondevteam/chat/ChatFormatTest.java
Normal file
44
src/test/java/buttondevteam/chat/ChatFormatTest.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.formatting.ChatFormatter;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.core.TestPrepare;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ChatFormatTest extends TestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
TestPrepare.PrepareServer();
|
||||
final CommandSender sender = Mockito.mock(CommandSender.class);
|
||||
DebugCommand.DebugMode = true;
|
||||
testMessage(sender, "*test*", new TellrawPart("test").setItalic(true).setColor(Color.White));
|
||||
testMessage(sender, "**test**", new TellrawPart("test").setBold(true).setColor(Color.White));
|
||||
/*testMessage(sender, "***test***", new TellrawPart("test").setBold(true).setItalic(true).setColor(Color.White));
|
||||
testMessage(sender, "***_test_***",
|
||||
new TellrawPart("test").setBold(true).setItalic(true).setUnderlined(true).setColor(Color.White));
|
||||
testMessage(sender, "***_~~test~~_***", new TellrawPart("test").setBold(true).setItalic(true)
|
||||
.setUnderlined(true).setStrikethrough(true).setColor(Color.White));*/
|
||||
}
|
||||
|
||||
void testMessage(final CommandSender sender, final String message, TellrawPart... extras) {
|
||||
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White);
|
||||
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, null);
|
||||
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, chid);
|
||||
ChatFormatter.Combine(cfs, message, tp);
|
||||
System.out.println("Testing: " + message);
|
||||
// System.out.println(ChatProcessing.toJson(tp));
|
||||
final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, chid);
|
||||
// System.out.println("Raw: " + ChatProcessing.toJson(expectedtp));
|
||||
for (TellrawPart extra : extras)
|
||||
expectedtp.addExtra(extra);
|
||||
assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue