YEEHAW, small fixes (mcchat)

Working on #70
This commit is contained in:
Norbi Peti 2018-10-25 23:54:16 +02:00
parent 7d624816f2
commit a0e0890160
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 17 additions and 9 deletions

View file

@ -16,10 +16,11 @@ import java.util.Set;
public class DiscordSender extends DiscordSenderBase implements CommandSender {
private PermissibleBase perm = new PermissibleBase(this);
private String name = null;
private String name;
public DiscordSender(IUser user, IChannel channel) {
super(user, channel);
name = user == null ? "Discord user" : user.getDisplayName(DiscordPlugin.mainServer);
}
public DiscordSender(IUser user, IChannel channel, String name) {
@ -100,7 +101,7 @@ public class DiscordSender extends DiscordSenderBase implements CommandSender {
@Override
public String getName() {
return name == null ? user == null ? "Discord user" : user.getDisplayName(DiscordPlugin.mainServer) : name;
return name;
}
@Override

View file

@ -7,7 +7,6 @@ import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.ChatMessage;
import buttondevteam.lib.chat.ChatRoom;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.PlayerData;
import buttondevteam.lib.player.TBMCPlayer;
import com.vdurmont.emoji.EmojiParser;
import io.netty.util.collection.LongObjectHashMap;
@ -411,7 +410,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
return ch -> DiscordPlugin.sendMessageToChannel(ch, DPUtils.sanitizeString(message));
}
public static void forAllowedMCChat(Consumer<IChannel> action, TBMCSystemChatEvent event) { //TODO
public static void forAllowedMCChat(Consumer<IChannel> action, TBMCSystemChatEvent event) {
if (Channel.GlobalChat.ID.equals(event.getChannel().ID))
action.accept(DiscordPlugin.chatchannel);
for (LastMsgData data : lastmsgPerUser)
@ -566,8 +565,14 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
if (!ch.isPresent())
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
() -> {
val channel = dsender.getChromaUser().channel(); //TODO: Save?
val chtmp = channel.get();
if (clmd != null)
channel.set(clmd.mcchannel); //Hack to send command in the channel
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
if (clmd != null)
channel.set(chtmp);
});
else {
Channel chc = ch.get();
@ -577,7 +582,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
else {
if (spi == -1) // Switch channels
{
final PlayerData<Channel> channel = dsender.getChromaUser().channel();
val channel = dsender.getChromaUser().channel();
val oldch = channel.get();
if (oldch instanceof ChatRoom)
((ChatRoom) oldch).leaveRoom(dsender);

View file

@ -159,10 +159,12 @@ public class MCListener implements Listener {
MCChatListener.forCustomAndAllMCChat(MCChatListener.send(event.getMessage()), ChannelconBroadcast.BROADCAST, false);
}
/*@EventHandler
public void onYEEHAW(TBMCYEEHAWEvent event) {
MCChatListener.forAllowedCustomMCChat();event.getSender().getName()+" <:YEEHAW:"+DiscordPlugin.mainServer.getEmojiByName("YEEHAW").getStringID()+">s"//TODO: :YEEHAW:s - Change from broadcastMessage() in ButtonChat
}*/
@EventHandler
public void onYEEHAW(TBMCYEEHAWEvent event) { //TODO: Inherit from the chat event base to have channel support
String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName()
: event.getSender().getName();
MCChatListener.forAllMCChat(MCChatListener.send(name + " <:YEEHAW:" + DiscordPlugin.mainServer.getEmojiByName("YEEHAW").getStringID() + ">s"));
}
private static final String[] EXCLUDED_PLUGINS = {"ProtocolLib", "LibsDisguises"};