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

Commit 1e96ef0

Browse files
committed
Release 0.1-SNAPSHOT
1 parent 3a82ef8 commit 1e96ef0

11 files changed

+762
-20
lines changed

pom.xml

+2-20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
<properties>
5858
<!-- The prefix to use when logging to the console -->
5959
<plugin.prefix>Channels</plugin.prefix>
60+
<!-- The main class -->
61+
<plugin.mainClass>com.github.rmsy.channels.ChannelsPlugin</plugin.mainClass>
6062
</properties>
6163

6264
<dependencies>
@@ -66,16 +68,6 @@
6668
<version>1.5.2-R0.1</version>
6769
<scope>provided</scope>
6870
</dependency>
69-
<dependency>
70-
<groupId>com.sk89q</groupId>
71-
<artifactId>command-framework-core</artifactId>
72-
<version>0.4-SNAPSHOT</version>
73-
</dependency>
74-
<dependency>
75-
<groupId>com.sk89q</groupId>
76-
<artifactId>command-framework-bukkit</artifactId>
77-
<version>0.4-SNAPSHOT</version>
78-
</dependency>
7971
<dependency>
8072
<groupId>org.mcstats.bukkit</groupId>
8173
<artifactId>metrics</artifactId>
@@ -90,16 +82,6 @@
9082
<name>Bukkit repo</name>
9183
<url>http://repo.bukkit.org/content/groups/public</url>
9284
</repository>
93-
<repository>
94-
<id>overcast-repo</id>
95-
<name>Overcast Network repo</name>
96-
<url>http://repo.oc.tc/content/groups/public/</url>
97-
</repository>
98-
<repository>
99-
<id>sk89q-repo</id>
100-
<name>sk89q repo</name>
101-
<url>http://maven.sk89q.com/repo/</url>
102-
</repository>
10385
<repository>
10486
<id>mcstats-repo</id>
10587
<name>MCStats repo</name>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.github.rmsy.channels;
2+
3+
import org.bukkit.entity.Player;
4+
5+
import javax.annotation.Nonnull;
6+
import javax.annotation.Nullable;
7+
import java.util.Set;
8+
9+
/**
10+
* Interface to represent a chat channel.
11+
*/
12+
public interface Channel {
13+
/**
14+
* Gets the channel's format.
15+
*
16+
* @return The channel's format.
17+
* @see #setFormat(String)
18+
*/
19+
@Nonnull
20+
public String getFormat();
21+
22+
/**
23+
* Sets the channel's format (the string that appears before the message).</br><b>Note</b>: <code>%s</code> will be
24+
* replaced with the sending user's display name. For example, if iamramsey had a display name of 'rmsy', and had a
25+
* message directed to a channel with a format of <code>[Z] <%s> </code>, his message would be prepended in chat
26+
* with "[Z] rmsy".
27+
*
28+
* @param format The format.
29+
*/
30+
public void setFormat(@Nonnull String format);
31+
32+
/**
33+
* Gets the users who are sending to this channel by default. All users sending to the channel by default must also
34+
* be listening.
35+
*
36+
* @return The users who are sending to this channel by default.
37+
*/
38+
@Nonnull
39+
public Set<Player> getMembers();
40+
41+
/**
42+
* Gets the users who are listening to messages on this channel.
43+
*
44+
* @return The users who are listening to messages on this channel.
45+
*/
46+
@Nonnull
47+
public Set<Player> getListeners();
48+
49+
/**
50+
* Adds a user as a listener.
51+
*
52+
* @param listener The user.
53+
*/
54+
public void addListener(@Nonnull final Player listener);
55+
56+
/**
57+
* Gets whether or not messages sent are stripped of color.
58+
*
59+
* @return Whether or not messages sent are stripped of color.
60+
*/
61+
public boolean shouldStripColors();
62+
63+
/**
64+
* Sets whether or not messages sent are stripped of color.
65+
*
66+
* @param shouldStripColors Whether or not messages sent are stripped of color.
67+
*/
68+
public void shouldStripColors(boolean shouldStripColors);
69+
70+
/**
71+
* Removes a user as a listener (and as a member, if they are one).
72+
*
73+
* @param listener The user.
74+
*/
75+
public void removeListener(@Nonnull final Player listener);
76+
77+
/**
78+
* Sends a new message to the channel.
79+
*
80+
* @param format Whether or not to format the message.
81+
* @param message The message to be sent.
82+
* @param sender The message sender, or null for console.
83+
* @return Whether or not the message was sent.
84+
*/
85+
public boolean sendMessage(final boolean format, @Nonnull final String message, @Nullable final Player sender);
86+
87+
/**
88+
* Gets whether or not the console is listening to this channel.
89+
*
90+
* @return Whether or not the console is listening to this channel.
91+
*/
92+
public boolean isConsoleListening();
93+
94+
/**
95+
* Sets whether or not the console is listening to this channel.
96+
*
97+
* @param listening Whether or not the console is listening to this channel.
98+
*/
99+
public void setConsoleListening(boolean listening);
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.github.rmsy.channels;
2+
3+
import org.bukkit.event.Event;
4+
5+
/**
6+
* Represents a channel-related event.
7+
*/
8+
public abstract class ChannelsEvent extends Event {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.github.rmsy.channels;
2+
3+
import com.github.rmsy.channels.impl.SimpleChannel;
4+
import com.github.rmsy.channels.impl.SimplePlayerManager;
5+
import org.bukkit.ChatColor;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
import org.mcstats.Metrics;
8+
9+
import javax.annotation.Nonnull;
10+
import javax.annotation.Nullable;
11+
import java.io.IOException;
12+
import java.util.logging.Level;
13+
14+
public class ChannelsPlugin extends JavaPlugin {
15+
/**
16+
* The global channel.
17+
*/
18+
@Nonnull
19+
private Channel globalChannel;
20+
/**
21+
* The MCStats metrics instance. Null if creation failed.
22+
*/
23+
@Nullable
24+
private Metrics metrics;
25+
/**
26+
* The player manager.
27+
*/
28+
@Nonnull
29+
private PlayerManager playerManager;
30+
31+
@Override
32+
public void onDisable() {
33+
this.metrics = null;
34+
this.playerManager = null;
35+
this.globalChannel = null;
36+
}
37+
38+
@Override
39+
public void onEnable() {
40+
this.globalChannel = new SimpleChannel("<%s" + ChatColor.RESET + ">", true, true);
41+
this.playerManager = new SimplePlayerManager();
42+
43+
try {
44+
this.metrics = new Metrics(this);
45+
this.metrics.start();
46+
this.getLogger().log(Level.INFO, "Metrics enabled.");
47+
} catch (IOException exception) {
48+
this.getLogger().log(Level.WARNING, "An unknown error occurred. Metrics were not started.");
49+
}
50+
}
51+
52+
/**
53+
* Gets the universal player manager.
54+
*
55+
* @return The universal player manager.
56+
*/
57+
@Nonnull
58+
public PlayerManager getPlayerManager() {
59+
return this.playerManager;
60+
}
61+
62+
/**
63+
* Gets the global channel.
64+
*
65+
* @return The global channel.
66+
*/
67+
@Nonnull
68+
public Channel getGlobalChannel() {
69+
return this.globalChannel;
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.rmsy.channels;
2+
3+
import org.bukkit.entity.Player;
4+
5+
import javax.annotation.Nonnull;
6+
import java.util.Set;
7+
8+
/**
9+
* Interface to represent a player manager.
10+
*/
11+
public interface PlayerManager {
12+
/**
13+
* Gets the channel the player is a member of.
14+
*
15+
* @param player The player.
16+
* @return The channel the player is a member of.
17+
*/
18+
public Channel getMembershipChannel(@Nonnull final Player player);
19+
20+
/**
21+
* Gets the channels the player is listening to.
22+
*
23+
* @param player The player.
24+
* @return The channels the player is listening to.
25+
*/
26+
@Nonnull
27+
public Set<Channel> getListeningChannels(@Nonnull final Player player);
28+
29+
/**
30+
* Sets the channel the player is a member of. Removes the player from their old membership channel.
31+
*
32+
* @param player The player.
33+
* @param membershipChannel The channel the player is a member of.
34+
*/
35+
public void setMembershipChannel(@Nonnull final Player player, @Nonnull Channel membershipChannel);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.github.rmsy.channels.event;
2+
3+
import com.github.rmsy.channels.ChannelsEvent;
4+
import com.google.common.base.Preconditions;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.event.Cancellable;
7+
import org.bukkit.event.HandlerList;
8+
9+
import javax.annotation.Nonnull;
10+
import javax.annotation.Nullable;
11+
12+
/**
13+
* Raised when a message is sent to a channel.
14+
*/
15+
public final class ChannelMessageEvent extends ChannelsEvent implements Cancellable {
16+
/**
17+
* The handlers for the event.
18+
*/
19+
private static final HandlerList handlers = new HandlerList();
20+
/**
21+
* The message sender, or null for console.
22+
*/
23+
@Nullable
24+
private final Player sender;
25+
/**
26+
* The message to be sent.
27+
*/
28+
@Nonnull
29+
private String message;
30+
/**
31+
* Whether or not the event is cancelled.
32+
*/
33+
private boolean cancelled = false;
34+
35+
private ChannelMessageEvent() {
36+
this.sender = null;
37+
}
38+
39+
/**
40+
* Creates a new ChannelMessageEvent.
41+
*
42+
* @param message The message.
43+
* @param sender The sender, or null for console.
44+
*/
45+
public ChannelMessageEvent(@Nonnull String message, @Nullable final Player sender) {
46+
this.message = Preconditions.checkNotNull(message, "message");
47+
this.sender = sender;
48+
}
49+
50+
/**
51+
* Gets the message sender, or null for console.
52+
*
53+
* @return The message sender, or null for console.
54+
*/
55+
@Nullable
56+
public Player getSender() {
57+
return this.sender;
58+
}
59+
60+
/**
61+
* Gets the message to be sent.
62+
*
63+
* @return The message to be sent.
64+
*/
65+
@Nonnull
66+
public String getMessage() {
67+
return message;
68+
}
69+
70+
/**
71+
* Sets the message to be sent.
72+
*
73+
* @param message The message to be sent.
74+
*/
75+
public void setMessage(@Nonnull String message) {
76+
this.message = Preconditions.checkNotNull(message, "message");
77+
}
78+
79+
/**
80+
* Gets the handlers for the event.
81+
*/
82+
@Override
83+
public HandlerList getHandlers() {
84+
return ChannelMessageEvent.handlers;
85+
}
86+
87+
/**
88+
* Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still
89+
* pass to other plugins
90+
*
91+
* @return true if this event is cancelled
92+
*/
93+
@Override
94+
public boolean isCancelled() {
95+
return this.cancelled;
96+
}
97+
98+
/**
99+
* Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still
100+
* pass to other plugins.
101+
*
102+
* @param cancel true if you wish to cancel this event
103+
*/
104+
@Override
105+
public void setCancelled(boolean cancel) {
106+
this.cancelled = cancel;
107+
}
108+
}

0 commit comments

Comments
 (0)