Bug fixes & party leave detection

This commit is contained in:
Draycia committed 2020-07-10 21:54:29 -07:00
1 parent dc9617974f
commit 97b4b55722
5 files changed
+42 -38

No files matched your search

@@ -1,10 +1,14 @@
package net.draycia.simplechat.channels.impls;
import com.gmail.nossr50.api.PartyAPI;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.storage.ChatUser;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PartyChatChannel extends SimpleChatChannel {
public class PartyChatChannel extends SimpleChatChannel implements Listener {
public PartyChatChannel(String name, SimpleChat simpleChat) {
super(name, simpleChat);
@@ -45,6 +49,35 @@ public class PartyChatChannel extends SimpleChatChannel {
return false;
}
private McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
private McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
@EventHandler
public void onPartyLeave(McMMOPartyChangeEvent event) {
if (event.getReason() != LEFT && event.getReason() != KICKED) {
return;
}
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
if (user.getSelectedChannel().isPartyChat() && !isInParty(user)) {
switchPlayerToDefault(user);
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
if (user.getSelectedChannel().isPartyChat() && !isInParty(user)) {
switchPlayerToDefault(user);
}
}
private void switchPlayerToDefault(ChatUser user) {
user.setSelectedChannel(getSimpleChat().getDefaultChannel());
}
public boolean isInParty(ChatUser user) {
return PartyAPI.inParty(user.asPlayer());
}
@@ -243,7 +243,7 @@ public class SimpleChatChannel extends ChatChannel {
}
if (isIgnorable()) {
if (target.isIgnoringUser(sender) && !targetPlayer.hasPermission("simplechat.ignoreexempt")) {
if (target.isIgnoringUser(sender) && !targetPlayer.hasPermission("simplechat.ignore.exempt")) {
return false;
}
@@ -1,32 +0,0 @@
package net.draycia.simplechat.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.storage.ChatUser;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.entity.Player;
@CommandAlias("chcolor|channelcolor")
@CommandPermission("simplechat.setcolor")
public class ChannelColorCommand extends BaseCommand {
private SimpleChat simpleChat;
public ChannelColorCommand(SimpleChat simpleChat) {
this.simpleChat = simpleChat;
}
@Default
@CommandCompletion("@chatchannel @chatcolors")
public void baseCommand(Player player, ChatChannel chatChannel, String color) {
ChatUser user = simpleChat.getUserService().wrap(player);
user.getChannelSettings(chatChannel).setColor(TextColor.fromHexString(color));
}
}
@@ -1,10 +1,7 @@
package net.draycia.simplechat.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.*;
import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.storage.ChatUser;
@@ -13,6 +10,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
@CommandAlias("spych|spychannel|spy")
@CommandPermission("simplechat.spy")
public class SpyChannelCommand extends BaseCommand {
private SimpleChat simpleChat;
@@ -7,6 +7,7 @@ import net.draycia.simplechat.channels.impls.*;
import net.draycia.simplechat.commands.AliasedChannelCommand;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.Listener;
public class ChannelManager {
@@ -82,6 +83,10 @@ public class ChannelManager {
commandManager.getCommandReplacements().addReplacement("channelName", commandName);
commandManager.registerCommand(new AliasedChannelCommand(simpleChat, channel));
if (channel instanceof Listener) {
Bukkit.getPluginManager().registerEvents((Listener)channel, simpleChat);
}
}
boolean townyInstalled = Bukkit.getPluginManager().isPluginEnabled("Towny");