Start fixing errors related to player API changes
- The fancy chat API would be useful here, I don't want to update my old code
This commit is contained in:
parent
2242655c41
commit
51cf31713b
11 changed files with 75 additions and 75 deletions
|
@ -1,8 +1,8 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.ChromaUtils;
|
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -48,19 +48,18 @@ public final class ChatUtils {
|
||||||
* @param e The chat event
|
* @param e The chat event
|
||||||
*/
|
*/
|
||||||
public static void sendChatMessage(TBMCChatEvent e) {
|
public static void sendChatMessage(TBMCChatEvent e) {
|
||||||
var str = getMessageString(e.getChannel(), e.getSender(), e.getMessage());
|
var str = getMessageString(e.getChannel(), e.getUser(), e.getMessage());
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
if (e.shouldSendTo(p))
|
if (e.shouldSendTo(ChromaGamerBase.getFromSender(p)))
|
||||||
p.sendMessage(str);
|
p.sendMessage(str);
|
||||||
Bukkit.getConsoleSender().sendMessage(str);
|
Bukkit.getConsoleSender().sendMessage(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMessageString(Channel channel, CommandSender sender, String message) {
|
public static String getMessageString(Channel channel, ChromaGamerBase sender, String message) {
|
||||||
return "§c!§r[" + channel.displayName.get() + "] <"
|
return "§c!§r[" + channel.displayName.get() + "] <" + sender.getName() + "> " + message;
|
||||||
+ ChromaUtils.getDisplayName(sender) + "> " + message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendChatMessage(Channel channel, CommandSender sender, String message, CommandSender to) {
|
public static void sendChatMessage(Channel channel, ChromaGamerBase sender, String message, CommandSender to) {
|
||||||
to.sendMessage(getMessageString(channel, sender, message));
|
to.sendMessage(getMessageString(channel, sender, message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package buttondevteam.chat;
|
||||||
|
|
||||||
import buttondevteam.core.MainPlugin;
|
import buttondevteam.core.MainPlugin;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -16,14 +17,12 @@ import java.util.function.Predicate;
|
||||||
public class VanillaUtils {
|
public class VanillaUtils {
|
||||||
public String getGroupIfChatOn(Player p, TBMCChatEvent e) {
|
public String getGroupIfChatOn(Player p, TBMCChatEvent e) {
|
||||||
try {
|
try {
|
||||||
if (isChatOn(p)) // Only send if client allows chat
|
if (!isChatOn(p)) // Only send if client allows chat
|
||||||
return e.getGroupID(p);
|
|
||||||
else
|
|
||||||
return null;
|
return null;
|
||||||
} catch (NoClassDefFoundError ex) {
|
} 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);
|
|
||||||
}
|
}
|
||||||
|
return e.getGroupID(ChromaGamerBase.getFromSender(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<Player> isChatOn;
|
private Predicate<Player> isChatOn;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package buttondevteam.chat.commands;
|
package buttondevteam.chat.commands;
|
||||||
|
|
||||||
import buttondevteam.lib.ChromaUtils;
|
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import buttondevteam.lib.chat.*;
|
import buttondevteam.lib.chat.*;
|
||||||
|
|
||||||
|
@ -11,6 +10,6 @@ import buttondevteam.lib.chat.*;
|
||||||
public class MeCommand extends ICommand2MC {
|
public class MeCommand extends ICommand2MC {
|
||||||
@Command2.Subcommand
|
@Command2.Subcommand
|
||||||
public void def(Command2MCSender sender, @Command2.TextArg String message) {
|
public void def(Command2MCSender sender, @Command2.TextArg String message) {
|
||||||
TBMCChatAPI.SendSystemMessage(sender.getChannel(), sender.getChannel().getRTR(sender.getPermCheck()), "§5* " + ChromaUtils.getDisplayName(sender.getSender()) + " " + message, TBMCSystemChatEvent.BroadcastTarget.ALL);
|
TBMCChatAPI.SendSystemMessage(sender.getChannel(), sender.getChannel().getRTR(sender.getPermCheck()), "§5* " + sender.getSender().getName() + " " + message, TBMCSystemChatEvent.BroadcastTarget.ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,8 @@ import buttondevteam.lib.chat.ChatMessage;
|
||||||
import buttondevteam.lib.chat.Command2;
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.CustomTabCompleteMethod;
|
import buttondevteam.lib.chat.CustomTabCompleteMethod;
|
||||||
import lombok.RequiredArgsConstructor;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
@ -26,11 +25,11 @@ public class HistoryCommand extends UCommandBase {
|
||||||
private static final HashMap<String, LinkedList<HistoryEntry>> messages = new HashMap<>();
|
private static final HashMap<String, LinkedList<HistoryEntry>> messages = new HashMap<>();
|
||||||
|
|
||||||
@Command2.Subcommand
|
@Command2.Subcommand
|
||||||
public boolean def(CommandSender sender, @Command2.OptionalArg String channel) {
|
public boolean def(ChromaGamerBase sender, @Command2.OptionalArg String channel) {
|
||||||
return showHistory(sender, channel);
|
return showHistory(sender, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showHistory(CommandSender sender, String channel) {
|
public static boolean showHistory(ChromaGamerBase sender, String channel) {
|
||||||
if (!PluginMain.Instance.storeChatHistory.get()) {
|
if (!PluginMain.Instance.storeChatHistory.get()) {
|
||||||
sender.sendMessage("§6Chat history is disabled");
|
sender.sendMessage("§6Chat history is disabled");
|
||||||
return true;
|
return true;
|
||||||
|
@ -55,7 +54,7 @@ public class HistoryCommand extends UCommandBase {
|
||||||
for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) {
|
for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) {
|
||||||
HistoryEntry e = arr[i];
|
HistoryEntry e = arr[i];
|
||||||
val cm = e.chatMessage;
|
val cm = e.chatMessage;
|
||||||
sender.sendMessage("[" + e.channel.displayName.get() + "] " + cm.getSender().getName() + ": " + cm.getMessage());
|
sender.sendMessage("[" + e.channel.displayName.get() + "] " + cm.getUser().getName() + ": " + cm.getMessage());
|
||||||
sent.set(true);
|
sent.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,14 +68,10 @@ public class HistoryCommand extends UCommandBase {
|
||||||
return Channel.getChannels().map(Channel::getIdentifier)::iterator;
|
return Channel.getChannels().map(Channel::getIdentifier)::iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
/**
|
||||||
private static class HistoryEntry {
|
* @param timestamp System.nanoTime()
|
||||||
/**
|
*/
|
||||||
* System.nanoTime()
|
private record HistoryEntry(long timestamp, ChatMessage chatMessage, Channel channel) {
|
||||||
*/
|
|
||||||
private final long timestamp;
|
|
||||||
private final ChatMessage chatMessage;
|
|
||||||
private final Channel channel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addChatMessage(ChatMessage chatMessage, Channel channel) {
|
public static void addChatMessage(ChatMessage chatMessage, Channel channel) {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.architecture.ConfigData;
|
import buttondevteam.lib.architecture.ConfigData;
|
||||||
import buttondevteam.lib.architecture.IHaveConfig;
|
import buttondevteam.lib.architecture.IHaveConfig;
|
||||||
import buttondevteam.lib.chat.*;
|
import buttondevteam.lib.chat.*;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -101,7 +100,7 @@ public class AppendTextComponent extends Component<PluginMain> {
|
||||||
|
|
||||||
@Command2.Subcommand
|
@Command2.Subcommand
|
||||||
public void def(Command2MCSender sender, @Command2.OptionalArg @Command2.TextArg String message) {
|
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(),
|
||||||
(message == null ? "" : message + " ") + appendedText).fromCommand(true).permCheck(sender.getPermCheck()).build());
|
(message == null ? "" : message + " ") + appendedText).fromCommand(true).permCheck(sender.getPermCheck()).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.google.common.collect.Lists;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -103,14 +104,14 @@ public class ChatProcessing {
|
||||||
|
|
||||||
public static boolean ProcessChat(TBMCChatEvent e, FormatterComponent component) {
|
public static boolean ProcessChat(TBMCChatEvent e, FormatterComponent component) {
|
||||||
Channel channel = e.getChannel();
|
Channel channel = e.getChannel();
|
||||||
CommandSender sender = e.getSender();
|
ChromaGamerBase cuser = e.getUser();
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
long processstart = System.nanoTime();
|
long processstart = System.nanoTime();
|
||||||
Player player = (sender instanceof Player ? (Player) sender : null);
|
Player player = (cuser instanceof TBMCPlayerBase ? ((TBMCPlayerBase) cuser).getPlayer() : null);
|
||||||
User user = PluginMain.essentials.getUser(player);
|
User user = PluginMain.essentials.getUser(player);
|
||||||
|
|
||||||
if (player != null && PluginMain.essentials.getSettings().cancelAfkOnInteract()) {
|
if (player != null && PluginMain.essentials.getSettings().cancelAfkOnInteract()) {
|
||||||
user.updateActivity(true); //Could talk in a private channel, so broadcast
|
user.updateActivity(true, AfkStatusChangeEvent.Cause.CHAT); //Could talk in a private channel, so broadcast
|
||||||
if (user.isMuted())
|
if (user.isMuted())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +124,7 @@ public class ChatProcessing {
|
||||||
|
|
||||||
if (mp != null) {
|
if (mp != null) {
|
||||||
if (System.nanoTime() - mp.LastMessageTime < 1000L * 1000L * component.minTimeBetweenMessages.get()) { //0.1s by default
|
if (System.nanoTime() - mp.LastMessageTime < 1000L * 1000L * component.minTimeBetweenMessages.get()) { //0.1s by default
|
||||||
sender.sendMessage("§cYou are sending messages too quickly!");
|
cuser.sendMessage("§cYou are sending messages too quickly!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mp.LastMessageTime = System.nanoTime();
|
mp.LastMessageTime = System.nanoTime();
|
||||||
|
@ -135,12 +136,12 @@ public class ChatProcessing {
|
||||||
//IRegistry
|
//IRegistry
|
||||||
//CraftServer
|
//CraftServer
|
||||||
|
|
||||||
doFunStuff(sender, e, message);
|
doFunStuff(cuser, e, message);
|
||||||
|
|
||||||
final String channelidentifier = getChannelID(channel, e.getOrigin());
|
final String channelidentifier = getChannelID(channel, e.getOrigin());
|
||||||
|
|
||||||
PluginMain.Instance.getServer().getConsoleSender()
|
PluginMain.Instance.getServer().getConsoleSender()
|
||||||
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, cuser.getName(), message));
|
||||||
|
|
||||||
if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14)
|
if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14)
|
||||||
|
|
||||||
|
@ -150,7 +151,7 @@ public class ChatProcessing {
|
||||||
|
|
||||||
ArrayList<MatchProviderBase> formatters;
|
ArrayList<MatchProviderBase> formatters;
|
||||||
if (component.allowFormatting.get()) {
|
if (component.allowFormatting.get()) {
|
||||||
formatters = addFormatters(e::shouldSendTo, component);
|
formatters = addFormatters(sender -> e.shouldSendTo(ChromaGamerBase.getFromSender(sender)), 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);
|
createRPC(colormode, formatters);
|
||||||
}
|
}
|
||||||
|
@ -158,14 +159,13 @@ public class ChatProcessing {
|
||||||
} else
|
} else
|
||||||
formatters = Lists.newArrayList();
|
formatters = Lists.newArrayList();
|
||||||
|
|
||||||
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
TellrawPart json = createTellraw(cuser, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
||||||
long combinetime = System.nanoTime();
|
long combinetime = System.nanoTime();
|
||||||
ChatFormatter.Combine(formatters, message, json, component.getConfig(), FormatSettings.builder().color(colormode).build());
|
ChatFormatter.Combine(formatters, message, json, component.getConfig(), FormatSettings.builder().color(colormode).build());
|
||||||
combinetime = System.nanoTime() - combinetime;
|
combinetime = System.nanoTime() - combinetime;
|
||||||
String jsonstr = toJson(json);
|
String jsonstr = toJson(json);
|
||||||
if (jsonstr.length() >= 32767) {
|
if (jsonstr.length() >= 32767) {
|
||||||
sender.sendMessage(
|
cuser.sendMessage("§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
||||||
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DebugCommand.SendDebugMessage(jsonstr);
|
DebugCommand.SendDebugMessage(jsonstr);
|
||||||
|
@ -180,7 +180,7 @@ public class ChatProcessing {
|
||||||
val tc = ComponentManager.getIfEnabled(TownyComponent.class);
|
val tc = ComponentManager.getIfEnabled(TownyComponent.class);
|
||||||
Consumer<Player> spyConsumer = null;
|
Consumer<Player> spyConsumer = null;
|
||||||
if (tc != null)
|
if (tc != null)
|
||||||
spyConsumer = tc.handleSpiesInit(channel, json, ChatProcessing::toJson, sender, message);
|
spyConsumer = tc.handleSpiesInit(channel, json, ChatProcessing::toJson, cuser, message);
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
final String group;
|
final String group;
|
||||||
if (player != null
|
if (player != null
|
||||||
|
@ -221,11 +221,11 @@ public class ChatProcessing {
|
||||||
return gson.toJson(json);
|
return gson.toJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
|
static TellrawPart createTellraw(ChromaGamerBase user, String message, @Nullable Player player,
|
||||||
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
||||||
String origin) {
|
String origin) {
|
||||||
TellrawPart json = new TellrawPart("");
|
TellrawPart json = new TellrawPart("");
|
||||||
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API
|
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Use nice API (Paper)
|
||||||
json.addExtra(
|
json.addExtra(
|
||||||
new TellrawPart(channelidentifier)
|
new TellrawPart(channelidentifier)
|
||||||
.setHoverEvent(
|
.setHoverEvent(
|
||||||
|
@ -243,7 +243,7 @@ public class ChatProcessing {
|
||||||
TellrawPart hovertp = new TellrawPart("");
|
TellrawPart hovertp = new TellrawPart("");
|
||||||
if (cg != null)
|
if (cg != null)
|
||||||
hovertp.addExtra(new TellrawPart(cg.getInfo(ChromaGamerBase.InfoTarget.MCHover)));
|
hovertp.addExtra(new TellrawPart(cg.getInfo(ChromaGamerBase.InfoTarget.MCHover)));
|
||||||
json.addExtra(new TellrawPart(getSenderName(sender, player))
|
json.addExtra(new TellrawPart(user.getName())
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, hovertp)));
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, hovertp)));
|
||||||
json.addExtra(new TellrawPart("> "));
|
json.addExtra(new TellrawPart("> "));
|
||||||
return json;
|
return json;
|
||||||
|
@ -330,8 +330,8 @@ public class ChatProcessing {
|
||||||
component.notificationPitch.get());
|
component.notificationPitch.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {
|
static void doFunStuff(ChromaGamerBase user, TBMCChatEventBase event, String message) {
|
||||||
val fc = ComponentManager.getIfEnabled(FunComponent.class);
|
val fc = ComponentManager.getIfEnabled(FunComponent.class);
|
||||||
if (fc != null) fc.onChat(sender, event, message);
|
if (fc != null) fc.onChat(user, event, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package buttondevteam.chat.components.fun;
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.ChromaUtils;
|
|
||||||
import buttondevteam.lib.TBMCChatEventBase;
|
import buttondevteam.lib.TBMCChatEventBase;
|
||||||
import buttondevteam.lib.TBMCCommandPreprocessEvent;
|
import buttondevteam.lib.TBMCCommandPreprocessEvent;
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
|
@ -12,9 +11,9 @@ import buttondevteam.lib.architecture.ConfigData;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -36,7 +35,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
|
||||||
private boolean ActiveF = false;
|
private boolean ActiveF = false;
|
||||||
private ChatPlayer FPlayer = null;
|
private ChatPlayer FPlayer = null;
|
||||||
private BukkitTask Ftask = null;
|
private BukkitTask Ftask = null;
|
||||||
private final HashSet<CommandSender> Fs = new HashSet<>();
|
private final HashSet<ChromaGamerBase> Fs = new HashSet<>();
|
||||||
private UnlolCommand command;
|
private UnlolCommand command;
|
||||||
private TBMCSystemChatEvent.BroadcastTarget unlolTarget;
|
private TBMCSystemChatEvent.BroadcastTarget unlolTarget;
|
||||||
private TBMCSystemChatEvent.BroadcastTarget fTarget;
|
private TBMCSystemChatEvent.BroadcastTarget fTarget;
|
||||||
|
@ -80,20 +79,21 @@ public class FunComponent extends Component<PluginMain> implements Listener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onChat(CommandSender sender, TBMCChatEventBase event, String message) {
|
public void onChat(ChromaGamerBase sender, TBMCChatEventBase event, String message) {
|
||||||
if (ActiveF && !Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
if (ActiveF && !Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
||||||
Fs.add(sender);
|
Fs.add(sender);
|
||||||
|
|
||||||
if (unlol.get()) {
|
if (unlol.get()) {
|
||||||
String msg = message.toLowerCase();
|
String msg = message.toLowerCase();
|
||||||
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
|
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
|
||||||
boolean add;
|
boolean add = msg.contains("lol");
|
||||||
if (add = msg.contains("lol"))
|
if (add)
|
||||||
lld.setLolornot(true);
|
lld.setLolornot(true);
|
||||||
else {
|
else {
|
||||||
String[] laughs = laughStrings.get();
|
String[] laughs = laughStrings.get();
|
||||||
for (String laugh : laughs) {
|
for (String laugh : laughs) {
|
||||||
if (add = msg.contains(laugh)) {
|
add = msg.contains(laugh);
|
||||||
|
if (add) {
|
||||||
lld.setLolornot(false);
|
lld.setLolornot(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||||
if (unlol.get())
|
if (unlol.get())
|
||||||
command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
|
command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(ChromaGamerBase.getFromSender(event.getPlayer())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
@ -150,7 +150,14 @@ public class FunComponent extends Component<PluginMain> implements Listener {
|
||||||
if (ht.getName().equalsIgnoreCase(cmd))
|
if (ht.getName().equalsIgnoreCase(cmd))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (PluginMain.permission.has(event.getSender(), "chroma.unanything")) {
|
val user = event.getSender();
|
||||||
|
if (!(user instanceof TBMCPlayerBase)) {
|
||||||
|
// TODO: Cross-platform permission check; console is not supported here
|
||||||
|
user.sendMessage("§cError: You must be a player to use this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
val player = ((TBMCPlayerBase) user).getPlayer();
|
||||||
|
if (player != null && PluginMain.permission.has(player, "chroma.unanything")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
int index = cmd.lastIndexOf(' ');
|
int index = cmd.lastIndexOf(' ');
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
|
@ -163,10 +170,9 @@ public class FunComponent extends Component<PluginMain> implements Listener {
|
||||||
event.getSender().sendMessage("§cError: Player not found. (/un" + s + " <player>)");
|
event.getSender().sendMessage("§cError: Player not found. (/un" + s + " <player>)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
val user = ChromaGamerBase.getFromSender(event.getSender());
|
|
||||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
||||||
val chan = user.channel.get();
|
val chan = user.getChannel().get();
|
||||||
TBMCChatAPI.SendSystemMessage(chan, chan.getRTR(event.getSender()), ChromaUtils.getDisplayName(event.getSender()) + " un" + s
|
TBMCChatAPI.SendSystemMessage(chan, chan.getRTR(event.getSender()), event.getSender().getName() + " un" + s
|
||||||
+ "'d " + target.getDisplayName(), unlolTarget);
|
+ "'d " + target.getDisplayName(), unlolTarget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
package buttondevteam.chat.components.fun;
|
package buttondevteam.chat.components.fun;
|
||||||
|
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.ChromaUtils;
|
|
||||||
import buttondevteam.lib.TBMCChatEventBase;
|
import buttondevteam.lib.TBMCChatEventBase;
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import buttondevteam.lib.chat.Command2;
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.ICommand2MC;
|
import buttondevteam.lib.chat.ICommand2MC;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
@ -33,17 +32,17 @@ public final class UnlolCommand extends ICommand2MC {
|
||||||
private final TBMCSystemChatEvent.BroadcastTarget target;
|
private final TBMCSystemChatEvent.BroadcastTarget target;
|
||||||
|
|
||||||
@Command2.Subcommand
|
@Command2.Subcommand
|
||||||
public boolean def(CommandSender sender) {
|
public boolean def(ChromaGamerBase sender) {
|
||||||
LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender))
|
LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender))
|
||||||
.max(Comparator.comparingLong(lld -> lld.Loltime)).orElse(null);
|
.max(Comparator.comparingLong(lld -> lld.Loltime)).orElse(null);
|
||||||
if (lol == null)
|
if (lol == null)
|
||||||
return true;
|
return true;
|
||||||
if (lol.Lolowner instanceof Player)
|
if (lol.Lolowner instanceof TBMCPlayerBase) {
|
||||||
((Player) lol.Lolowner)
|
var player = ((TBMCPlayerBase) lol.Lolowner).getPlayer();
|
||||||
.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false));
|
if (player != null)
|
||||||
String msg = ChromaUtils.getDisplayName(sender)
|
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false));
|
||||||
+ (lol.Lolornot ? " unlolled " : " unlaughed ")
|
}
|
||||||
+ ChromaUtils.getDisplayName(lol.Lolowner);
|
String msg = sender.getName() + (lol.Lolornot ? " unlolled " : " unlaughed ") + lol.Lolowner.getName();
|
||||||
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL, msg, target);
|
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL, msg, target);
|
||||||
Lastlol.remove(lol.Chatevent.getChannel());
|
Lastlol.remove(lol.Chatevent.getChannel());
|
||||||
return true;
|
return true;
|
||||||
|
@ -52,7 +51,7 @@ public final class UnlolCommand extends ICommand2MC {
|
||||||
@Data
|
@Data
|
||||||
public static class LastlolData {
|
public static class LastlolData {
|
||||||
private boolean Lolornot;
|
private boolean Lolornot;
|
||||||
private final CommandSender Lolowner;
|
private final ChromaGamerBase Lolowner;
|
||||||
private final TBMCChatEventBase Chatevent;
|
private final TBMCChatEventBase Chatevent;
|
||||||
private final long Loltime;
|
private final long Loltime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
@ -15,7 +17,6 @@ import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -55,7 +56,7 @@ public class TownyComponent extends Component<PluginMain> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Consumer<Player> handleSpiesInit(Channel channel, TellrawPart json, Function<TellrawPart, String> toJson,
|
public Consumer<Player> handleSpiesInit(Channel channel, TellrawPart json, Function<TellrawPart, String> toJson,
|
||||||
CommandSender sender, String message) {
|
ChromaGamerBase sender, String message) {
|
||||||
if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) {
|
if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) {
|
||||||
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
||||||
String jsonstr = toJson.apply(json);
|
String jsonstr = toJson.apply(json);
|
||||||
|
@ -64,7 +65,7 @@ public class TownyComponent extends Component<PluginMain> {
|
||||||
return p -> {};
|
return p -> {};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSpies(Channel channel, Player p, String jsonstr, CommandSender sender, String message) {
|
private void handleSpies(Channel channel, Player p, String jsonstr, ChromaGamerBase sender, String message) {
|
||||||
if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) {
|
if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) {
|
||||||
val res = dataSource.getResident(p.getName());
|
val res = dataSource.getResident(p.getName());
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
|
@ -79,9 +80,10 @@ public class TownyComponent extends Component<PluginMain> {
|
||||||
/**
|
/**
|
||||||
* Return the error message for the message sender if they can't send it and the score
|
* Return the error message for the message sender if they can't send it and the score
|
||||||
*/
|
*/
|
||||||
private static Channel.RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) {
|
private static Channel.RecipientTestResult checkTownNationChat(ChromaGamerBase user, boolean nationchat) {
|
||||||
if (!(sender instanceof Player))
|
if (!(user instanceof TBMCPlayerBase))
|
||||||
return new Channel.RecipientTestResult("§cYou are not a player!");
|
return new Channel.RecipientTestResult("§cYou are not a player!");
|
||||||
|
val sender = ((TBMCPlayerBase) user).getOfflinePlayer();
|
||||||
Resident resident = dataSource.getResident(sender.getName());
|
Resident resident = dataSource.getResident(sender.getName());
|
||||||
Channel.RecipientTestResult result = checkTownNationChatInternal(nationchat, resident);
|
Channel.RecipientTestResult result = checkTownNationChatInternal(nationchat, resident);
|
||||||
if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it
|
if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it
|
||||||
|
|
|
@ -7,6 +7,7 @@ import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||||
import buttondevteam.chat.components.flair.FlairComponent;
|
import buttondevteam.chat.components.flair.FlairComponent;
|
||||||
import buttondevteam.chat.components.flair.FlairStates;
|
import buttondevteam.chat.components.flair.FlairStates;
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -53,7 +54,7 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
|
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
|
||||||
|
|
||||||
if (PluginMain.Instance.storeChatHistory.get())
|
if (PluginMain.Instance.storeChatHistory.get())
|
||||||
HistoryCommand.showHistory(e.getPlayer(), null);
|
HistoryCommand.showHistory(ChromaGamerBase.getFromSender(e.getPlayer()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -10,6 +10,7 @@ import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
|
@ -81,7 +82,7 @@ public class PlayerListener implements Listener {
|
||||||
&& Bukkit.getOnlinePlayers().size() > 0) { //If there are no players on, display to the first person
|
&& Bukkit.getOnlinePlayers().size() > 0) { //If there are no players on, display to the first person
|
||||||
lastError = System.nanoTime(); //I put the whole thing in the if to protect against race conditions
|
lastError = System.nanoTime(); //I put the whole thing in the if to protect against race conditions
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
if (e.shouldSendTo(p))
|
if (e.shouldSendTo(ChromaGamerBase.getFromSender(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);
|
ChatUtils.sendChatMessage(e);
|
||||||
|
|
Loading…
Reference in a new issue