mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
Add contexts and towny town support
This commit is contained in:
1 parent
e111416717
commit
d5d066fcb6
15 files changed
+313
-135
No files matched your search
@@ -1,79 +0,0 @@
|
|||||||
package net.draycia.simplechatmcmmo;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.api.PartyAPI;
|
|
||||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
|
||||||
import net.draycia.simplechat.channels.impls.SimpleChatChannel;
|
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
|
|
||||||
public class PartyChatChannel extends SimpleChatChannel implements Listener {
|
|
||||||
|
|
||||||
public PartyChatChannel(String name, SimpleChat simpleChat, ConfigurationSection config) {
|
|
||||||
super(name, simpleChat, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String processPlaceholders(ChatUser user, String input) {
|
|
||||||
String partyName = PartyAPI.getPartyName(user.asPlayer());
|
|
||||||
|
|
||||||
if (partyName == null) {
|
|
||||||
partyName = "NotLoaded";
|
|
||||||
}
|
|
||||||
|
|
||||||
return input.replace("<party>", partyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying) {
|
|
||||||
if (checkSpying && target.asPlayer().hasPermission("simplechat.spy." + getName())) {
|
|
||||||
if (target.getChannelSettings(this).isSpying()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (super.canPlayerSee(sender, target, false) && sender != null) {
|
|
||||||
return PartyAPI.inSameParty(sender.asPlayer(), target.asPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean canPlayerUse(ChatUser user) {
|
|
||||||
return super.canPlayerUse(user) && isInParty(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
|
||||||
private final 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() instanceof PartyChatChannel) {
|
|
||||||
user.clearSelectedChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
ChatUser user = getSimpleChat().getUserService().wrap(event.getPlayer());
|
|
||||||
|
|
||||||
if ((user.getSelectedChannel() instanceof PartyChatChannel) && !isInParty(user)) {
|
|
||||||
user.clearSelectedChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInParty(ChatUser user) {
|
|
||||||
return PartyAPI.inParty(user.asPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package net.draycia.simplechatmcmmo;
|
package net.draycia.simplechatmcmmo;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.api.PartyAPI;
|
||||||
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class SimpleChatMCMMO extends JavaPlugin {
|
public final class SimpleChatMCMMO extends JavaPlugin {
|
||||||
@@ -14,31 +17,48 @@ public final class SimpleChatMCMMO extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
simpleChat = (SimpleChat) Bukkit.getPluginManager().getPlugin("SimpleChat");
|
simpleChat = (SimpleChat) Bukkit.getPluginManager().getPlugin("SimpleChat");
|
||||||
|
|
||||||
for (String key : getConfig().getConfigurationSection("channels").getKeys(false)) {
|
simpleChat.getContextManager().register("mcmmo-party", (context) -> {
|
||||||
ConfigurationSection section = getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
return isInSameParty(context.getSender(), context.getTarget());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ChatChannel channel = loadChannel(key, section);
|
private final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
||||||
|
private final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||||
|
|
||||||
if (channel != null) {
|
@EventHandler
|
||||||
if (simpleChat.getChannelManager().registerChannel(channel)) {
|
public void onPartyLeave(McMMOPartyChangeEvent event) {
|
||||||
getLogger().info("Registering channel: " + channel.getName());
|
if (event.getReason() != LEFT && event.getReason() != KICKED) {
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChatUser user = simpleChat.getUserService().wrap(event.getPlayer());
|
||||||
|
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
||||||
|
|
||||||
|
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatChannel loadChannel(String key, ConfigurationSection section) {
|
@EventHandler
|
||||||
ChatChannel channel = new PartyChatChannel(key, simpleChat, section);
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
ChatUser user = simpleChat.getUserService().wrap(event.getPlayer());
|
||||||
|
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
||||||
|
|
||||||
String name = section.getString("name");
|
if ((party instanceof Boolean) && ((Boolean) party) && !isInParty(user)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (name != null && name.length() > 16) {
|
public boolean isInParty(ChatUser user) {
|
||||||
getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
return PartyAPI.inParty(user.asPlayer());
|
||||||
getLogger().warning("Skipping channel, please check your settings!");
|
}
|
||||||
return null;
|
|
||||||
|
public boolean isInSameParty(ChatUser user1, ChatUser user2) {
|
||||||
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel;
|
return PartyAPI.inSameParty(user1.asPlayer(), user2.asPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
channels:
|
|
||||||
party:
|
|
||||||
name: 'Party'
|
|
||||||
aliases: 'partychat|pc'
|
|
||||||
color: '#00FF00'
|
|
||||||
formats:
|
|
||||||
default: '<color>[<white>%player_displayname%<color>] <color><pre><message>'
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.draycia.simplechat;
|
package net.draycia.simplechat;
|
||||||
|
|
||||||
|
import net.draycia.simplechat.channels.contexts.impl.DistanceContext;
|
||||||
import net.draycia.simplechat.listeners.*;
|
import net.draycia.simplechat.listeners.*;
|
||||||
import net.draycia.simplechat.managers.*;
|
import net.draycia.simplechat.managers.*;
|
||||||
import net.draycia.simplechat.storage.UserService;
|
import net.draycia.simplechat.storage.UserService;
|
||||||
@@ -24,6 +25,7 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
private RedisManager redisManager = null;
|
private RedisManager redisManager = null;
|
||||||
private AdventureManager adventureManager;
|
private AdventureManager adventureManager;
|
||||||
|
private ContextManager contextManager;
|
||||||
|
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
pluginMessageManager = new PluginMessageManager(this);
|
pluginMessageManager = new PluginMessageManager(this);
|
||||||
commandManager = new CommandManager(this);
|
commandManager = new CommandManager(this);
|
||||||
channelManager = new ChannelManager(this);
|
channelManager = new ChannelManager(this);
|
||||||
|
contextManager = new ContextManager();
|
||||||
|
|
||||||
if (getConfig().getBoolean("redis.enabled")) {
|
if (getConfig().getBoolean("redis.enabled")) {
|
||||||
redisManager = new RedisManager(this);
|
redisManager = new RedisManager(this);
|
||||||
@@ -69,6 +72,7 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
// Setup listeners
|
// Setup listeners
|
||||||
setupListeners();
|
setupListeners();
|
||||||
reloadPatterns();
|
reloadPatterns();
|
||||||
|
registerContexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -98,6 +102,10 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerContexts() {
|
||||||
|
getContextManager().register("distance", new DistanceContext());
|
||||||
|
}
|
||||||
|
|
||||||
public Permission getPermission() {
|
public Permission getPermission() {
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
@@ -129,4 +137,8 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
public AdventureManager getAdventureManager() {
|
public AdventureManager getAdventureManager() {
|
||||||
return adventureManager;
|
return adventureManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContextManager getContextManager() {
|
||||||
|
return contextManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -41,11 +41,6 @@ public abstract class ChatChannel {
|
|||||||
|
|
||||||
public abstract String getAliases();
|
public abstract String getAliases();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The distance other players must be within to the sender to see messages in this channel.
|
|
||||||
*/
|
|
||||||
public abstract Double getDistance();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message to be sent to the player when switching to this channel.
|
* @return The message to be sent to the player when switching to this channel.
|
||||||
*/
|
*/
|
||||||
@@ -73,6 +68,10 @@ public abstract class ChatChannel {
|
|||||||
|
|
||||||
public abstract Boolean firstMatchingGroup();
|
public abstract Boolean firstMatchingGroup();
|
||||||
|
|
||||||
|
public abstract boolean testContext(ChatUser sender, ChatUser target);
|
||||||
|
|
||||||
|
public abstract Object getContext(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the player can use this channel.
|
* @return If the player can use this channel.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package net.draycia.simplechat.channels.contexts;
|
||||||
|
|
||||||
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
|
||||||
|
public interface MessageContext {
|
||||||
|
ChatUser getSender();
|
||||||
|
ChatUser getTarget();
|
||||||
|
ChatChannel getChatChannel();
|
||||||
|
Object getValue();
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package net.draycia.simplechat.channels.contexts.impl;
|
||||||
|
|
||||||
|
import net.draycia.simplechat.channels.contexts.MessageContext;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean apply(MessageContext context) {
|
||||||
|
if (!context.getSender().isOnline() || !context.getTarget().isOnline()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location senderLocation = context.getSender().asPlayer().getLocation();
|
||||||
|
Location targetLocation = context.getTarget().asPlayer().getLocation();
|
||||||
|
|
||||||
|
if (!senderLocation.getWorld().equals(targetLocation.getWorld())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Double value = (Double) context.getValue();
|
||||||
|
|
||||||
|
if (value > 0) {
|
||||||
|
return senderLocation.distance(targetLocation) <= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package net.draycia.simplechat.channels.contexts.impl;
|
||||||
|
|
||||||
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
|
import net.draycia.simplechat.channels.contexts.MessageContext;
|
||||||
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
|
||||||
|
public class SimpleMessageContext implements MessageContext {
|
||||||
|
private final ChatUser sender;
|
||||||
|
private final ChatUser target;
|
||||||
|
private final ChatChannel chatChannel;
|
||||||
|
private final Object value;
|
||||||
|
|
||||||
|
public SimpleMessageContext(ChatUser sender, ChatUser target, ChatChannel chatChannel, Object value) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.target = target;
|
||||||
|
this.chatChannel = chatChannel;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatUser getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatUser getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatChannel getChatChannel() {
|
||||||
|
return chatChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
-24
@@ -4,6 +4,7 @@ import net.draycia.simplechat.SimpleChat;
|
|||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.events.ChatComponentEvent;
|
import net.draycia.simplechat.events.ChatComponentEvent;
|
||||||
import net.draycia.simplechat.events.ChatFormatEvent;
|
import net.draycia.simplechat.events.ChatFormatEvent;
|
||||||
|
import net.draycia.simplechat.managers.ContextManager;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
@@ -34,6 +35,11 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return simpleChat;
|
return simpleChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean testContext(ChatUser sender, ChatUser target) {
|
||||||
|
return simpleChat.getContextManager().testContext(sender, target, this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean canPlayerUse(ChatUser user) {
|
public Boolean canPlayerUse(ChatUser user) {
|
||||||
return user.asPlayer().hasPermission("simplechat.channels." + getName() + ".use");
|
return user.asPlayer().hasPermission("simplechat.channels." + getName() + ".use");
|
||||||
@@ -207,25 +213,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.isOnline()) {
|
|
||||||
if (getDistance() == 0) {
|
|
||||||
if (!targetPlayer.getWorld().equals(sender.asPlayer().getWorld())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (getDistance() > 0) {
|
|
||||||
Location one = targetPlayer.getLocation();
|
|
||||||
Location two = sender.asPlayer().getLocation();
|
|
||||||
|
|
||||||
if (!one.getWorld().equals(two.getWorld())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (one.distance(two) > getDistance()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isIgnorable()) {
|
if (isIgnorable()) {
|
||||||
if (target.isIgnoringUser(sender) && !targetPlayer.hasPermission("simplechat.ignore.exempt")) {
|
if (target.isIgnoringUser(sender) && !targetPlayer.hasPermission("simplechat.ignore.exempt")) {
|
||||||
return false;
|
return false;
|
||||||
@@ -287,11 +274,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return name == null ? key : name;
|
return name == null ? key : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Double getDistance() {
|
|
||||||
return getDouble("distance");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSwitchMessage() {
|
public String getSwitchMessage() {
|
||||||
return getString("switch-message");
|
return getString("switch-message");
|
||||||
@@ -348,6 +330,29 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return itemPatterns;
|
return itemPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getContext(String key) {
|
||||||
|
ConfigurationSection section = config.getConfigurationSection("contexts");
|
||||||
|
|
||||||
|
if (section == null) {
|
||||||
|
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
||||||
|
|
||||||
|
if (defaultSection == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationSection defaultContexts = defaultSection.getConfigurationSection("contexts");
|
||||||
|
|
||||||
|
if (defaultContexts == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultContexts.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return section.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
private String getString(String key) {
|
private String getString(String key) {
|
||||||
if (config != null && config.contains(key)) {
|
if (config != null && config.contains(key)) {
|
||||||
return config.getString(key);
|
return config.getString(key);
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package net.draycia.simplechat.managers;
|
||||||
|
|
||||||
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
|
import net.draycia.simplechat.channels.contexts.MessageContext;
|
||||||
|
import net.draycia.simplechat.channels.contexts.impl.SimpleMessageContext;
|
||||||
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ContextManager {
|
||||||
|
|
||||||
|
private final Map<String, Function<MessageContext, Boolean>> handlers = new HashMap<>();
|
||||||
|
|
||||||
|
public boolean register(String key, Function<MessageContext, Boolean> handler) {
|
||||||
|
if (this.handlers.containsKey(key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handlers.put(key, handler);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean testContext(ChatUser user, ChatUser target, ChatChannel channel) {
|
||||||
|
for (Map.Entry<String, Function<MessageContext, Boolean>> handler : handlers.entrySet()) {
|
||||||
|
String key = handler.getKey();
|
||||||
|
|
||||||
|
Object value = channel.getContext(key);
|
||||||
|
|
||||||
|
if (value == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageContext context = new SimpleMessageContext(user, target, channel, value);
|
||||||
|
|
||||||
|
return handler.getValue().apply(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,12 +21,15 @@ default:
|
|||||||
# Also supports PlaceholderAPI
|
# Also supports PlaceholderAPI
|
||||||
staff: '<gray>{[%vault_prefix%<gray>]} %player_displayname% <gray>» <color><pre><message>'
|
staff: '<gray>{[%vault_prefix%<gray>]} %player_displayname% <gray>» <color><pre><message>'
|
||||||
default: '<gray>[%vault_prefix%<gray>] %player_displayname%<gray>: <color><pre><message>'
|
default: '<gray>[%vault_prefix%<gray>] %player_displayname%<gray>: <color><pre><message>'
|
||||||
|
contexts:
|
||||||
|
distance: -1 # -1 to disable, 0 to set to world, 1+ to fully enable
|
||||||
|
# mcmmo-party only works when the SiumpleChatMCMMO addon is installed.
|
||||||
|
# Requires both players to be in the same party to see the message.
|
||||||
|
mcmmo-party: false
|
||||||
color: '#FFFFFF'
|
color: '#FFFFFF'
|
||||||
# Can players /toggle this channel and hide its messages?
|
# Can players /toggle this channel and hide its messages?
|
||||||
ignorable: true
|
ignorable: true
|
||||||
# -1 = disabled, 0 = world chat, greater than 0 = enabled
|
# -1 = disabled, 0 = world chat, greater than 0 = enabled
|
||||||
distance: -1
|
|
||||||
# Forces all other servers to use this server's formatting for this channel
|
|
||||||
forward-format: true
|
forward-format: true
|
||||||
# Enables/disables cross server chat for this channel
|
# Enables/disables cross server chat for this channel
|
||||||
should-bungee: true
|
should-bungee: true
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
|
||||||
|
maven { url = "https://jitpack.io" }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT'
|
||||||
|
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||||
|
|
||||||
|
api project(':SimpleChat')
|
||||||
|
}
|
||||||
|
|
||||||
|
description = 'SimpleChatTowny'
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package net.draycia.simplechattowny;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
|
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import net.draycia.simplechat.SimpleChat;
|
||||||
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public final class SimpleChatTowny extends JavaPlugin {
|
||||||
|
|
||||||
|
private SimpleChat simpleChat;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
simpleChat = (SimpleChat) Bukkit.getPluginManager().getPlugin("SimpleChat");
|
||||||
|
|
||||||
|
simpleChat.getContextManager().register("towny-town", (context) -> {
|
||||||
|
return isInSameTown(context.getSender(), context.getTarget());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||||
|
String name = event.getResident().getName();
|
||||||
|
ChatUser user = simpleChat.getUserService().wrap(Bukkit.getOfflinePlayer(name));
|
||||||
|
Object town = user.getSelectedChannel().getContext("towny-town");
|
||||||
|
|
||||||
|
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
ChatUser user = simpleChat.getUserService().wrap(event.getPlayer());
|
||||||
|
Object town = user.getSelectedChannel().getContext("towny-town");
|
||||||
|
|
||||||
|
if ((town instanceof Boolean) && ((Boolean) town) && !isInTown(user)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInTown(ChatUser user) {
|
||||||
|
try {
|
||||||
|
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInSameTown(ChatUser user1, ChatUser user2) {
|
||||||
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.asPlayer().getName());
|
||||||
|
|
||||||
|
if (resident.hasTown()) {
|
||||||
|
return resident.getTown().hasResident(user2.asPlayer().getName());
|
||||||
|
}
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
name: SimpleChatTowny
|
||||||
|
version: ${project.version}
|
||||||
|
main: net.draycia.simplechatmcmmo.SimpleChatTowny
|
||||||
|
api-version: 1.16
|
||||||
|
depend: [SimpleChat]
|
||||||
@@ -3,7 +3,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
rootProject.name = 'SimpleChatParent'
|
rootProject.name = 'SimpleChatParent'
|
||||||
|
|
||||||
include(':SimpleChat')
|
include(':SimpleChat')
|
||||||
|
|
||||||
include(':SimpleChatModeration')
|
include(':SimpleChatModeration')
|
||||||
include(':SimpleChatMCMMO')
|
include(':SimpleChatMCMMO')
|
||||||
|
include(':SimpleChatTowny')
|
||||||
|
|
||||||
project(':SimpleChat').projectDir = file('SimpleChatPlugin')
|
project(':SimpleChat').projectDir = file('SimpleChatPlugin')
|
||||||
Reference in new issue
Block a user