diff --git a/ButtonCore/.gitignore b/ButtonCore/.gitignore
index 84dff78..86472d4 100755
--- a/ButtonCore/.gitignore
+++ b/ButtonCore/.gitignore
@@ -132,7 +132,7 @@ publish/
*.publishproj
# NuGet Packages Directory
-## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+## TO!DO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
diff --git a/ButtonCore/src/main/java/buttondevteam/core/ScheduledRestartCommand.java b/ButtonCore/src/main/java/buttondevteam/core/ScheduledRestartCommand.java
index d7ade35..6044c40 100755
--- a/ButtonCore/src/main/java/buttondevteam/core/ScheduledRestartCommand.java
+++ b/ButtonCore/src/main/java/buttondevteam/core/ScheduledRestartCommand.java
@@ -32,7 +32,7 @@ public class ScheduledRestartCommand extends TBMCCommandBase {
return false;
}
final int restarttime = restartcounter = ticks;
- restartbar = Bukkit.createBossBar("Server restart in " + ticks / 20f, BarColor.RED, BarStyle.SOLID,
+ restartbar = Bukkit.createBossBar("Server restart in " + ticks / 20f + "s", BarColor.RED, BarStyle.SOLID,
BarFlag.DARKEN_SKY);
restartbar.setProgress(1);
Bukkit.getOnlinePlayers().forEach(p -> restartbar.addPlayer(p));
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectFakeEvent.java b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectFakeEvent.java
deleted file mode 100644
index afc12cd..0000000
--- a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChannelConnectFakeEvent.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package buttondevteam.lib;
-
-import buttondevteam.lib.chat.Channel;
-import lombok.Getter;
-import org.bukkit.command.CommandSender;
-import org.bukkit.event.Cancellable;
-import org.bukkit.event.HandlerList;
-
-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 not meant to be called from any plugin - it should be only created to use the helper methods
- */
-@Getter
-public class TBMCChannelConnectFakeEvent extends TBMCChatEventBase implements Cancellable {
- private static final HandlerList handlers = new HandlerList();
-
- @Nullable
- private final CommandSender sender;
-
- /**
- * Using this the group will be determined based on the sender.
- *
- * @param sender The sender to get the group from
- * @param channel The channel to use
- */
- 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;
- }
-
- /**
- * Using this the given group will be validated and used.
- *
- * @param groupid The group to use, for example the name of a town or nation
- * @param channel The channel to use
- */
- 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;
- }
-
- @Override
- public HandlerList getHandlers() {
- return handlers;
- }
-
- public static HandlerList getHandlerList() {
- return handlers;
- }
-}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java
index 77dd9fd..14c7de9 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/TBMCChatEventBase.java
@@ -1,7 +1,6 @@
package buttondevteam.lib;
import buttondevteam.lib.chat.Channel;
-import buttondevteam.lib.chat.Channel.RecipientTestResult;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -31,20 +30,14 @@ public abstract class TBMCChatEventBase extends Event implements Cancellable {
* Note: Errors are sent to the sender automatically
*/
public boolean shouldSendTo(CommandSender sender) {
- if (channel.filteranderrormsg == null)
- return true;
- RecipientTestResult result = channel.filteranderrormsg.apply(sender);
- return result.errormessage == null && score == result.score;
+ return channel.shouldSendTo(sender, score);
}
/**
* 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;
+ return channel.getMCScore(sender);
}
/**
@@ -54,9 +47,6 @@ public abstract class TBMCChatEventBase extends Event implements Cancellable {
*/
@Nullable
public String getGroupID(CommandSender sender) {
- if (channel.filteranderrormsg == null)
- return "everyone";
- RecipientTestResult result = channel.filteranderrormsg.apply(sender);
- return result.errormessage == null ? result.groupID : null;
+ return channel.getGroupID(sender); //TODO: Performance-wise it'd be much better to use serialization for player data - it's only converted once
}
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
index a9d4d20..c18c557 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
@@ -14,6 +14,18 @@ import java.util.function.Function;
import java.util.function.Predicate;
public class Channel {
+ /**
+ * Specifies a score that means it's OK to send - but it does not define any groups, only send or not send. See {@link #GROUP_EVERYONE}
+ */
+ public static final int SCORE_SEND_OK = 0;
+ /**
+ * Specifies a score that means the user doesn't have permission to see or send the message. Any negative value has the same effect.
+ */
+ public static final int SCORE_SEND_NOPE = -1;
+ /**
+ * Send the message to everyone who has access to the channel - this does not necessarily mean all players
+ */
+ public static final String GROUP_EVERYONE = "everyone";
public final String DisplayName;
public final Color color;
public final String ID;
@@ -57,6 +69,43 @@ public class Channel {
this.filteranderrormsg = s -> filteranderrormsg.apply((T) this, s);
}
+ public boolean isGlobal() {
+ return filteranderrormsg == null;
+ }
+
+ /**
+ * Note: Errors are sent to the sender automatically
+ *
+ * @param sender The user we're sending to
+ * @param score The (source) score to compare with the user's
+ */
+ public boolean shouldSendTo(CommandSender sender, int score) {
+ return score == getMCScore(sender); //If there's any error, the score won't be equal
+ }
+
+ /**
+ * Note: Errors are sent to the sender automatically
+ */
+ public int getMCScore(CommandSender sender) {
+ if (filteranderrormsg == null)
+ return SCORE_SEND_OK;
+ RecipientTestResult result = filteranderrormsg.apply(sender);
+ return result.errormessage == null ? result.score : SCORE_SEND_NOPE;
+ }
+
+ /**
+ * Note: Errors are sent to the sender automatically
+ *
+ * Null means don't send
+ */
+ @Nullable
+ public String getGroupID(CommandSender sender) {
+ if (filteranderrormsg == null)
+ return GROUP_EVERYONE;
+ RecipientTestResult result = filteranderrormsg.apply(sender);
+ return result.errormessage == null ? result.groupID : null;
+ }
+
public static List