Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.model;
- import com.google.common.base.Preconditions;
- import server.model.players.Player;
- import server.model.players.World;
- /**
- * Handles sending a notice to players
- *
- * @author Arithium
- *
- */
- public class Notices {
- /**
- * The announcement type of the notice to send, whether its global or a single player
- * @author Arithium
- *
- */
- public enum NoticeAnnouncementType {
- PLAYER,
- GLOBAL,
- }
- /**
- * The type of notice to send to the players
- *
- * @author Arithium
- *
- */
- public enum NoticeType {
- DROP_MESSAGE("[Drop]", "255", NoticeAnnouncementType.GLOBAL),
- GAME_MESSAGE(null, null, NoticeAnnouncementType.PLAYER),
- ;
- private final String prefix, color;
- private final NoticeAnnouncementType type;
- NoticeType(String prefix, String color, NoticeAnnouncementType type) {
- this.prefix = prefix;
- this.color = color;
- this.type = type;
- }
- public String getPrefix() {
- return prefix;
- }
- public String getColor() {
- return color;
- }
- public NoticeAnnouncementType getType() {
- return type;
- }
- }
- /**
- * Sends a notice to all players online
- *
- * @param type
- * The {@link NoticeType} of the notice to send
- * @param message
- * The message of the notice to send
- */
- public static void send(NoticeType type, String message) {
- Preconditions.checkArgument(type.getType() != NoticeAnnouncementType.PLAYER);
- send(type, message, null);
- }
- /**
- * Sends a notice to either a single player or to all players
- *
- * @param type
- * The {@link NoticeType} of the notice to send
- * @param message
- * The message of the notice to send
- * @param player
- * The individual player to send the notice to
- */
- public static void send(NoticeType type, String message, Player player) {
- StringBuilder bldr = new StringBuilder();
- if (type.getColor() != null) {
- bldr.append("<col=" + type.getColor() + ">");
- }
- if (type.getPrefix() != null) {
- bldr.append(type.getPrefix() + " ");
- }
- bldr.append(message);
- final String toSend = bldr.toString();
- if (type.getType().equals(NoticeAnnouncementType.GLOBAL)) {
- World.getPlayerStream().forEach(i -> i.sendMessage(toSend));
- } else if (type.getType().equals(NoticeAnnouncementType.PLAYER)) {
- if (player != null) {
- player.sendMessage(toSend);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement