Moved everything for Channel.java

This commit is contained in:
Norbi Peti 2016-11-15 22:34:07 +01:00
parent 5ec39c3581
commit a87c71f37b
11 changed files with 40 additions and 131 deletions

View file

@ -1,38 +0,0 @@
package buttondevteam.chat;
import java.util.ArrayList;
import java.util.List;
import buttondevteam.chat.formatting.ChatFormatter;
public class Channel {
public final String DisplayName;
public final ChatFormatter.Color Color;
public final String Command;
private static List<Channel> channels = new ArrayList<>();
public Channel(String displayname, ChatFormatter.Color color, String command) {
DisplayName = displayname;
Color = color;
Command = command;
}
static {
channels.add(GlobalChat = new Channel("§fg§f", ChatFormatter.Color.White, "g"));
channels.add(TownChat = new Channel("§3TC§f", ChatFormatter.Color.DarkAqua, "tc"));
channels.add(NationChat = new Channel("§6NC§f", ChatFormatter.Color.Gold, "nc"));
channels.add(AdminChat = new Channel("§cADMIN§f", ChatFormatter.Color.Red, "a"));
channels.add(ModChat = new Channel("§9MOD§f", ChatFormatter.Color.Blue, "mod"));
}
public static List<Channel> getChannels() {
return channels;
}
public static Channel GlobalChat;
public static Channel TownChat;
public static Channel NationChat;
public static Channel AdminChat;
public static Channel ModChat;
}

View file

@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.formatting.ChatFormatter;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.chat.*;
public class ChatPlayer extends TBMCPlayer {
public String getUserName() {
@ -73,7 +74,7 @@ public class ChatPlayer extends TBMCPlayer {
public Channel CurrentChannel = Channel.GlobalChat;
public boolean SendingLink = false;
public boolean RainbowPresserColorMode = false;
public ChatFormatter.Color OtherColorMode = null;
public Color OtherColorMode = null;
public boolean ChatOnly = false;
public int LoginWarningCount = 0;

View file

@ -24,12 +24,12 @@ import buttondevteam.chat.formatting.ChatFormatter;
import buttondevteam.chat.formatting.ChatFormatterBuilder;
import buttondevteam.chat.formatting.TellrawEvent;
import buttondevteam.chat.formatting.TellrawPart;
import buttondevteam.chat.formatting.TellrawSerializableEnum;
import buttondevteam.chat.formatting.TellrawSerializer;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.chat.formatting.ChatFormatter.Color;
import buttondevteam.chat.formatting.ChatFormatter.Priority;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TellrawSerializableEnum;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.chat.*;
public class ChatProcessing {
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\([\\*\\_\\\\])");
@ -85,13 +85,13 @@ public class ChatProcessing {
ArrayList<ChatFormatter> formatters = new ArrayList<ChatFormatter>();
ChatFormatter.Color colormode = currentchannel.Color;
Color colormode = currentchannel.color;
if (mp != null && mp.OtherColorMode != null)
colormode = mp.OtherColorMode;
if (mp != null && mp.RainbowPresserColorMode)
colormode = ChatFormatter.Color.RPC;
colormode = Color.RPC;
if (message.startsWith(">"))
colormode = ChatFormatter.Color.Green;
colormode = Color.Green;
// If greentext, ignore channel or player colors
formatters.add(new ChatFormatterBuilder().setRegex(ENTIRE_MESSAGE_PATTERN).setColor(colormode)
@ -101,17 +101,17 @@ public class ChatProcessing {
String suggestmsg = formattedmessage;
formatters.add(new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setFormat(ChatFormatter.Format.Bold)
formatters.add(new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setFormat(Format.Bold)
.setRemoveCharCount((short) 2).build());
formatters.add(new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setFormat(ChatFormatter.Format.Italic)
formatters.add(new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setFormat(Format.Italic)
.setRemoveCharCount((short) 1).build());
formatters.add(new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setFormat(Format.Underlined)
.setRemoveCharCount((short) 1).build());
formatters.add(new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN)
.setFormat(ChatFormatter.Format.Underlined).setRemoveCharCount((short) 1).build());
formatters.add(new ChatFormatterBuilder().setRegex(ESCAPE_PATTERN).setRemoveCharPos((short) 0).build());
// URLs + Rainbow text
formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(ChatFormatter.Format.Underlined)
.setOpenlink("$1").build());
formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(Format.Underlined).setOpenlink("$1")
.build());
if (PluginMain.GetPlayers().size() > 0) {
StringBuilder namesb = new StringBuilder();
namesb.append("(?i)(");
@ -126,8 +126,8 @@ public class ChatProcessing {
nicksb.deleteCharAt(nicksb.length() - 1);
nicksb.append(")");
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString()))
.setColor(ChatFormatter.Color.Aqua).setOnmatch((String match) -> {
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()
@ -144,8 +144,8 @@ public class ChatProcessing {
return color + p.getName() + "§r";
}).setPriority(Priority.High).build());
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString()))
.setColor(ChatFormatter.Color.Aqua).setOnmatch((String match) -> {
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) {
@ -167,7 +167,7 @@ public class ChatProcessing {
}
pingedconsole = false;
formatters.add(new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(ChatFormatter.Color.Aqua)
formatters.add(new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(Color.Aqua)
.setOnmatch((String match) -> {
if (!pingedconsole) {
System.out.print("\007");
@ -176,7 +176,7 @@ public class ChatProcessing {
return match;
}).setPriority(Priority.High).build());
formatters.add(new ChatFormatterBuilder().setRegex(HASHTAG_PATTERN).setColor(ChatFormatter.Color.Blue)
formatters.add(new ChatFormatterBuilder().setRegex(HASHTAG_PATTERN).setColor(Color.Blue)
.setOpenlink("https://twitter.com/hashtag/$1").setPriority(Priority.High).build());
/*

View file

@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
import buttondevteam.chat.formatting.ChatFormatter;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.chat.*;
public class CCommand extends UCommandBase {
@ -37,7 +37,7 @@ public class CCommand extends UCommandBase {
p.RainbowPresserColorMode = false;
p.OtherColorMode = null;
try {
p.OtherColorMode = ChatFormatter.Color.valueOf(args[0].toLowerCase());
p.OtherColorMode = Color.valueOf(args[0].toLowerCase());
} catch (Exception e) {
player.sendMessage("§cUnknown message color: " + args[0]);
player.sendMessage("§cUse color names, like blue, or dark_aqua");

View file

@ -8,6 +8,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import buttondevteam.lib.chat.*;
public final class ChatFormatter {
private Pattern regex;
@ -168,7 +169,7 @@ public final class ChatFormatter {
if (formatter.color != null)
color = formatter.color;
if (formatter.format != null)
format = formatter.format.flag; //TODO: Fix
format = formatter.format.getFlag(); //TODO: Fix
if (formatter.openlink != null)
openlink = formatter.openlink;
}
@ -193,58 +194,4 @@ public final class ChatFormatter {
return new StringBuilder("F(").append(color).append(", ").append(format).append(", ").append(openlink)
.append(", ").append(priority).append(")").toString();
}
public enum Format implements TellrawSerializableEnum {
Bold("bold"), Underlined("underlined"), Italic("italic"), Strikethrough("strikethrough"), Obfuscated(
"obfuscated");
// TODO: Add format codes to /u c <mode>
private String name;
Format(String name) {
this.name = name;
this.flag = 1 << this.ordinal();
}
@Override
public String getName() {
return name;
}
private final int flag;
public int getFlag() {
return flag;
}
}
public enum Color implements TellrawSerializableEnum {
Black("black"), DarkBlue("dark_blue"), DarkGreen("dark_green"), DarkAqua("dark_aqua"), DarkRed(
"dark_red"), DarkPurple("dark_purple"), Gold("gold"), Gray("gray"), DarkGray("dark_gray"), Blue(
"blue"), Green("green"), Aqua("aqua"), Red(
"red"), LightPurple("light_purple"), Yellow("yellow"), White("white"), RPC("rpc");
private String name;
Color(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}
public enum Priority {
Low(0), Normal(1), High(2);
private int val;
Priority(int v) {
val = v;
}
public int GetValue() {
return val;
}
}
}

View file

@ -3,9 +3,7 @@ package buttondevteam.chat.formatting;
import java.util.function.Function;
import java.util.regex.Pattern;
import buttondevteam.chat.formatting.ChatFormatter.Color;
import buttondevteam.chat.formatting.ChatFormatter.Format;
import buttondevteam.chat.formatting.ChatFormatter.Priority;
import buttondevteam.lib.chat.*;
public class ChatFormatterBuilder {
private Pattern regex;

View file

@ -2,6 +2,8 @@ package buttondevteam.chat.formatting;
import java.io.Serializable;
import buttondevteam.lib.chat.TellrawSerializableEnum;
public final class TellrawEvent<T extends TellrawEvent.Action> implements Serializable {
private static final long serialVersionUID = -1681364161210561505L;
private transient boolean hoverEvent;

View file

@ -4,10 +4,12 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import buttondevteam.lib.chat.*;
@SuppressWarnings("unused")
public final class TellrawPart implements Serializable {
private static final long serialVersionUID = 4125357644462144024L;
private ChatFormatter.Color color;
private Color color;
private transient int format;
private boolean italic;
private boolean bold;
@ -23,11 +25,11 @@ public final class TellrawPart implements Serializable {
this.text = text;
}
public ChatFormatter.Color getColor() {
public Color getColor() {
return color;
}
public TellrawPart setColor(ChatFormatter.Color color) {
public TellrawPart setColor(Color color) {
this.color = color;
return this;
}
@ -43,15 +45,15 @@ public final class TellrawPart implements Serializable {
this.underlined = false;
this.strikethrough = false;
this.obfuscated = false;
if ((format & ChatFormatter.Format.Italic.getFlag()) != 0)
if ((format & Format.Italic.getFlag()) != 0)
this.italic = true;
else if ((format & ChatFormatter.Format.Bold.getFlag()) != 0)
else if ((format & Format.Bold.getFlag()) != 0)
this.bold = true;
else if ((format & ChatFormatter.Format.Underlined.getFlag()) != 0)
else if ((format & Format.Underlined.getFlag()) != 0)
this.underlined = true;
else if ((format & ChatFormatter.Format.Strikethrough.getFlag()) != 0)
else if ((format & Format.Strikethrough.getFlag()) != 0)
this.strikethrough = true;
else if ((format & ChatFormatter.Format.Obfuscated.getFlag()) != 0)
else if ((format & Format.Obfuscated.getFlag()) != 0)
this.obfuscated = true;
else
throw new UnsupportedOperationException("Trying to set to an unknown format!");

View file

@ -1,5 +0,0 @@
package buttondevteam.chat.formatting;
public interface TellrawSerializableEnum {
public String getName();
}

View file

@ -7,6 +7,8 @@ import java.util.Collection;
import com.google.gson.*;
import com.google.gson.stream.*;
import buttondevteam.lib.chat.TellrawSerializableEnum;
public abstract class TellrawSerializer {
public static class TwEnum extends TypeAdapter<TellrawSerializableEnum> {
@Override

View file

@ -32,13 +32,13 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import au.com.mineauz.minigames.MinigamePlayer;
import au.com.mineauz.minigames.Minigames;
import buttondevteam.chat.Channel;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.PluginMain;
import buttondevteam.chat.commands.ucmds.KittycannonCommand;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.TBMCPlayer.InfoTarget;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.TBMCPlayerGetInfoEvent;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;