Skip to content
This repository has been archived by the owner on Aug 31, 2019. It is now read-only.

Commit

Permalink
Release 0.1-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
rmsy committed Jun 19, 2013
1 parent 3a82ef8 commit 1e96ef0
Show file tree
Hide file tree
Showing 11 changed files with 762 additions and 20 deletions.
22 changes: 2 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<properties>
<!-- The prefix to use when logging to the console -->
<plugin.prefix>Channels</plugin.prefix>
<!-- The main class -->
<plugin.mainClass>com.github.rmsy.channels.ChannelsPlugin</plugin.mainClass>
</properties>

<dependencies>
Expand All @@ -66,16 +68,6 @@
<version>1.5.2-R0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>command-framework-core</artifactId>
<version>0.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>command-framework-bukkit</artifactId>
<version>0.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mcstats.bukkit</groupId>
<artifactId>metrics</artifactId>
Expand All @@ -90,16 +82,6 @@
<name>Bukkit repo</name>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
<repository>
<id>overcast-repo</id>
<name>Overcast Network repo</name>
<url>http://repo.oc.tc/content/groups/public/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<name>sk89q repo</name>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>mcstats-repo</id>
<name>MCStats repo</name>
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/com/github/rmsy/channels/Channel.java
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);
}
9 changes: 9 additions & 0 deletions src/main/java/com/github/rmsy/channels/ChannelsEvent.java
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 src/main/java/com/github/rmsy/channels/ChannelsPlugin.java
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;
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/github/rmsy/channels/PlayerManager.java
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 src/main/java/com/github/rmsy/channels/event/ChannelMessageEvent.java
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;
}
}
Loading

0 comments on commit 1e96ef0

Please sign in to comment.