First release of the 'redesign', organizing most features into components #54
3 changed files with 29 additions and 19 deletions
|
@ -1,8 +1,9 @@
|
|||
package buttondevteam.lib;
|
||||
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Delegate;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
@ -16,22 +17,19 @@ import javax.annotation.Nullable;
|
|||
*/
|
||||
@Getter
|
||||
public class TBMCChatEvent extends TBMCChatEventBase {
|
||||
public TBMCChatEvent(CommandSender sender, ChromaGamerBase user, Channel channel, String message, int score, boolean fromcmd, String groupid, boolean ignoreSenderPermissions, String origin) {
|
||||
super(channel, message, score, groupid);
|
||||
this.sender = sender;
|
||||
this.user = user;
|
||||
this.fromcmd = fromcmd;
|
||||
this.ignoreSenderPermissions = ignoreSenderPermissions;
|
||||
this.origin = origin;
|
||||
public TBMCChatEvent(Channel channel, ChatMessage cm, Channel.RecipientTestResult rtr) {
|
||||
super(channel, cm.getMessage(), rtr.score, rtr.groupID);
|
||||
this.cm = cm;
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final CommandSender sender;
|
||||
private final boolean fromcmd;
|
||||
private final boolean ignoreSenderPermissions;
|
||||
private final ChromaGamerBase user;
|
||||
private final String origin;
|
||||
@Delegate //<-- Backwards compatibility
|
||||
private ChatMessage cm;
|
||||
|
||||
private boolean isIgnoreSenderPermissions() {
|
||||
return cm.getPermCheck() != cm.getSender();
|
||||
}
|
||||
// TODO: Message object with data?
|
||||
|
||||
/**
|
||||
|
@ -39,7 +37,7 @@ public class TBMCChatEvent extends TBMCChatEventBase {
|
|||
*/
|
||||
@Override
|
||||
public boolean shouldSendTo(CommandSender sender) {
|
||||
if (isIgnoreSenderPermissions() && sender.equals(this.sender))
|
||||
if (isIgnoreSenderPermissions() && sender.equals(this.cm.getSender()))
|
||||
return true; //Allow sending the message no matter what
|
||||
return super.shouldSendTo(sender);
|
||||
}
|
||||
|
@ -49,7 +47,7 @@ public class TBMCChatEvent extends TBMCChatEventBase {
|
|||
*/
|
||||
@Override
|
||||
public int getMCScore(CommandSender sender) {
|
||||
if (isIgnoreSenderPermissions() && sender.equals(this.sender))
|
||||
if (isIgnoreSenderPermissions() && sender.equals(this.cm.getSender()))
|
||||
return getScore(); //Send in the correct group no matter what
|
||||
return super.getMCScore(sender);
|
||||
}
|
||||
|
@ -60,7 +58,7 @@ public class TBMCChatEvent extends TBMCChatEventBase {
|
|||
@Nullable
|
||||
@Override
|
||||
public String getGroupID(CommandSender sender) {
|
||||
if (isIgnoreSenderPermissions() && sender.equals(this.sender))
|
||||
if (isIgnoreSenderPermissions() && sender.equals(this.cm.getSender()))
|
||||
return getGroupID(); //Send in the correct group no matter what
|
||||
return super.getGroupID(sender);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import buttondevteam.lib.player.ChromaGamerBase;
|
|||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Builder
|
||||
|
@ -20,7 +21,8 @@ public class ChatMessage {
|
|||
/**
|
||||
* The message to send as the user.
|
||||
*/
|
||||
private final String message;
|
||||
@Setter
|
||||
private String message;
|
||||
/**
|
||||
* Indicates whether the message comes from running a command (like /tableflip). Implemented to be used from Discord.
|
||||
*/
|
||||
|
@ -35,6 +37,15 @@ public class ChatMessage {
|
|||
*/
|
||||
private final String origin;
|
||||
|
||||
/**
|
||||
* The sender which we should check for permissions. Same as {@link #sender} by default.
|
||||
*
|
||||
* @return The perm check or the sender
|
||||
*/
|
||||
public CommandSender getPermCheck() {
|
||||
return permCheck == null ? sender : permCheck;
|
||||
}
|
||||
|
||||
private static ChatMessageBuilder builder() {
|
||||
return new ChatMessageBuilder();
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ public class TBMCChatAPI {
|
|||
public static boolean SendChatMessage(ChatMessage cm, Channel channel) {
|
||||
if (!Channel.getChannels().contains(channel))
|
||||
throw new RuntimeException("Channel " + channel.DisplayName + " not registered!");
|
||||
val permcheck = cm.getPermCheck() == null ? cm.getSender() : cm.getPermCheck();
|
||||
val permcheck = cm.getPermCheck();
|
||||
RecipientTestResult rtr = getScoreOrSendError(channel, permcheck);
|
||||
int score = rtr.score;
|
||||
if (score == Channel.SCORE_SEND_NOPE || rtr.groupID == null)
|
||||
|
@ -237,8 +237,9 @@ public class TBMCChatAPI {
|
|||
Bukkit.getPluginManager().callEvent(eventPre);
|
||||
if (eventPre.isCancelled())
|
||||
return true;
|
||||
cm.setMessage(eventPre.getMessage());
|
||||
TBMCChatEvent event;
|
||||
event = new TBMCChatEvent(cm.getSender(), cm.getUser(), channel, eventPre.getMessage(), score, cm.isFromCommand(), rtr.groupID, permcheck != cm.getSender(), cm.getOrigin());
|
||||
event = new TBMCChatEvent(channel, cm, rtr);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue