Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[B+C] Add API to use 1.7 chat features. Adds BUKKIT-5245 #1065

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/org/bukkit/Bukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.logging.Logger;

import org.bukkit.Warning.WarningState;
import org.bukkit.chat.RichMessage;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
Expand Down Expand Up @@ -187,6 +188,13 @@ public static int broadcastMessage(String message) {
return server.broadcastMessage(message);
}

/**
* @see Server#broadcastMessage(org.bukkit.chat.RichMessage message)
*/
public static int broadcastMessage(RichMessage message) {
return server.broadcastMessage(message);
}

/**
* @see Server#getUpdateFolder()
*/
Expand Down Expand Up @@ -429,6 +437,13 @@ public static int broadcast(String message, String permission) {
return server.broadcast(message, permission);
}

/**
* @see Server#broadcast(RichMessage message, String permission)
*/
public static int broadcast(RichMessage message, String permission) {
return server.broadcast(message, permission);
}

/**
* @see Server#getOfflinePlayer(String name)
*/
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/bukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.logging.Logger;

import org.bukkit.Warning.WarningState;
import org.bukkit.chat.RichMessage;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
Expand Down Expand Up @@ -236,6 +237,17 @@ public interface Server extends PluginMessageRecipient {
*/
public int broadcastMessage(String message);

/**
* Broadcast a rich message to all players.
* <p>
* This is the same as calling {@link #broadcast(RichMessage, String)}
* to {@link #BROADCAST_CHANNEL_USERS}
*
* @param message the rich message
* @return the number of players
*/
public int broadcastMessage(RichMessage message);

/**
* Gets the name of the update folder. The update folder is used to safely
* update plugins at the right moment on a plugin load.
Expand Down Expand Up @@ -594,6 +606,17 @@ public interface Server extends PluginMessageRecipient {
*/
public int broadcast(String message, String permission);

/**
* Broadcasts the specified rich message to every user with the given
* permission name.
*
* @param message rich message to broadcast
* @param permission the required permission {@link Permissible
* permissibles} must have to receive the broadcast
* @return number of message recipients
*/
public int broadcast(RichMessage message, String permission);

/**
* Gets the player by the given name, regardless if they are offline or
* online.
Expand Down
149 changes: 149 additions & 0 deletions src/main/java/org/bukkit/chat/AchievementMessagePart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package org.bukkit.chat;

import org.apache.commons.lang.Validate;
import org.bukkit.Achievement;
import org.bukkit.Utility;

import java.util.Map;

/**
* Represents a message part with a tooltip like the one which can be seen in
* the Vanilla <b>"Achievement got"</b> message.
* <p>
* Note that the tooltip is fixed to the {@link Achievement} and cannot be
* altered.
*/
public class AchievementMessagePart extends RichMessagePart {

private Achievement achievement;

/**
* Creates a new AchievementMessagePart with the given
* {@link Achievement}.
* <p>
* The representation of the text message defaults to minecraft's
* <b>"Achievement got"</b> design.
*
* @param achievement the {@link Achievement} that should be displayed
*/
public AchievementMessagePart(Achievement achievement) {
this(achievement, (String) null);
}

/**
* Creates a new AchievementMessagePart with the given
* {@link Achievement} and the given {@link ClickAction}.
* <p>
* The representation of the text message defaults to minecraft's
* <b>"Achievement got"</b> design.
*
* @param achievement the {@link Achievement} that should be displayed
* @param clickAction the action executed when the player click on this
* {@link RichMessagePart}
*/
public AchievementMessagePart(Achievement achievement, ClickAction clickAction) {
this(achievement, (String) null, clickAction);
}

/**
* Creates a new AchievementMessagePart with the given
* {@link Achievement}.
* <p>
* Note that the text can contain {@link org.bukkit.ChatColor} codes.
*
* @param achievement the {@link Achievement} that should be displayed
* @param customText the text of this {@link RichMessagePart}
*/
public AchievementMessagePart(Achievement achievement, String customText) {
super(Type.ACHIEVEMENT, customText);
Validate.notNull(achievement, "AchievementMessagePart's can't be null");
this.achievement = achievement;
}

/**
* Creates a new AchievementMessagePart with the given
* {@link Achievement} and the given {@link ClickAction}.
* <p>
* Note that the text can contain {@link org.bukkit.ChatColor} codes.
*
* @param achievement the {@link Achievement} that should be displayed
* @param customText the text of this {@link RichMessagePart}
* @param clickAction the action executed when the player click on this
* {@link RichMessagePart}
*/
public AchievementMessagePart(Achievement achievement, String customText, ClickAction clickAction) {
super(Type.ACHIEVEMENT, customText, clickAction);
Validate.notNull(achievement, "AchievementMessagePart's can't be null");
this.achievement = achievement;
}

/**
* Creates a new AchievementMessagePart with the given
* {@link Achievement}.
*
* @param achievement the {@link Achievement} that should be displayed
* @param customText the localized text of this {@link RichMessagePart}
*/
public AchievementMessagePart(Achievement achievement, LocalizedText customText) {
super(Type.ACHIEVEMENT, customText);
Validate.notNull(achievement, "AchievementMessagePart's can't be null");
this.achievement = achievement;
}

/**
* Creates a new AchievementMessagePart with the given
* {@link Achievement}.
*
* @param achievement the {@link Achievement} that should be displayed
* @param customText the localized text of this {@link RichMessagePart}
* @param clickAction the action executed when the player click on this
* {@link RichMessagePart}
*/
public AchievementMessagePart(Achievement achievement, LocalizedText customText, ClickAction clickAction) {
super(Type.ACHIEVEMENT, customText, clickAction);
Validate.notNull(achievement, "AchievementMessagePart's can't be null");
this.achievement = achievement;
}

/**
* Gets the {@link Achievement} connected to this
* {@link RichMessagePart}.
* <p>
* The {@link Achievement}'s tooltip will be shown when the player hover
* on the text of this {@link RichMessagePart}.
*
* @return the {@link Achievement} connected to this RichMessagePart
*/
public Achievement getAchievement() {
return achievement;
}

/**
* Sets the {@link Achievement} connected to this
* {@link RichMessagePart}.
* <p>
* The {@link Achievement}'s tooltip will be shown when the player hover
* on the text of this {@link RichMessagePart}.
*
* @param achievement the new {@link Achievement} connected to this
* RichMessagePart
*/
public void setAchievement(Achievement achievement) {
Validate.notNull(achievement, "AchievementMessagePart's can't be null");
this.achievement = achievement;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + achievement.hashCode();
return result;
}

@Utility
public Map<String, Object> serialize() {
Map<String, Object> result = super.serialize();
result.put("achievement", achievement.name());
return result;
}
}
77 changes: 77 additions & 0 deletions src/main/java/org/bukkit/chat/ChatAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.bukkit.chat;

import org.apache.commons.lang.Validate;
import org.bukkit.Utility;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* Represents the action to send the specified chat message or command to the
* server as the Player when clicked client side.
*/
public class ChatAction extends ClickAction {

private String text;

/**
* Builds a new ChatAction, which will send the given text to the server
* as the Player when clicked client side.
* <p>
* The provided text can be either a simple chat message or a command
* (starting with a <b>/</b>).
*
* @param text the text that should be sent to the server
*/
public ChatAction(String text) {
super(Type.CHAT);
Validate.notNull(text, "ChatAction's text can't be null");
this.text = text;
}

/**
* Gets the text that is sent to the server as the Player when clicked
* client side.
*
* @return the text to send to the server
*/
public String getText() {
return text;
}

/**
* Sets the text that is send to the server as the Player when clicked
* client side.
*
* @param text the new text send to the server
*/
public void setText(String text) {
Validate.notNull(text, "ChatAction's text can't be null");
this.text = text;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + text.hashCode();
return result;
}

@Utility
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("text", text);
return result;
}

/**
* Required method for configuration serialization.
*
* @param args map to deserialize
* @return deserialized ChatAction
* @see org.bukkit.configuration.serialization.ConfigurationSerializable
*/
public static ChatAction deserialize(Map<String, Object> args) {
return new ChatAction((String) args.get("text"));
}
}
Loading