mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
Town and Nation leave detection
This commit is contained in:
1 parent
97b4b55722
commit
986fd0f271
8 files changed
+91
-43
No files matched your search
@@ -110,7 +110,7 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return channels.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatChannel getChannel(String name) {
|
public ChatChannel getChannel(String name) {
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
package net.draycia.simplechat.channels.impls;
|
package net.draycia.simplechat.channels.impls;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
|
import com.palmergames.bukkit.towny.event.NationRemoveTownEvent;
|
||||||
|
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public class AllianceChatChannel extends SimpleChatChannel {
|
public class AllianceChatChannel extends NationChatChannel {
|
||||||
|
|
||||||
public AllianceChatChannel(String name, SimpleChat simpleChat) {
|
public AllianceChatChannel(String name, SimpleChat simpleChat) {
|
||||||
super(name, simpleChat);
|
super(name, simpleChat);
|
||||||
@@ -36,32 +42,14 @@ public class AllianceChatChannel extends SimpleChatChannel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canPlayerUse(ChatUser user) {
|
|
||||||
if (super.canPlayerUse(user)) {
|
|
||||||
try {
|
|
||||||
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInTown(ChatUser user) {
|
|
||||||
try {
|
|
||||||
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAllianceChat() {
|
public boolean isAllianceChat() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNationChat() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
package net.draycia.simplechat.channels.impls;
|
package net.draycia.simplechat.channels.impls;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
|
import com.palmergames.bukkit.towny.event.NationRemoveTownEvent;
|
||||||
|
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public class NationChatChannel extends SimpleChatChannel {
|
public class NationChatChannel extends SimpleChatChannel {
|
||||||
|
|
||||||
@@ -61,15 +67,7 @@ public class NationChatChannel extends SimpleChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayerUse(ChatUser user) {
|
public boolean canPlayerUse(ChatUser user) {
|
||||||
if (super.canPlayerUse(user)) {
|
return super.canPlayerUse(user) && isInNation(user);
|
||||||
try {
|
|
||||||
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasNation();
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInNation(ChatUser user) {
|
public boolean isInNation(ChatUser user) {
|
||||||
@@ -82,6 +80,42 @@ public class NationChatChannel extends SimpleChatChannel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||||
|
String name = event.getResident().getName();
|
||||||
|
ChatUser user = getSimpleChat().getUserService().wrap(Bukkit.getOfflinePlayer(name));
|
||||||
|
|
||||||
|
if (user.getSelectedChannel().isAllianceChat()) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onNationRemoveTown(NationRemoveTownEvent event) {
|
||||||
|
for (Resident resident : event.getTown().getResidents()) {
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(resident.getName());
|
||||||
|
|
||||||
|
if (!offlinePlayer.isOnline()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatUser user = getSimpleChat().getUserService().wrap(offlinePlayer);
|
||||||
|
|
||||||
|
if (user.getSelectedChannel().isAllianceChat()) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
|
||||||
|
|
||||||
|
if (user.getSelectedChannel().isAllianceChat() && !isInNation(user)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNationChat() {
|
public boolean isNationChat() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ public class PartyChatChannel extends SimpleChatChannel implements Listener {
|
|||||||
|
|
||||||
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
|
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
|
||||||
|
|
||||||
if (user.getSelectedChannel().isPartyChat() && !isInParty(user)) {
|
if (user.getSelectedChannel().isPartyChat()) {
|
||||||
switchPlayerToDefault(user);
|
user.clearSelectedChannel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,14 +70,10 @@ public class PartyChatChannel extends SimpleChatChannel implements Listener {
|
|||||||
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
|
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
|
||||||
|
|
||||||
if (user.getSelectedChannel().isPartyChat() && !isInParty(user)) {
|
if (user.getSelectedChannel().isPartyChat() && !isInParty(user)) {
|
||||||
switchPlayerToDefault(user);
|
user.clearSelectedChannel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchPlayerToDefault(ChatUser user) {
|
|
||||||
user.setSelectedChannel(getSimpleChat().getDefaultChannel());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInParty(ChatUser user) {
|
public boolean isInParty(ChatUser user) {
|
||||||
return PartyAPI.inParty(user.asPlayer());
|
return PartyAPI.inParty(user.asPlayer());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package net.draycia.simplechat.channels.impls;
|
package net.draycia.simplechat.channels.impls;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
|
import com.palmergames.bukkit.towny.event.TownAddResidentEvent;
|
||||||
|
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public class TownChatChannel extends SimpleChatChannel {
|
public class TownChatChannel extends SimpleChatChannel {
|
||||||
|
|
||||||
@@ -77,6 +82,25 @@ public class TownChatChannel extends SimpleChatChannel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||||
|
String name = event.getResident().getName();
|
||||||
|
ChatUser user = getSimpleChat().getUserService().wrap(Bukkit.getOfflinePlayer(name));
|
||||||
|
|
||||||
|
if (user.getSelectedChannel().isTownChat()) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
|
||||||
|
|
||||||
|
if (user.getSelectedChannel().isTownChat() && !isInTown(user)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTownChat() {
|
public boolean isTownChat() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class CommandManager {
|
|||||||
throw new ConditionFailedException(simpleChat.getConfig().getString("language.town-cannot-use"));
|
throw new ConditionFailedException(simpleChat.getConfig().getString("language.town-cannot-use"));
|
||||||
} else if (value.isNationChat() && !((NationChatChannel)value).isInNation(user)) {
|
} else if (value.isNationChat() && !((NationChatChannel)value).isInNation(user)) {
|
||||||
throw new ConditionFailedException(simpleChat.getConfig().getString("language.nation-cannot-use"));
|
throw new ConditionFailedException(simpleChat.getConfig().getString("language.nation-cannot-use"));
|
||||||
} else if (value.isAllianceChat() && !((AllianceChatChannel)value).isInTown(user)) {
|
} else if (value.isAllianceChat() && !((AllianceChatChannel)value).isInNation(user)) {
|
||||||
throw new ConditionFailedException(simpleChat.getConfig().getString("language.alliance-cannot-use"));
|
throw new ConditionFailedException(simpleChat.getConfig().getString("language.alliance-cannot-use"));
|
||||||
} else if (value.isPartyChat() && !((PartyChatChannel)value).isInParty(user)) {
|
} else if (value.isPartyChat() && !((PartyChatChannel)value).isInParty(user)) {
|
||||||
throw new ConditionFailedException(simpleChat.getConfig().getString("language.party-cannot-use"));
|
throw new ConditionFailedException(simpleChat.getConfig().getString("language.party-cannot-use"));
|
||||||
@@ -107,7 +107,6 @@ public class CommandManager {
|
|||||||
manager.registerCommand(new MessageCommand(simpleChat));
|
manager.registerCommand(new MessageCommand(simpleChat));
|
||||||
manager.registerCommand(new ReplyCommand(simpleChat));
|
manager.registerCommand(new ReplyCommand(simpleChat));
|
||||||
manager.registerCommand(new MuteCommand(simpleChat));
|
manager.registerCommand(new MuteCommand(simpleChat));
|
||||||
manager.registerCommand(new ChannelColorCommand(simpleChat));
|
|
||||||
manager.registerCommand(new SetColorCommand(simpleChat));
|
manager.registerCommand(new SetColorCommand(simpleChat));
|
||||||
manager.registerCommand(new SpyChannelCommand(simpleChat));
|
manager.registerCommand(new SpyChannelCommand(simpleChat));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public interface ChatUser extends Audience {
|
|||||||
ChatChannel getSelectedChannel();
|
ChatChannel getSelectedChannel();
|
||||||
void setSelectedChannel(ChatChannel channel);
|
void setSelectedChannel(ChatChannel channel);
|
||||||
|
|
||||||
|
void clearSelectedChannel();
|
||||||
|
|
||||||
UserChannelSettings getChannelSettings(ChatChannel channel);
|
UserChannelSettings getChannelSettings(ChatChannel channel);
|
||||||
|
|
||||||
void setMuted(boolean muted);
|
void setMuted(boolean muted);
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ public class SimpleChatUser implements ChatUser, ForwardingAudience {
|
|||||||
syncToRedis();
|
syncToRedis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearSelectedChannel() {
|
||||||
|
setSelectedChannel(simpleChat.getDefaultChannel());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIgnoringUser(UUID uuid) {
|
public boolean isIgnoringUser(UUID uuid) {
|
||||||
return ignoredUsers.contains(uuid);
|
return ignoredUsers.contains(uuid);
|
||||||
|
|||||||
Reference in new issue
Block a user