diff --git a/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g4519d5f_237.xml b/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g4519d5f_237.xml
deleted file mode 100644
index dc72500..0000000
--- a/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g4519d5f_237.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml b/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml
index dbefdef..8ae748d 100644
--- a/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml
+++ b/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml
@@ -1,13 +1,13 @@
-
+
-
+
-
+
\ No newline at end of file
diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml
index 4902d56..9cd800b 100644
--- a/BuildConfigUpdater/BuildConfigUpdater.iml
+++ b/BuildConfigUpdater/BuildConfigUpdater.iml
@@ -13,6 +13,7 @@
+
diff --git a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java
index 0d04f52..2bb22cc 100755
--- a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java
+++ b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java
@@ -51,9 +51,9 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onSystemChat(TBMCSystemChatEvent event) {
- if (event.isHandled())
- return; // Only handle here if ButtonChat couldn't
- Bukkit.getOnlinePlayers().stream().filter(p -> event.shouldSendTo(p))
- .forEach(p -> p.sendMessage(event.getChannel().DisplayName.substring(0, 2) + event.getMessage()));
- }
+ if (event.isHandled())
+ return; // Only handle here if ButtonChat couldn't
+ Bukkit.getOnlinePlayers().stream().filter(p -> event.shouldSendTo(p))
+ .forEach(p -> p.sendMessage(event.getChannel().DisplayName.substring(0, 2) + event.getMessage()));
+ }
}
\ No newline at end of file
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectEvent.java b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectFakeEvent.java
similarity index 69%
rename from ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectEvent.java
rename to ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectFakeEvent.java
index 28e120e..afc12cd 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectEvent.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectFakeEvent.java
@@ -2,7 +2,6 @@ package buttondevteam.lib;
import buttondevteam.lib.chat.Channel;
import lombok.Getter;
-import lombok.Setter;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@@ -12,18 +11,14 @@ import javax.annotation.Nullable;
/**
* The purpose of this event is to determine which group the given channel belongs to
* or to validate that they have access to the given group chat.
- * It's mainly meant to be called from DiscordPlugin and listened for in ButtonChat
- * and the groups are towns/nations.
+ * It's not meant to be called from any plugin - it should be only created to use the helper methods
*/
@Getter
-public class TBMCChannelConnectEvent extends TBMCChatEventBase implements Cancellable {
+public class TBMCChannelConnectFakeEvent extends TBMCChatEventBase implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Nullable
private final CommandSender sender;
- @Nullable
- @Setter
- private String groupid; //Town name etc.
/**
* Using this the group will be determined based on the sender.
@@ -31,8 +26,8 @@ public class TBMCChannelConnectEvent extends TBMCChatEventBase implements Cancel
* @param sender The sender to get the group from
* @param channel The channel to use
*/
- public TBMCChannelConnectEvent(CommandSender sender, Channel channel) {
- super(channel, "Channel connecting message. One of the things users should never see in action.", -1);
+ public TBMCChannelConnectFakeEvent(CommandSender sender, Channel channel) {
+ super(channel, "Channel connecting message. One of the things users should never see in action.", -1, null);
this.sender = sender;
}
@@ -42,9 +37,8 @@ public class TBMCChannelConnectEvent extends TBMCChatEventBase implements Cancel
* @param groupid The group to use, for example the name of a town or nation
* @param channel The channel to use
*/
- public TBMCChannelConnectEvent(String groupid, Channel channel) {
- super(channel, "Channel connecting message. One of the things users should never see in action.", -1);
- this.groupid = groupid;
+ public TBMCChannelConnectFakeEvent(String groupid, Channel channel) {
+ super(channel, "Channel connecting message. One of the things users should never see in action.", -1, groupid);
this.sender = null;
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEvent.java b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEvent.java
index 6be9825..0dab094 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEvent.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEvent.java
@@ -13,8 +13,8 @@ import org.bukkit.event.HandlerList;
*/
@Getter
public class TBMCChatEvent extends TBMCChatEventBase {
- public TBMCChatEvent(CommandSender sender, Channel channel, String message, int score, boolean fromcmd) {
- super(channel, message, score);
+ public TBMCChatEvent(CommandSender sender, Channel channel, String message, int score, boolean fromcmd, String groupid) {
+ super(channel, message, score, groupid);
this.sender = sender;
this.fromcmd = fromcmd;
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java
index 249230c..9265b0c 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java
@@ -10,13 +10,22 @@ import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
+import javax.annotation.Nullable;
+
@Getter
@RequiredArgsConstructor
public abstract class TBMCChatEventBase extends Event implements Cancellable {
private final Channel channel;
private @NonNull String message;
private @Setter boolean cancelled;
- private final int score;
+ /**
+ * The sender's score.
+ */
+ private final int score;
+ /**
+ * The sender's group ID.
+ */
+ private final String groupID;
/**
* Note: Errors are sent to the sender automatically
@@ -31,10 +40,21 @@ public abstract class TBMCChatEventBase extends Event implements Cancellable {
/**
* Note: Errors are sent to the sender automatically
*/
- public int getMCScore(CommandSender sender) {
- if (channel.filteranderrormsg == null)
- return 0;
- RecipientTestResult result = channel.filteranderrormsg.apply(sender);
- return result.errormessage == null ? result.score : -1;
- }
+ public int getMCScore(CommandSender sender) {
+ if (channel.filteranderrormsg == null)
+ return 0;
+ RecipientTestResult result = channel.filteranderrormsg.apply(sender);
+ return result.errormessage == null ? result.score : -1;
+ }
+
+ /**
+ * Note: Errors are sent to the sender automatically
+ */
+ @Nullable
+ public String getGroupID(CommandSender sender) {
+ if (channel.filteranderrormsg == null)
+ return null;
+ RecipientTestResult result = channel.filteranderrormsg.apply(sender);
+ return result.errormessage == null ? result.groupID : null;
+ }
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/TBMCSystemChatEvent.java b/ButtonCore/src/main/java/buttondevteam/lib/TBMCSystemChatEvent.java
index 81d82d4..c81c16e 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/TBMCSystemChatEvent.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/TBMCSystemChatEvent.java
@@ -19,8 +19,8 @@ public class TBMCSystemChatEvent extends TBMCChatEventBase {
handled = true;
}
- public TBMCSystemChatEvent(Channel channel, String message, int score) { // TODO: RIch message
- super(channel, message, score);
+ public TBMCSystemChatEvent(Channel channel, String message, int score, String groupid) { // TODO: Rich message
+ super(channel, message, score, groupid);
}
private static final HandlerList handlers = new HandlerList();
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
index a7b2c2d..c37c3b9 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
@@ -77,12 +77,12 @@ public class Channel {
public static Function noScoreResult(Predicate filter,
String errormsg) {
- return s -> filter.test(s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg);
+ return s -> filter.test(s) ? new RecipientTestResult(0, "everyone") : new RecipientTestResult(errormsg);
}
public static BiFunction noScoreResult(
BiPredicate filter, String errormsg) {
- return (this_, s) -> filter.test(this_, s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg);
+ return (this_, s) -> filter.test(this_, s) ? new RecipientTestResult(0, "everyone") : new RecipientTestResult(errormsg);
}
public static Channel GlobalChat;
@@ -97,6 +97,7 @@ public class Channel {
public static class RecipientTestResult {
public String errormessage = null;
public int score = -1; // Anything below 0 is "never send"
+ public String groupID = null;
/**
* Creates a result that indicates an error
@@ -111,9 +112,11 @@ public class Channel {
* Creates a result that indicates a success
*
* @param score The score that identifies the target group. For example, the index of the town or nation to send to.
+ * @param groupID The ID of the target group.
*/
- public RecipientTestResult(int score) {
+ public RecipientTestResult(int score, String groupID) {
this.score = score;
+ this.groupID = groupID;
}
}
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatRoom.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatRoom.java
index f037936..dcd88b7 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatRoom.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatRoom.java
@@ -15,11 +15,11 @@ public class ChatRoom extends Channel {
public void joinRoom(CommandSender sender) {
usersInRoom.add(sender);
- TBMCChatAPI.SendSystemMessage(this, 0, sender.getName() + " joined the room");
+ TBMCChatAPI.SendSystemMessage(this, 0, "everyone", sender.getName() + " joined the room");
}
public void leaveRoom(CommandSender sender) {
usersInRoom.remove(sender);
- TBMCChatAPI.SendSystemMessage(this, 0, sender.getName() + " left the room");
+ TBMCChatAPI.SendSystemMessage(this, 0, "everyone", sender.getName() + " left the room");
}
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java
index 3dbcf76..2a5762c 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java
@@ -221,7 +221,8 @@ public class TBMCChatAPI {
}
/**
- * Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
+ * Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
+ * This will also send the error message to the sender, if they can't send the message.
*
* @param channel The channel to send to
* @param sender The sender to send from
@@ -236,10 +237,11 @@ public class TBMCChatAPI {
Bukkit.getPluginManager().callEvent(eventPre);
if (eventPre.isCancelled())
return true;
- int score = getScoreOrSendError(channel, sender);
- if (score == -1)
+ RecipientTestResult rtr = getScoreOrSendError(channel, sender);
+ int score = rtr.score;
+ if (score == -1 || rtr.groupID == null)
return true;
- TBMCChatEvent event = new TBMCChatEvent(sender, channel, eventPre.getMessage(), score, fromcommand);
+ TBMCChatEvent event = new TBMCChatEvent(sender, channel, eventPre.getMessage(), score, fromcommand, rtr.groupID);
Bukkit.getPluginManager().callEvent(event);
return event.isCancelled();
}
@@ -255,27 +257,23 @@ public class TBMCChatAPI {
* The message to send
* @return The event cancelled state
*/
- public static boolean SendSystemMessage(Channel channel, int score, String message) {
+ public static boolean SendSystemMessage(Channel channel, int score, String groupid, String message) {
if (!Channel.getChannels().contains(channel))
throw new RuntimeException("Channel " + channel.DisplayName + " not registered!");
- TBMCSystemChatEvent event = new TBMCSystemChatEvent(channel, message, score);
+ TBMCSystemChatEvent event = new TBMCSystemChatEvent(channel, message, score, groupid);
Bukkit.getPluginManager().callEvent(event);
return event.isCancelled();
}
- private static int getScoreOrSendError(Channel channel, CommandSender sender) {
- int score;
+ private static RecipientTestResult getScoreOrSendError(Channel channel, CommandSender sender) {
if (channel.filteranderrormsg == null)
- score = 0;
+ return new RecipientTestResult(0, "everyone");
else {
RecipientTestResult result = channel.filteranderrormsg.apply(sender);
- if (result.errormessage != null) {
+ if (result.errormessage != null)
sender.sendMessage("§c" + result.errormessage);
- return -1;
- }
- score = result.score;
+ return result;
}
- return score;
}
/**