Added new Server.broadcast method to broadcast to specific groups of users, including non-players

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-09-02 22:21:26 +01:00
parent f4545766e3
commit 2ba705febc
4 changed files with 30 additions and 2 deletions

View file

@ -219,4 +219,8 @@ public final class Bukkit {
public static void shutdown() { public static void shutdown() {
server.shutdown(); server.shutdown();
} }
public int broadcast(String message, String permission) {
return server.broadcast(message, permission);
}
} }

View file

@ -21,6 +21,19 @@ import org.bukkit.scheduler.BukkitScheduler;
* Represents a server implementation * Represents a server implementation
*/ */
public interface Server { public interface Server {
/**
* Used for all administrative messages, such as an operator using a command.
*
* For use in {@link #broadcast(java.lang.String, java.lang.String)}
*/
public static final String BROADCAST_CHANNEL_ADMINISTRATIVE = "bukkit.broadcast.admin";
/**
* Used for all announcement messages, such as informing users that a player has joined.
*
* For use in {@link #broadcast(java.lang.String, java.lang.String)}
*/
public static final String BROADCAST_CHANNEL_USERS = "bukkit.broadcast.user";
/** /**
* Gets the name of this server implementation * Gets the name of this server implementation
@ -103,6 +116,8 @@ public interface Server {
/** /**
* Broadcast a message to all players. * Broadcast a message to all players.
* *
* This is the same as calling {@link #broadcast(java.lang.String, java.lang.String)} to {@link #BROADCAST_CHANNEL_USERS}
*
* @param message the message * @param message the message
* @return the number of players * @return the number of players
*/ */
@ -351,4 +366,13 @@ public interface Server {
* Shutdowns the server, stopping everything. * Shutdowns the server, stopping everything.
*/ */
public void shutdown(); public void shutdown();
/**
* Broadcasts the specified message to every user with the given permission
*
* @param message Message to broadcast
* @param permission Permission the users must have to receive the broadcast
* @return Amount of users who received the message
*/
public int broadcast(String message, String permission);
} }

View file

@ -3,7 +3,7 @@ package org.bukkit.util.permissions;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
public class CommandPermissions { public final class CommandPermissions {
private static final String ROOT = "bukkit.command"; private static final String ROOT = "bukkit.command";
private static final String PREFIX = ROOT + "."; private static final String PREFIX = ROOT + ".";

View file

@ -1,6 +1,5 @@
package org.bukkit.util.permissions; package org.bukkit.util.permissions;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
@ -77,6 +76,7 @@ public final class DefaultPermissions {
Permission parent = registerPermission(ROOT, "Gives the user the ability to use all Craftbukkit utilities and commands"); Permission parent = registerPermission(ROOT, "Gives the user the ability to use all Craftbukkit utilities and commands");
CommandPermissions.registerPermissions(parent); CommandPermissions.registerPermissions(parent);
BroadcastPermissions.registerPermissions(parent);
parent.recalculatePermissibles(); parent.recalculatePermissibles();
} }