Update Chroma-Core to v2.0.0

This commit is contained in:
Norbi Peti 2023-03-24 21:53:29 +01:00
parent 6c1378f370
commit 522f29ba58
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
21 changed files with 55 additions and 44 deletions

View file

@ -125,7 +125,7 @@
<dependency>
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
<artifactId>Chroma-Core</artifactId>
<version>v1.0.0</version>
<version>v2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.essentialsx</groupId>
@ -198,6 +198,13 @@
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mojang/brigadier -->
<dependency>
<groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId>
<version>1.0.500</version>
<scope>provided</scope>
</dependency>
</dependencies>
<artifactId>Chroma-Chat</artifactId>
<organization>

View file

@ -9,11 +9,13 @@ import buttondevteam.lib.player.TBMCPlayerBase;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Collections;
@PlayerClass(pluginname = "Chroma-Chat")
public class ChatPlayer extends TBMCPlayerBase {
public final ConfigData<String> UserName = getConfig().getData("UserName", "");
public final ListConfigData<String> UserNames = getConfig().getListData("UserNames");
public final ListConfigData<String> UserNames = getConfig().getListData("UserNames", Collections.emptyList());
public final ConfigData<Integer> FlairTime = getConfig().getData("FlairTime", FlairTimeNone);
@ -26,7 +28,7 @@ public class ChatPlayer extends TBMCPlayerBase {
public final ConfigData<Boolean> FlairCheater = getConfig().getData("FlairCheater", false);
public final ListConfigData<Integer> NameColorLocations = getConfig().getListData("NameColorLocations"); // No byte[], no TIntArrayList
public final ListConfigData<Integer> NameColorLocations = getConfig().getListData("NameColorLocations", Collections.emptyList()); // No byte[], no TIntArrayList
public boolean Working;
// public int Tables = 10;
@ -80,7 +82,7 @@ public class ChatPlayer extends TBMCPlayerBase {
// Flairs from Command Block The Button - Teams
// PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add()
Player p = Bukkit.getPlayer(uuid);
Player p = Bukkit.getPlayer(getUniqueId());
if (p != null)
p.setPlayerListName(String.format("%s%s", p.getDisplayName(), GetFormattedFlair()));
}

View file

@ -56,7 +56,7 @@ public final class ChatUtils {
}
public static String getMessageString(Channel channel, CommandSender sender, String message) {
return "§c!§r[" + channel.DisplayName.get() + "] <"
return "§c!§r[" + channel.displayName.get() + "] <"
+ ChromaUtils.getDisplayName(sender) + "> " + message;
}

View file

@ -53,7 +53,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
Component.registerComponent(this, new TownyComponent());
TBMCChatAPI.RegisterChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
TBMCChatAPI.registerChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
if (!setupPermissions())
TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up permissions!"), this);

View file

@ -21,7 +21,7 @@ public class VanillaUtils {
else
return null;
} catch (NoClassDefFoundError ex) {
MainPlugin.Instance.getLogger().warning("Compatibility error, can't check if the chat is hidden by the player.");
MainPlugin.instance.getLogger().warning("Compatibility error, can't check if the chat is hidden by the player.");
return e.getGroupID(p);
}
}

View file

@ -49,8 +49,8 @@ public final class HelpCommand extends UCommandBase {
"§nunderline - &n§r | §oitalic - &o§r", //
"The format codes in tellraw should be used like \"italic\":\"true\""}); //
} else {
String[] text = getManager().getHelpText(topicOrCommand);
if (text == null)
String[] text = getManager().getCommandNode(topicOrCommand).getData().getHelpText(sender); // TODO: This only works for the main command, not subcommands
if (text == null) // TODO: Null check for command node
sender.sendMessage(
new String[]{"§cError: Command not found: " + topicOrCommand,
"Usage example: /u accept --> /u help u accept"});

View file

@ -35,13 +35,13 @@ public class HistoryCommand extends UCommandBase {
sender.sendMessage("§6Chat history is disabled");
return true;
}
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.ID + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.getIdentifier() + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
sender.sendMessage("§6---- Chat History ----");
Stream<Channel> stream;
if (channel == null) {
stream = Channel.getChannels();
} else {
Optional<Channel> och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(channel)).findAny();
Optional<Channel> och = Channel.getChannels().filter(chan -> chan.getIdentifier().equalsIgnoreCase(channel)).findAny();
if (!och.isPresent()) {
sender.sendMessage("§cChannel not found. Use the ID, for example: /u history g");
return true;
@ -55,7 +55,7 @@ public class HistoryCommand extends UCommandBase {
for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) {
HistoryEntry e = arr[i];
val cm = e.chatMessage;
sender.sendMessage("[" + e.channel.DisplayName.get() + "] " + cm.getSender().getName() + ": " + cm.getMessage());
sender.sendMessage("[" + e.channel.displayName.get() + "] " + cm.getSender().getName() + ": " + cm.getMessage());
sent.set(true);
}
}
@ -66,7 +66,7 @@ public class HistoryCommand extends UCommandBase {
@CustomTabCompleteMethod(param = "channel")
public Iterable<String> def() {
return Channel.getChannels().map(ch -> ch.ID)::iterator;
return Channel.getChannels().map(Channel::getIdentifier)::iterator;
}
@RequiredArgsConstructor
@ -84,7 +84,7 @@ public class HistoryCommand extends UCommandBase {
val groupID = channel.getGroupID(chatMessage.getPermCheck());
if (groupID == null) return; //Just to be sure
synchronized (messages) {
var ll = messages.computeIfAbsent(channel.ID + "_" + groupID, k -> new LinkedList<>()); //<-- TIL
var ll = messages.computeIfAbsent(channel.getIdentifier() + "_" + groupID, k -> new LinkedList<>()); //<-- TIL
ll.add(new HistoryEntry(System.nanoTime(), chatMessage, channel)); //Adds as last element
while (ll.size() > 10)
ll.remove(); //Removes the first element

View file

@ -10,6 +10,8 @@ import buttondevteam.lib.architecture.ListConfigData;
import buttondevteam.lib.chat.TBMCChatAPI;
import org.bukkit.Bukkit;
import java.util.Collections;
/**
* Displays the configured messages at the set interval when someone is online.
*/
@ -18,7 +20,7 @@ public class AnnouncerComponent extends Component<PluginMain> implements Runnabl
/**
* The messages to display to players.
*/
public ListConfigData<String> announceMessages = getConfig().getListData("announceMessages");
public ListConfigData<String> announceMessages = getConfig().getListData("announceMessages", Collections.emptyList());
/**
* The time in milliseconds between the messages. Use /u announce settime to set minutes.
@ -39,7 +41,7 @@ public class AnnouncerComponent extends Component<PluginMain> implements Runnabl
}
if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on
if (announceMessages.get().size() > AnnounceMessageIndex) {
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, announceMessages.get().get(AnnounceMessageIndex), target);
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL, announceMessages.get().get(AnnounceMessageIndex), target);
AnnounceMessageIndex++;
if (AnnounceMessageIndex == announceMessages.get().size())
AnnounceMessageIndex = 0;

View file

@ -21,7 +21,7 @@ public class AppendTextComponent extends Component<PluginMain> {
private Map<String, IHaveConfig> appendTexts;
private ConfigData<String[]> helpText(IHaveConfig config) {
return config.getData("helpText", () -> new String[]{
return config.getData("helpText", new String[]{
"Tableflip", //
"This command appends a tableflip after your message", //
"Or just makes you tableflip", //
@ -29,7 +29,7 @@ public class AppendTextComponent extends Component<PluginMain> {
}
private ConfigData<String> appendedText(IHaveConfig config) {
return config.getData("appendedText", () -> "tableflip");
return config.getData("appendedText", "tableflip");
}
@Override
@ -101,7 +101,7 @@ public class AppendTextComponent extends Component<PluginMain> {
@Command2.Subcommand
public void def(Command2MCSender sender, @Command2.OptionalArg @Command2.TextArg String message) {
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender.getSender(), ChromaGamerBase.getFromSender(sender.getSender()),
TBMCChatAPI.sendChatMessage(ChatMessage.builder(sender.getSender(), ChromaGamerBase.getFromSender(sender.getSender()),
(message == null ? "" : message + " ") + appendedText).fromCommand(true).permCheck(sender.getPermCheck()).build());
}

View file

@ -145,7 +145,7 @@ public class FlairComponent extends Component<PluginMain> {
} catch (Exception e) {
p.FlairState.set(FlairStates.Commented); // Flair unknown
p.SetFlair(ChatPlayer.FlairTimeNone);
TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName + "!", e, this);
TBMCCoreAPI.SendException("Error while checking join date for player " + p.playerName + "!", e, this);
}
return;
default:
@ -178,7 +178,7 @@ public class FlairComponent extends Component<PluginMain> {
}
public static void ConfirmUserMessage(ChatPlayer mp) {
Player p = Bukkit.getPlayer(mp.getUUID());
Player p = Bukkit.getPlayer(mp.getUniqueId());
if (mp.FlairState.get().equals(FlairStates.Commented) && p != null)
if (mp.UserNames.get().size() > 1)
p.sendMessage(

View file

@ -49,8 +49,7 @@ public class SetFlairCommand extends AdminCommandBase {
if (!mp.UserNames.get().contains(username))
mp.UserNames.get().add(username);
}
sender.sendMessage(
"§bThe flair has been set. Player: " + mp.PlayerName + " Flair: " + mp.GetFormattedFlair() + "§r");
sender.sendMessage("§bThe flair has been set. Player: " + mp.playerName + " Flair: " + mp.GetFormattedFlair() + "§r");
return true;
}

View file

@ -144,14 +144,14 @@ public class ChatProcessing {
if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14)
Color colormode = channel.Color.get();
Color colormode = channel.color.get();
if (mp != null && mp.OtherColorMode != null)
colormode = mp.OtherColorMode;
ArrayList<MatchProviderBase> formatters;
if (component.allowFormatting.get()) {
formatters = addFormatters(e::shouldSendTo, component);
if (colormode == channel.Color.get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
if (colormode == channel.color.get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
createRPC(colormode, formatters);
}
pingedconsole = false; // Will set it to true onmatch (static constructor)
@ -256,7 +256,7 @@ public class ChatProcessing {
}
static String getChannelID(Channel channel, String origin) {
return ("[" + (ChatUtils.MCORIGIN.equals(origin) ? "" : "§8" + origin.charAt(0) + "§r|") + channel.DisplayName.get())
return ("[" + (ChatUtils.MCORIGIN.equals(origin) ? "" : "§8" + origin.charAt(0) + "§r|") + channel.displayName.get())
+ "]";
}

View file

@ -35,12 +35,12 @@ public class FormatterComponent extends Component<PluginMain> {
@Override
protected void enable() {
MainPlugin.Instance.setChatHandlerEnabled(false); //Disable Core chat handler - if this component is disabled then let it do its job
MainPlugin.instance.setChatHandlerEnabled(false); //Disable Core chat handler - if this component is disabled then let it do its job
}
@Override
protected void disable() {
MainPlugin.Instance.setChatHandlerEnabled(true);
MainPlugin.instance.setChatHandlerEnabled(true);
}
/**

View file

@ -55,7 +55,7 @@ public class FTopCommand extends ICommand2MC {
val ai = new AtomicInteger();
sender.sendMessage("§6---- Top Fs ----");
sender.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10)
.map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName.get(), cp.getF()))
.map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.playerName.get(), cp.getF()))
.collect(Collectors.joining("\n")));
});
return true;

View file

@ -45,7 +45,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
/**
* The strings that count as laughs, see unlol.
*/
private final ConfigData<String[]> laughStrings = getConfig().getData("laughStrings", () -> new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"});
private final ConfigData<String[]> laughStrings = getConfig().getData("laughStrings", new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"});
/**
* The "Press F to pay respects" meme in Minecraft. It will randomly appear on player death and keep track of how many "F"s are said in chat.
@ -113,7 +113,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
ActiveF = false;
if (FPlayer != null && FPlayer.FCount.get() < Integer.MAX_VALUE - 1)
FPlayer.FCount.set(FPlayer.FCount.get() + Fs.size());
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL,
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL,
"§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
+ " paid their respects.§r", fTarget);
Fs.clear();
@ -127,7 +127,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
Fs.clear();
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class);
FPlayer.FDeaths.set(FPlayer.FDeaths.get() + 1);
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL,
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL,
"§bPress F to pay respects.§r", fTarget);
Ftask = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20);
}

View file

@ -1,6 +1,7 @@
package buttondevteam.chat.components.fun;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.core.component.restart.RestartComponent;
import buttondevteam.core.component.restart.ScheduledRestartCommand;
import buttondevteam.lib.ChromaUtils;
import buttondevteam.lib.ScheduledServerRestartEvent;
@ -36,7 +37,7 @@ public class PressCommand extends ICommand2MC implements Listener {
return;
}
pressers.add(sender);
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, String.format("§b-- %s §bpressed at %.0fs", ChromaUtils.getDisplayName(sender), command.getRestartCounter() / 20f), command.getComponent().getRestartBroadcast());
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL, String.format("§b-- %s §bpressed at %.0fs", ChromaUtils.getDisplayName(sender), command.getRestartCounter() / 20f), ((RestartComponent) command.getComponent()).getRestartBroadcast());
command.setRestartCounter(startTicks);
}
@ -46,6 +47,6 @@ public class PressCommand extends ICommand2MC implements Listener {
pressers = new HashSet<>();
startTicks = event.getRestartTicks();
if (Bukkit.getOnlinePlayers().size() > 0)
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, "§b-- Do /press to reset the timer. You may only press once.", command.getComponent().getRestartBroadcast());
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL, "§b-- Do /press to reset the timer. You may only press once.", ((RestartComponent) command.getComponent()).getRestartBroadcast());
}
}

View file

@ -44,7 +44,7 @@ public final class UnlolCommand extends ICommand2MC {
String msg = ChromaUtils.getDisplayName(sender)
+ (lol.Lolornot ? " unlolled " : " unlaughed ")
+ ChromaUtils.getDisplayName(lol.Lolowner);
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, msg, target);
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL, msg, target);
Lastlol.remove(lol.Chatevent.getChannel());
return true;
}

View file

@ -44,7 +44,7 @@ public class TownyAnnouncer {
message, target, ChatUtils.MCORIGIN);
break;
case "Global":
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
TBMCChatAPI.SendSystemMessage(Channel.globalChat,
Channel.RecipientTestResult.ALL,
message, target, ChatUtils.MCORIGIN);
break;

View file

@ -53,9 +53,9 @@ public class TownyComponent extends Component<PluginMain> {
}
Towns = dataSource.getTowns().stream().map(Town::getName).collect(Collectors.toCollection(ArrayList::new)); // Creates a snapshot of towns, new towns will be added when needed
Nations = dataSource.getNations().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations
TBMCChatAPI.RegisterChatChannel(
TBMCChatAPI.registerChatChannel(
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
TBMCChatAPI.RegisterChatChannel(
TBMCChatAPI.registerChatChannel(
NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true)));
TownyAnnouncer.setup(TownChat, NationChat);
}
@ -67,7 +67,7 @@ public class TownyComponent extends Component<PluginMain> {
public Consumer<Player> handleSpiesInit(Channel channel, TellrawPart json, Function<TellrawPart, String> toJson,
CommandSender sender, String message) {
if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) {
if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) {
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
String jsonstr = toJson.apply(json);
return p -> handleSpies(channel, p, jsonstr, sender, message);
@ -76,7 +76,7 @@ public class TownyComponent extends Component<PluginMain> {
}
private void handleSpies(Channel channel, Player p, String jsonstr, CommandSender sender, String message) {
if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) {
if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) {
try {
if (dataSource.getResident(p.getName()).hasMode("spy"))
if (!VanillaUtils.tellRaw(p, jsonstr))

View file

@ -56,7 +56,7 @@ public class PlayerListener implements Listener {
ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class);
if (cp == null)
return;
e.addInfo("Minecraft name: " + cp.PlayerName.get());
e.addInfo("Minecraft name: " + cp.playerName.get());
if (cp.UserName.get() != null && cp.UserName.get().length() > 0)
e.addInfo("Reddit name: " + cp.UserName.get());
if (ComponentManager.isEnabled(FlairComponent.class)) {
@ -74,7 +74,7 @@ public class PlayerListener implements Listener {
try {
if (e.isCancelled())
return;
HistoryCommand.addChatMessage(e.getCm(), e.getChannel());
HistoryCommand.addChatMessage(e.getChatMessage(), e.getChannel());
e.setCancelled(FormatterComponent.handleChat(e));
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
if (lastError < System.nanoTime() - 1000L * 1000L * 1000L * 60 * 60 //60 mins
@ -82,7 +82,7 @@ public class PlayerListener implements Listener {
lastError = System.nanoTime(); //I put the whole thing in the if to protect against race conditions
for (Player p : Bukkit.getOnlinePlayers())
if (e.shouldSendTo(p))
p.sendMessage("[" + e.getChannel().DisplayName.get() + "] §cSome features in the message below might be unavailable due to an error.");
p.sendMessage("[" + e.getChannel().displayName.get() + "] §cSome features in the message below might be unavailable due to an error.");
}
ChatUtils.sendChatMessage(e);
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex, PluginMain.Instance);

View file

@ -134,7 +134,7 @@ public class ChatFormatIT {
public void testMessage() {
System.out.println("Testing: " + message);
ArrayList<MatchProviderBase> cfs = ChatProcessing.addFormatters(p -> true, null);
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN);
final String chid = ChatProcessing.getChannelID(Channel.globalChat, ChatUtils.MCORIGIN);
if (rainbowMode)
ChatProcessing.createRPC(Color.White, cfs);
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);