Skip to content
Open
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
16 changes: 14 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,17 @@ handicapChars: 10
# will chat messages only appear in chat bubbles and won't echo on chat window?
disableChatWindow: false

# chat bubbles text format, omit section signs, see http://minecraft.gamepedia.com/Formatting_codes
chatFormat: EL
# chat formatting codes for messages, without &. Examples: "EL", "C", "L"
# consider using "&e&l{message}" in chatFormat. This is here only for backwards compatibility purposes
chatFormat: ""

# chat message format. Applied for each message. Set to "SERVER" to make it the same as in chat.
# examples: "&e{player} said: &f{message}", "{player}: {message}", "&l{message}", "SERVER"
messageFormat: "{message}"

# bubble format. Applied to every bubble.
# examples: "&e{player} said: &f{message}", "{player}: {message}", "&l{message}"
bubbleFormat: "{message}"

# row format. Applied for each row.
rowFormat: "&e&l{message}"
10 changes: 7 additions & 3 deletions src/cl/netgamer/lightchatbubbles/ChatBubbles.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package cl.netgamer.lightchatbubbles;

import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

public class ChatBubbles
{
private int handicapChars;
private int readSpeed;
private String chatFormat;
private String rowFormat;

// constructor
public ChatBubbles(Main plugin)
{
handicapChars = plugin.getConfig().getInt("handicapChars");
readSpeed = plugin.getConfig().getInt("readSpeed");
chatFormat = plugin.getConfig().getString("chatFormat").replaceAll("(.)", "\u00A7$1");
rowFormat = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("rowFormat"));
}

// recieve chat to be displayed, return display duration in ticks so previous method can schedule next
int receiveMessage(Player player, String playerId, String chat)
{
// prepare chat message and empty bubble
String[] chatLines = chat.split("\n");
new ArrayList<LivingEntity>();

// calculate bubble duration, 1200 = ticks per minute, to convert readSpeed to ticks
int duration = (chat.length()+(handicapChars*chatLines.length))*1200/readSpeed;
Expand All @@ -45,6 +45,10 @@ int receiveMessage(Player player, String playerId, String chat)
// spawn a nameplate and return it to caller so it can stack together
private AreaEffectCloud spawnNameTag(Entity vehicle, String text, Location spawnPoint, int duration)
{
text = rowFormat
.replaceAll("\\{player}", vehicle.getType() == EntityType.PLAYER ? ((Player) vehicle).getDisplayName() : vehicle.getName())
.replaceAll("\\{message}", text);

// spawn name tag away from player in same chunk, then set invisible
AreaEffectCloud nameTag = (AreaEffectCloud) spawnPoint.getWorld().spawnEntity(spawnPoint, EntityType.AREA_EFFECT_CLOUD);
nameTag.setParticle(Particle.TOWN_AURA); // ITEM_TAKE was deprecated so i found mycelium (TOWN_AURA) has the tiniest particle
Expand Down
19 changes: 18 additions & 1 deletion src/cl/netgamer/lightchatbubbles/ChatBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Map;
import java.util.Queue;

import org.bukkit.ChatColor;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

Expand All @@ -16,19 +18,31 @@ public class ChatBuffer
private int maxBubbleWidth;
private int bubblesInterval;
private Map<String, Queue<String>> chatQueue = new HashMap<String, Queue<String>>();
private String bubbleFormat;
private String messageFormat;

// constructor
ChatBuffer(Main plugin)
{
maxBubbleHeight = plugin.getConfig().getInt("maxBubbleHeight");
maxBubbleWidth = plugin.getConfig().getInt("maxBubbleWidth");
bubblesInterval = plugin.getConfig().getInt("bubblesInterval");
bubbleFormat = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("bubbleFormat"));
messageFormat = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messageFormat"));
this.plugin = plugin;
}

// wrap pre-trimmed chat and put in a player buffer
void receiveChat(Player player, String msg)
void receiveChat(Player player, String msg, String format)
{
if(messageFormat.equals("SERVER")) {
msg = String.format(format, player.getName(), msg);
} else {
msg = messageFormat
.replaceAll("\\{player}", player.getDisplayName())
.replaceAll("\\{message}", msg);
}

// most probable case, 1 line chat
if (msg.length() <= maxBubbleWidth)
{
Expand Down Expand Up @@ -69,6 +83,9 @@ void receiveChat(Player player, String msg)
// get word wrapped chat and queues in a player buffer, creates if not exists
private void queueChat(Player player, String chat)
{
chat = bubbleFormat
.replaceAll("\\{player}", player.getDisplayName())
.replaceAll("\\{message}", chat);
// if no player buffer yet, create it and schedule this message
String playerId = ""+player.getUniqueId();
if (!chatQueue.containsKey(playerId))
Expand Down
2 changes: 1 addition & 1 deletion src/cl/netgamer/lightchatbubbles/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void onPlayerChat(AsyncPlayerChatEvent e)
{
if (!e.isCancelled())
{
buffer.receiveChat(e.getPlayer(), e.getMessage());
buffer.receiveChat(e.getPlayer(), e.getMessage(), e.getFormat());

if(disableChatWindow)
e.setCancelled(true);
Expand Down