Add better channel switch failure messages

This commit is contained in:
Draycia committed 2020-07-10 01:27:16 -07:00
1 parent 6ca2b9c4c8
commit c351aa5e48
9 files changed
+69 -25

No files matched your search

@@ -4,12 +4,7 @@ import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
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 java.util.HashMap;
import java.util.Map;
public class AllianceChatChannel extends SimpleChatChannel {
@@ -54,6 +49,16 @@ public class AllianceChatChannel extends SimpleChatChannel {
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
public boolean isAllianceChat() {
return true;
@@ -5,12 +5,7 @@ import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
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 java.util.HashMap;
import java.util.Map;
public class NationChatChannel extends SimpleChatChannel {
@@ -77,6 +72,16 @@ public class NationChatChannel extends SimpleChatChannel {
return false;
}
public boolean isInNation(ChatUser user) {
try {
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasNation();
} catch (NotRegisteredException e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean isNationChat() {
return true;
@@ -2,12 +2,7 @@ package net.draycia.simplechat.channels.impls;
import com.gmail.nossr50.api.PartyAPI;
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 java.util.HashMap;
import java.util.Map;
public class PartyChatChannel extends SimpleChatChannel {
@@ -50,6 +45,10 @@ public class PartyChatChannel extends SimpleChatChannel {
return false;
}
public boolean isInParty(ChatUser user) {
return PartyAPI.inParty(user.asPlayer());
}
@Override
public boolean isPartyChat() {
return true;
@@ -4,12 +4,7 @@ import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
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 java.util.HashMap;
import java.util.Map;
public class TownChatChannel extends SimpleChatChannel {
@@ -72,6 +67,16 @@ public class TownChatChannel extends SimpleChatChannel {
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
public boolean isTownChat() {
return true;
@@ -1,9 +1,14 @@
package net.draycia.simplechat.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.ConditionFailedException;
import co.aikar.commands.annotation.*;
import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.channels.impls.AllianceChatChannel;
import net.draycia.simplechat.channels.impls.NationChatChannel;
import net.draycia.simplechat.channels.impls.PartyChatChannel;
import net.draycia.simplechat.channels.impls.TownChatChannel;
import net.draycia.simplechat.storage.ChatUser;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
@@ -26,8 +31,17 @@ public class AliasedChannelCommand extends BaseCommand {
ChatUser user = simpleChat.getUserService().wrap(player);
if (!chatChannel.canPlayerUse(user)) {
// TODO: send message
return;
if (chatChannel.isTownChat() && !((TownChatChannel)chatChannel).isInTown(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("language.town-cannot-use"));
} else if (chatChannel.isNationChat() && !((NationChatChannel)chatChannel).isInNation(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("language.nation-cannot-use"));
} else if (chatChannel.isAllianceChat() && !((AllianceChatChannel)chatChannel).isInTown(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("alliance-cannot-use"));
} else if (chatChannel.isPartyChat() && !((PartyChatChannel)chatChannel).isInParty(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("party-cannot-use"));
} else {
throw new ConditionFailedException(simpleChat.getConfig().getString("cannot-use-channel"));
}
}
if (args == null || args.length == 0) {
@@ -7,7 +7,6 @@ import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.storage.ChatUser;
import net.draycia.simplechat.storage.UserChannelSettings;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
@@ -6,7 +6,6 @@ import net.kyori.adventure.text.TextComponent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.scoreboard.ScoreboardManager;
import java.util.regex.Pattern;
@@ -3,6 +3,10 @@ package net.draycia.simplechat.managers;
import co.aikar.commands.*;
import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.channels.impls.AllianceChatChannel;
import net.draycia.simplechat.channels.impls.NationChatChannel;
import net.draycia.simplechat.channels.impls.PartyChatChannel;
import net.draycia.simplechat.channels.impls.TownChatChannel;
import net.draycia.simplechat.commands.*;
import net.draycia.simplechat.storage.ChatUser;
import org.bukkit.Bukkit;
@@ -69,7 +73,17 @@ public class CommandManager {
ChatUser user = simpleChat.getUserService().wrap(context.getIssuer().getPlayer());
if (!value.canPlayerUse(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("language.cannot-use-channel"));
if (value.isTownChat() && !((TownChatChannel)value).isInTown(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("language.town-cannot-use"));
} else if (value.isNationChat() && !((NationChatChannel)value).isInNation(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("language.nation-cannot-use"));
} else if (value.isAllianceChat() && !((AllianceChatChannel)value).isInTown(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("alliance-cannot-use"));
} else if (value.isPartyChat() && !((PartyChatChannel)value).isInParty(user)) {
throw new ConditionFailedException(simpleChat.getConfig().getString("party-cannot-use"));
} else {
throw new ConditionFailedException(simpleChat.getConfig().getString("cannot-use-channel"));
}
}
});