Skip to content
This repository was archived by the owner on Aug 31, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.rmsy.Channels</groupId>
<artifactId>Channels</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>

<name>Channels</name>
<description>Channels is a simple chat channel plugin and API.</description>
Expand Down
55 changes: 29 additions & 26 deletions src/main/java/com/github/rmsy/channels/Channel.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
package com.github.rmsy.channels;

import com.google.common.collect.ImmutableSet;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;

import javax.annotation.Nullable;

/** Interface to represent a chat channel. */
public interface Channel {
/**
* Gets the channel's format.
*
* @return The channel's format.
* @see #setFormat(String)
*/
public String getFormat();


/**
* Sets the channel's format.
*
* @param format The format.
*/
public void setFormat(String format);
/**
* Gets the channel's broadcast format.
* Creates the channel's format.
*
* @return The channel's format.
* @see #setFormat(String)
* @param message the message.
* @param sender the sender, null if console.
* @param receiver the receiver.
* @param broadcast whether this is a broadcast.
* @return the formatted component.
*/
public String getBroadcastFormat();
BaseComponent getFormat(final BaseComponent message, @Nullable final Player sender, final CommandSender receiver, boolean broadcast);

/**
* Sets the channel's broadcast format.
* Gets the users who are sending to this channel by default.
*
* @param format The format.
* @return The users who are sending to this channel by default.
*/
public void setBroadcastFormat(String format);
ImmutableSet<String> getMembers();

/**
* Gets the users who are sending to this channel by default.
* Sends a new message to the channel.
*
* @return The users who are sending to this channel by default.
* @param message The message to be sent.
* @param sender The message sender, or null for console.
* @return Whether or not the message was sent.
*/
public ImmutableSet<String> getMembers();
boolean sendMessage(final BaseComponent message, @Nullable final Player sender);

/**
* Sends a new message to the channel.
Expand All @@ -51,20 +46,28 @@ public interface Channel {
* @param sender The message sender, or null for console.
* @return Whether or not the message was sent.
*/
public boolean sendMessage(final String message, @Nullable final Player sender);
boolean sendMessage(String message, @Nullable final Player sender);

/**
* Gets the permission node that is required for listening on this channel. Users without this permission node will
* not receive messages from this channel.
*
* @return The permission node that is required for listening on this channel.
*/
public Permission getListeningPermission();
Permission getListeningPermission();

/**
* Broadcasts a message to the channel.
*
* @param message The message to be broadcast.
*/
public void broadcast(final String message);
void broadcast(final BaseComponent message);

/**
* Broadcasts a message to the channel.
*
* @param message The message to be broadcast.
*/
void broadcast(String message);

}
18 changes: 11 additions & 7 deletions src/main/java/com/github/rmsy/channels/ChannelsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
import com.sk89q.bukkit.util.BukkitCommandsManager;
import com.sk89q.bukkit.util.CommandsManagerRegistration;
import com.sk89q.minecraft.util.commands.*;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.java.JavaPlugin;

import javax.annotation.Nullable;

public class ChannelsPlugin extends JavaPlugin {
public static final String GLOBAL_CHANNEL_PARENT_NODE = "channels.global";
public static final String GLOBAL_CHANNEL_SEND_NODE = ChannelsPlugin.GLOBAL_CHANNEL_PARENT_NODE + ".send";
Expand Down Expand Up @@ -93,13 +98,12 @@ public void onEnable() {
config.options().copyDefaults(true);
this.saveConfig();

this.globalChannel = new SimpleChannel(
config.getString(
"global-chat.format",
ChatColor.WHITE + "<{1}" + ChatColor.RESET + ChatColor.WHITE + ">: {3}"
),
new Permission(ChannelsPlugin.GLOBAL_CHANNEL_PARENT_NODE, PermissionDefault.TRUE)
);
this.globalChannel = new SimpleChannel(new Permission(ChannelsPlugin.GLOBAL_CHANNEL_PARENT_NODE, PermissionDefault.TRUE)) {
@Override
public BaseComponent getFormat(BaseComponent message, @Nullable Player sender, CommandSender receiver, boolean broadcast) {
return broadcast ? new TextComponent(new TextComponent("[Broadcast] "), message) : new TextComponent(new TextComponent("<"), new TextComponent(sender != null ? sender.getDisplayName(receiver) : "Console"), new TextComponent(">: "), message);
}
};
this.defaultChannel = this.globalChannel;
this.playerManager = new SimplePlayerManager();
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.rmsy.channels.Channel;
import com.github.rmsy.channels.ChannelsEvent;
import com.google.common.base.Preconditions;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
Expand All @@ -18,7 +19,7 @@ public final class ChannelMessageEvent extends ChannelsEvent implements Cancella
/** The message sender, or null for console. */
private @Nullable final Player sender;
/** The message to be sent. */
private String message;
private BaseComponent message;
/** Whether or not the event is cancelled. */
private boolean cancelled = false;

Expand All @@ -28,7 +29,7 @@ public final class ChannelMessageEvent extends ChannelsEvent implements Cancella
* @param message The message.
* @param sender The sender, or null for console.
*/
public ChannelMessageEvent(String message, @Nullable final Player sender, Channel channel) {
public ChannelMessageEvent(BaseComponent message, @Nullable final Player sender, Channel channel) {
this.message = Preconditions.checkNotNull(message, "message");
this.sender = sender;
this.channel = Preconditions.checkNotNull(channel, "Channel");
Expand All @@ -48,7 +49,7 @@ public ChannelMessageEvent(String message, @Nullable final Player sender, Channe
*
* @return The message to be sent.
*/
public String getMessage() {
public BaseComponent getMessage() {
return message;
}

Expand All @@ -57,7 +58,7 @@ public String getMessage() {
*
* @param message The message to be sent.
*/
public void setMessage(String message) {
public void setMessage(BaseComponent message) {
this.message = Preconditions.checkNotNull(message, "message");
}

Expand Down
Loading