Channel connect fixes
Group ID is now required
This commit is contained in:
parent
c94eaebf5a
commit
a691278ea9
11 changed files with 66 additions and 63 deletions
|
@ -1,13 +0,0 @@
|
||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: com.github.TBMCPlugins.ButtonCore:Towny:master-v1.0-g4519d5f-237">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/com/github/TBMCPlugins/ButtonCore/Towny/master-v1.0-g4519d5f-237/Towny-master-v1.0-g4519d5f-237.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/com/github/TBMCPlugins/ButtonCore/Towny/master-v1.0-g4519d5f-237/Towny-master-v1.0-g4519d5f-237-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/com/github/TBMCPlugins/ButtonCore/Towny/master-v1.0-g4519d5f-237/Towny-master-v1.0-g4519d5f-237-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
|
@ -1,13 +1,13 @@
|
||||||
<component name="libraryTable">
|
<component name="libraryTable">
|
||||||
<library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT">
|
<library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180513.014306-84.jar!/" />
|
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180607.053457-86.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC>
|
<JAVADOC>
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180513.014306-84-javadoc.jar!/" />
|
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180607.053457-86-javadoc.jar!/" />
|
||||||
</JAVADOC>
|
</JAVADOC>
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180513.014306-84-sources.jar!/" />
|
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180607.053457-86-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
|
@ -13,6 +13,7 @@
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
|
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
|
||||||
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
|
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
|
||||||
|
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
|
||||||
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
|
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
|
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
|
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
|
||||||
|
|
|
@ -2,7 +2,6 @@ package buttondevteam.lib;
|
||||||
|
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
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
|
* 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.<br>
|
* or to validate that they have access to the given group chat.<br>
|
||||||
* It's mainly meant to be called from DiscordPlugin and listened for in ButtonChat
|
* It's not meant to be called from any plugin - it should be only created to use the helper methods
|
||||||
* and the groups are towns/nations.
|
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class TBMCChannelConnectEvent extends TBMCChatEventBase implements Cancellable {
|
public class TBMCChannelConnectFakeEvent extends TBMCChatEventBase implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
@Nullable
|
|
||||||
@Setter
|
|
||||||
private String groupid; //Town name etc.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Using this the group will be determined based on the sender.
|
* 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 sender The sender to get the group from
|
||||||
* @param channel The channel to use
|
* @param channel The channel to use
|
||||||
*/
|
*/
|
||||||
public TBMCChannelConnectEvent(CommandSender sender, Channel channel) {
|
public TBMCChannelConnectFakeEvent(CommandSender sender, Channel channel) {
|
||||||
super(channel, "Channel connecting message. One of the things users should never see in action.", -1);
|
super(channel, "Channel connecting message. One of the things users should never see in action.", -1, null);
|
||||||
this.sender = sender;
|
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 groupid The group to use, for example the name of a town or nation
|
||||||
* @param channel The channel to use
|
* @param channel The channel to use
|
||||||
*/
|
*/
|
||||||
public TBMCChannelConnectEvent(String groupid, Channel channel) {
|
public TBMCChannelConnectFakeEvent(String groupid, Channel channel) {
|
||||||
super(channel, "Channel connecting message. One of the things users should never see in action.", -1);
|
super(channel, "Channel connecting message. One of the things users should never see in action.", -1, groupid);
|
||||||
this.groupid = groupid;
|
|
||||||
this.sender = null;
|
this.sender = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ import org.bukkit.event.HandlerList;
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class TBMCChatEvent extends TBMCChatEventBase {
|
public class TBMCChatEvent extends TBMCChatEventBase {
|
||||||
public TBMCChatEvent(CommandSender sender, Channel channel, String message, int score, boolean fromcmd) {
|
public TBMCChatEvent(CommandSender sender, Channel channel, String message, int score, boolean fromcmd, String groupid) {
|
||||||
super(channel, message, score);
|
super(channel, message, score, groupid);
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.fromcmd = fromcmd;
|
this.fromcmd = fromcmd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,22 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public abstract class TBMCChatEventBase extends Event implements Cancellable {
|
public abstract class TBMCChatEventBase extends Event implements Cancellable {
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
private @NonNull String message;
|
private @NonNull String message;
|
||||||
private @Setter boolean cancelled;
|
private @Setter boolean cancelled;
|
||||||
|
/**
|
||||||
|
* The sender's score.
|
||||||
|
*/
|
||||||
private final int score;
|
private final int score;
|
||||||
|
/**
|
||||||
|
* The sender's group ID.
|
||||||
|
*/
|
||||||
|
private final String groupID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: Errors are sent to the sender automatically
|
* Note: Errors are sent to the sender automatically
|
||||||
|
@ -37,4 +46,15 @@ public abstract class TBMCChatEventBase extends Event implements Cancellable {
|
||||||
RecipientTestResult result = channel.filteranderrormsg.apply(sender);
|
RecipientTestResult result = channel.filteranderrormsg.apply(sender);
|
||||||
return result.errormessage == null ? result.score : -1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ public class TBMCSystemChatEvent extends TBMCChatEventBase {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TBMCSystemChatEvent(Channel channel, String message, int score) { // TODO: RIch message
|
public TBMCSystemChatEvent(Channel channel, String message, int score, String groupid) { // TODO: Rich message
|
||||||
super(channel, message, score);
|
super(channel, message, score, groupid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
|
@ -77,12 +77,12 @@ public class Channel {
|
||||||
|
|
||||||
public static Function<CommandSender, RecipientTestResult> noScoreResult(Predicate<CommandSender> filter,
|
public static Function<CommandSender, RecipientTestResult> noScoreResult(Predicate<CommandSender> filter,
|
||||||
String errormsg) {
|
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 <T extends Channel> BiFunction<T, CommandSender, RecipientTestResult> noScoreResult(
|
public static <T extends Channel> BiFunction<T, CommandSender, RecipientTestResult> noScoreResult(
|
||||||
BiPredicate<T, CommandSender> filter, String errormsg) {
|
BiPredicate<T, CommandSender> 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;
|
public static Channel GlobalChat;
|
||||||
|
@ -97,6 +97,7 @@ public class Channel {
|
||||||
public static class RecipientTestResult {
|
public static class RecipientTestResult {
|
||||||
public String errormessage = null;
|
public String errormessage = null;
|
||||||
public int score = -1; // Anything below 0 is "never send"
|
public int score = -1; // Anything below 0 is "never send"
|
||||||
|
public String groupID = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a result that indicates an <b>error</b>
|
* Creates a result that indicates an <b>error</b>
|
||||||
|
@ -111,9 +112,11 @@ public class Channel {
|
||||||
* Creates a result that indicates a <b>success</b>
|
* Creates a result that indicates a <b>success</b>
|
||||||
*
|
*
|
||||||
* @param score The score that identifies the target group. For example, the index of the town or nation to send to.
|
* @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.score = score;
|
||||||
|
this.groupID = groupID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ public class ChatRoom extends Channel {
|
||||||
|
|
||||||
public void joinRoom(CommandSender sender) {
|
public void joinRoom(CommandSender sender) {
|
||||||
usersInRoom.add(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) {
|
public void leaveRoom(CommandSender sender) {
|
||||||
usersInRoom.remove(sender);
|
usersInRoom.remove(sender);
|
||||||
TBMCChatAPI.SendSystemMessage(this, 0, sender.getName() + " left the room");
|
TBMCChatAPI.SendSystemMessage(this, 0, "everyone", sender.getName() + " left the room");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)}.<br>
|
||||||
|
* 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 channel The channel to send to
|
||||||
* @param sender The sender to send from
|
* @param sender The sender to send from
|
||||||
|
@ -236,10 +237,11 @@ public class TBMCChatAPI {
|
||||||
Bukkit.getPluginManager().callEvent(eventPre);
|
Bukkit.getPluginManager().callEvent(eventPre);
|
||||||
if (eventPre.isCancelled())
|
if (eventPre.isCancelled())
|
||||||
return true;
|
return true;
|
||||||
int score = getScoreOrSendError(channel, sender);
|
RecipientTestResult rtr = getScoreOrSendError(channel, sender);
|
||||||
if (score == -1)
|
int score = rtr.score;
|
||||||
|
if (score == -1 || rtr.groupID == null)
|
||||||
return true;
|
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);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
}
|
}
|
||||||
|
@ -255,27 +257,23 @@ public class TBMCChatAPI {
|
||||||
* The message to send
|
* The message to send
|
||||||
* @return The event cancelled state
|
* @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))
|
if (!Channel.getChannels().contains(channel))
|
||||||
throw new RuntimeException("Channel " + channel.DisplayName + " not registered!");
|
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);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getScoreOrSendError(Channel channel, CommandSender sender) {
|
private static RecipientTestResult getScoreOrSendError(Channel channel, CommandSender sender) {
|
||||||
int score;
|
|
||||||
if (channel.filteranderrormsg == null)
|
if (channel.filteranderrormsg == null)
|
||||||
score = 0;
|
return new RecipientTestResult(0, "everyone");
|
||||||
else {
|
else {
|
||||||
RecipientTestResult result = channel.filteranderrormsg.apply(sender);
|
RecipientTestResult result = channel.filteranderrormsg.apply(sender);
|
||||||
if (result.errormessage != null) {
|
if (result.errormessage != null)
|
||||||
sender.sendMessage("§c" + result.errormessage);
|
sender.sendMessage("§c" + result.errormessage);
|
||||||
return -1;
|
return result;
|
||||||
}
|
}
|
||||||
score = result.score;
|
|
||||||
}
|
|
||||||
return score;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue