This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
762 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.github.rmsy.channels; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Set; | ||
|
||
/** | ||
* Interface to represent a chat channel. | ||
*/ | ||
public interface Channel { | ||
/** | ||
* Gets the channel's format. | ||
* | ||
* @return The channel's format. | ||
* @see #setFormat(String) | ||
*/ | ||
@Nonnull | ||
public String getFormat(); | ||
|
||
/** | ||
* Sets the channel's format (the string that appears before the message).</br><b>Note</b>: <code>%s</code> will be | ||
* replaced with the sending user's display name. For example, if iamramsey had a display name of 'rmsy', and had a | ||
* message directed to a channel with a format of <code>[Z] <%s> </code>, his message would be prepended in chat | ||
* with "[Z] rmsy". | ||
* | ||
* @param format The format. | ||
*/ | ||
public void setFormat(@Nonnull String format); | ||
|
||
/** | ||
* Gets the users who are sending to this channel by default. All users sending to the channel by default must also | ||
* be listening. | ||
* | ||
* @return The users who are sending to this channel by default. | ||
*/ | ||
@Nonnull | ||
public Set<Player> getMembers(); | ||
|
||
/** | ||
* Gets the users who are listening to messages on this channel. | ||
* | ||
* @return The users who are listening to messages on this channel. | ||
*/ | ||
@Nonnull | ||
public Set<Player> getListeners(); | ||
|
||
/** | ||
* Adds a user as a listener. | ||
* | ||
* @param listener The user. | ||
*/ | ||
public void addListener(@Nonnull final Player listener); | ||
|
||
/** | ||
* Gets whether or not messages sent are stripped of color. | ||
* | ||
* @return Whether or not messages sent are stripped of color. | ||
*/ | ||
public boolean shouldStripColors(); | ||
|
||
/** | ||
* Sets whether or not messages sent are stripped of color. | ||
* | ||
* @param shouldStripColors Whether or not messages sent are stripped of color. | ||
*/ | ||
public void shouldStripColors(boolean shouldStripColors); | ||
|
||
/** | ||
* Removes a user as a listener (and as a member, if they are one). | ||
* | ||
* @param listener The user. | ||
*/ | ||
public void removeListener(@Nonnull final Player listener); | ||
|
||
/** | ||
* Sends a new message to the channel. | ||
* | ||
* @param format Whether or not to format the message. | ||
* @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 boolean sendMessage(final boolean format, @Nonnull final String message, @Nullable final Player sender); | ||
|
||
/** | ||
* Gets whether or not the console is listening to this channel. | ||
* | ||
* @return Whether or not the console is listening to this channel. | ||
*/ | ||
public boolean isConsoleListening(); | ||
|
||
/** | ||
* Sets whether or not the console is listening to this channel. | ||
* | ||
* @param listening Whether or not the console is listening to this channel. | ||
*/ | ||
public void setConsoleListening(boolean listening); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.rmsy.channels; | ||
|
||
import org.bukkit.event.Event; | ||
|
||
/** | ||
* Represents a channel-related event. | ||
*/ | ||
public abstract class ChannelsEvent extends Event { | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/github/rmsy/channels/ChannelsPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.github.rmsy.channels; | ||
|
||
import com.github.rmsy.channels.impl.SimpleChannel; | ||
import com.github.rmsy.channels.impl.SimplePlayerManager; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.mcstats.Metrics; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
|
||
public class ChannelsPlugin extends JavaPlugin { | ||
/** | ||
* The global channel. | ||
*/ | ||
@Nonnull | ||
private Channel globalChannel; | ||
/** | ||
* The MCStats metrics instance. Null if creation failed. | ||
*/ | ||
@Nullable | ||
private Metrics metrics; | ||
/** | ||
* The player manager. | ||
*/ | ||
@Nonnull | ||
private PlayerManager playerManager; | ||
|
||
@Override | ||
public void onDisable() { | ||
this.metrics = null; | ||
this.playerManager = null; | ||
this.globalChannel = null; | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
this.globalChannel = new SimpleChannel("<%s" + ChatColor.RESET + ">", true, true); | ||
this.playerManager = new SimplePlayerManager(); | ||
|
||
try { | ||
this.metrics = new Metrics(this); | ||
this.metrics.start(); | ||
this.getLogger().log(Level.INFO, "Metrics enabled."); | ||
} catch (IOException exception) { | ||
this.getLogger().log(Level.WARNING, "An unknown error occurred. Metrics were not started."); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the universal player manager. | ||
* | ||
* @return The universal player manager. | ||
*/ | ||
@Nonnull | ||
public PlayerManager getPlayerManager() { | ||
return this.playerManager; | ||
} | ||
|
||
/** | ||
* Gets the global channel. | ||
* | ||
* @return The global channel. | ||
*/ | ||
@Nonnull | ||
public Channel getGlobalChannel() { | ||
return this.globalChannel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.rmsy.channels; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Set; | ||
|
||
/** | ||
* Interface to represent a player manager. | ||
*/ | ||
public interface PlayerManager { | ||
/** | ||
* Gets the channel the player is a member of. | ||
* | ||
* @param player The player. | ||
* @return The channel the player is a member of. | ||
*/ | ||
public Channel getMembershipChannel(@Nonnull final Player player); | ||
|
||
/** | ||
* Gets the channels the player is listening to. | ||
* | ||
* @param player The player. | ||
* @return The channels the player is listening to. | ||
*/ | ||
@Nonnull | ||
public Set<Channel> getListeningChannels(@Nonnull final Player player); | ||
|
||
/** | ||
* Sets the channel the player is a member of. Removes the player from their old membership channel. | ||
* | ||
* @param player The player. | ||
* @param membershipChannel The channel the player is a member of. | ||
*/ | ||
public void setMembershipChannel(@Nonnull final Player player, @Nonnull Channel membershipChannel); | ||
} |
108 changes: 108 additions & 0 deletions
108
src/main/java/com/github/rmsy/channels/event/ChannelMessageEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.github.rmsy.channels.event; | ||
|
||
import com.github.rmsy.channels.ChannelsEvent; | ||
import com.google.common.base.Preconditions; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.HandlerList; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Raised when a message is sent to a channel. | ||
*/ | ||
public final class ChannelMessageEvent extends ChannelsEvent implements Cancellable { | ||
/** | ||
* The handlers for the event. | ||
*/ | ||
private static final HandlerList handlers = new HandlerList(); | ||
/** | ||
* The message sender, or null for console. | ||
*/ | ||
@Nullable | ||
private final Player sender; | ||
/** | ||
* The message to be sent. | ||
*/ | ||
@Nonnull | ||
private String message; | ||
/** | ||
* Whether or not the event is cancelled. | ||
*/ | ||
private boolean cancelled = false; | ||
|
||
private ChannelMessageEvent() { | ||
this.sender = null; | ||
} | ||
|
||
/** | ||
* Creates a new ChannelMessageEvent. | ||
* | ||
* @param message The message. | ||
* @param sender The sender, or null for console. | ||
*/ | ||
public ChannelMessageEvent(@Nonnull String message, @Nullable final Player sender) { | ||
this.message = Preconditions.checkNotNull(message, "message"); | ||
this.sender = sender; | ||
} | ||
|
||
/** | ||
* Gets the message sender, or null for console. | ||
* | ||
* @return The message sender, or null for console. | ||
*/ | ||
@Nullable | ||
public Player getSender() { | ||
return this.sender; | ||
} | ||
|
||
/** | ||
* Gets the message to be sent. | ||
* | ||
* @return The message to be sent. | ||
*/ | ||
@Nonnull | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
/** | ||
* Sets the message to be sent. | ||
* | ||
* @param message The message to be sent. | ||
*/ | ||
public void setMessage(@Nonnull String message) { | ||
this.message = Preconditions.checkNotNull(message, "message"); | ||
} | ||
|
||
/** | ||
* Gets the handlers for the event. | ||
*/ | ||
@Override | ||
public HandlerList getHandlers() { | ||
return ChannelMessageEvent.handlers; | ||
} | ||
|
||
/** | ||
* Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still | ||
* pass to other plugins | ||
* | ||
* @return true if this event is cancelled | ||
*/ | ||
@Override | ||
public boolean isCancelled() { | ||
return this.cancelled; | ||
} | ||
|
||
/** | ||
* Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still | ||
* pass to other plugins. | ||
* | ||
* @param cancel true if you wish to cancel this event | ||
*/ | ||
@Override | ||
public void setCancelled(boolean cancel) { | ||
this.cancelled = cancel; | ||
} | ||
} |
Oops, something went wrong.